2021-08-22 17:03:03 +00:00
|
|
|
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptResolver.hpp>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <iostream>
|
|
|
|
#include "../extern/args.hpp"
|
|
|
|
#include "BuildData/BuildLibrary.hpp"
|
2021-08-23 19:44:59 +00:00
|
|
|
#include "Globals.hpp"
|
2021-08-25 19:17:44 +00:00
|
|
|
#include "Tester/AngelScript/BattleFunctions.hpp"
|
|
|
|
#include "Tester/AngelScript/MiscMockFunctions.hpp"
|
2021-08-23 19:44:59 +00:00
|
|
|
#include "Tester/AngelScript/TestFunctions.hpp"
|
2021-08-22 17:03:03 +00:00
|
|
|
#include "Tester/TestRunner.hpp"
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
args::ArgumentParser parser("PkmnLib Script Tester.", "");
|
|
|
|
args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
|
|
|
|
|
|
|
|
std::string workingDirectory;
|
|
|
|
|
|
|
|
args::HelpFlag helpFlag(parser, "help", "Display this help menu", {'h', "help"});
|
|
|
|
args::ValueFlag<std::string> workingDirFlag(parser, "Working Directory", "Which work directory to use.",
|
|
|
|
{"workdir"});
|
|
|
|
try {
|
|
|
|
parser.ParseCLI(argc, argv);
|
|
|
|
} catch (args::Help&) {
|
|
|
|
std::cout << parser;
|
|
|
|
return 0;
|
|
|
|
} catch (args::ParseError& e) {
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
std::cerr << parser;
|
|
|
|
return 1;
|
|
|
|
} catch (args::ValidationError& e) {
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
std::cerr << parser;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (workingDirFlag) {
|
|
|
|
workingDirectory = args::get(workingDirFlag);
|
|
|
|
}
|
|
|
|
if (!workingDirectory.empty()) {
|
|
|
|
chdir(std::filesystem::path(workingDirectory).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void(PkmnLib::Battling::ScriptResolver*)> initialize =
|
|
|
|
[](PkmnLib::Battling::ScriptResolver* resolver) {
|
|
|
|
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(resolver);
|
2021-08-25 19:17:44 +00:00
|
|
|
scriptResolver->DefineWord("TESTS");
|
2021-08-22 17:03:03 +00:00
|
|
|
TestFunctions::Register(scriptResolver);
|
2021-08-25 19:17:44 +00:00
|
|
|
BattleFunctions::Register(scriptResolver);
|
|
|
|
MiscMockFunctions::Register(scriptResolver);
|
2021-08-22 17:03:03 +00:00
|
|
|
};
|
|
|
|
|
2021-08-23 19:44:59 +00:00
|
|
|
Globals::Library = BuildLibrary::Build("", initialize);
|
|
|
|
if (!Globals::Library.HasValue()) {
|
2021-08-22 17:03:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2021-08-23 19:44:59 +00:00
|
|
|
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(Globals::Library.GetValue()->GetScriptResolver().get());
|
2021-08-22 17:03:03 +00:00
|
|
|
auto testRunner = TestRunner(scriptResolver);
|
2021-08-22 17:29:00 +00:00
|
|
|
auto* engine = scriptResolver->GetBuilder().GetEngine();
|
|
|
|
return testRunner.RunAll(engine);
|
2021-08-22 17:03:03 +00:00
|
|
|
}
|