Commit 93f377ce authored by Jack's avatar Jack
Browse files

added batch compilation in tests

parent 63fd938d
......@@ -76,6 +76,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
......@@ -85,8 +86,7 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>C:\Users\Jack\Documents\dev\openmom\libs\sdl2\win\include;C:\Users\Jack\Documents\dev\sdl\SDL2_ttf\include;$(SolutionDir)../../../src;C:\Users\Jack\Documents\dev\odreader\projects\vs2017\zlib\include;C:\Users\Jack\Documents\dev\retro-8\projects\vs2017\libs\lua\include</AdditionalIncludeDirectories>
<LanguageStandard>
</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
......@@ -102,6 +102,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
......@@ -117,8 +118,7 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>C:\Users\Jack\Documents\dev\openmom\libs\sdl2\win\include;C:\Users\Jack\Documents\dev\sdl\SDL2_ttf\include;$(SolutionDir)../../../src;C:\Users\Jack\Documents\dev\odreader\projects\vs2017\zlib\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>
</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
......
......@@ -61,7 +61,7 @@ private:
#define MOUSE_ENABLED true
#define WINDOW_SCALE 1
#define DEBUGGER true
#define TEST_MODE false
#define TEST_MODE true
#else
#define MOUSE_ENABLED false
#endif
......@@ -46,6 +46,38 @@ retro8::sprite_flags_t Loader::spriteFlagsFromString(const char* c)
return (h << 4) | l;
}
std::string Loader::load(const std::string& path)
{
std::vector<std::string> lines;
std::ifstream input(path);
assert(input.good());
for (std::string line; std::getline(input, line); /**/)
lines.push_back(line);
for (auto& line : lines)
if (!line.empty() && line.back() == '\r')
line.resize(line.length() - 1);
std::stringstream code;
bool started = false;
for (auto& line : lines)
{
if (line == "__lua__")
started = true;
else if (line[0] == '_' && line[1] == '_')
return code.str();
else if (started)
code << line << std::endl;
}
assert(false);
return "";
}
void Loader::load(const std::string& path, Machine& m)
{
/* if it's a PNG we should use other loader */
......
......@@ -20,6 +20,7 @@ namespace retro8
public:
void load(const std::string& path, Machine& dest);
std::string load(const std::string& path);
};
}
}
\ No newline at end of file
......@@ -6,9 +6,11 @@
#include "catch.hpp"
#include "vm/machine.h"
#include "io/loader.h"
#include "lua/lua.hpp"
#include <unordered_set>
#include <filesystem>
using namespace retro8;
using namespace retro8::gfx;
......@@ -149,12 +151,53 @@ TEST_CASE("lua language modifications")
}
lua_close(L);
}
TEST_CASE("cartridge testing")
{
retro8::io::Loader loader;
namespace fs = std::filesystem;
std::error_code ec;
for (const auto& p : fs::directory_iterator("cartridges", ec))
{
const auto& path = p.path();
if (fs::is_regular_file(path) && path.extension() == ".p8")
{
SECTION(std::string("Test on source file ") + path.filename().generic_u8string())
{
lua_State* L = luaL_newstate();
std::string code = loader.load(path.generic_u8string());
int status = luaL_loadbufferx(L, code.c_str(), code.length(), path.filename().generic_u8string().c_str(), nullptr);
if (status)
{
const char* message = "unknown error";
if (lua_isstring(L, -1))
message = lua_tostring(L, -1);
FAIL("Error: " << message);
}
lua_close(L);
}
}
}
}
int testMain(int argc, char* argv[])
int testMain(int rargc, char* rargv[])
{
int result = Catch::Session().run(argc, argv);
Catch::Session session;
const char* argv2[] = { "retro8", "--success" };
int argc = rargc;
const char** argv = const_cast<const char**>(rargv);
int result = session.run(argc, argv);
return result;
}
......
......@@ -109,7 +109,7 @@ void GameView::render()
retro8::io::Loader loader;
if (_path.empty())
_path = "celeste.p8";
_path = "cartridges/celeste.p8";
loader.load(_path, machine);
......
......@@ -10,6 +10,13 @@ namespace lua
class Code
{
public:
struct Result
{
bool success;
std::string error;
};
private:
lua_State* L;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment