PokemonScriptTester/src/main.cpp

66 lines
2.6 KiB
C++
Raw Normal View History

2021-08-22 17:03:03 +00:00
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptResolver.hpp>
2021-08-26 17:24:35 +00:00
#include <chrono>
2021-08-22 17:03:03 +00:00
#include <filesystem>
#include <iostream>
#include "../extern/args.hpp"
#include "BuildData/BuildLibrary.hpp"
#include "Globals.hpp"
#include "Tester/AngelScript/BattleFunctions.hpp"
#include "Tester/AngelScript/MiscMockFunctions.hpp"
#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());
}
2021-08-26 17:24:35 +00:00
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
2021-08-22 17:03:03 +00:00
std::function<void(PkmnLib::Battling::ScriptResolver*)> initialize =
[](PkmnLib::Battling::ScriptResolver* resolver) {
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(resolver);
scriptResolver->DefineWord("TESTS");
2021-08-22 17:03:03 +00:00
TestFunctions::Register(scriptResolver);
BattleFunctions::Register(scriptResolver);
MiscMockFunctions::Register(scriptResolver);
2021-08-22 17:03:03 +00:00
};
Globals::Library = BuildLibrary::Build("", initialize);
if (!Globals::Library.HasValue()) {
2021-08-22 17:03:03 +00:00
return 1;
}
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();
2021-08-26 17:24:35 +00:00
auto v = testRunner.RunAll(engine);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << std::endl
<< "Total Run time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count()
<< "ms" << std::endl;
return v;
2021-08-22 17:03:03 +00:00
}