#include #include #include #include #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" #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 workingDirFlag(parser, "Working Directory", "Which work directory to use.", {"workdir"}); args::Flag logTimeFlag(parser, "time-log", "Whether to show time logging.", {'t', "time-log"}); 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::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); std::function initialize = [](PkmnLib::Battling::ScriptResolver* resolver) { auto* scriptResolver = dynamic_cast(resolver); scriptResolver->DefineWord("TESTS"); TestFunctions::Register(scriptResolver); BattleFunctions::Register(scriptResolver); MiscMockFunctions::Register(scriptResolver); }; Globals::Library = BuildLibrary::Build("", initialize); std::chrono::steady_clock::time_point end_build = std::chrono::steady_clock::now(); if (!Globals::Library.HasValue()) { return 1; } if (logTimeFlag.Get()) { std::cout << "Finished building library in: " << std::chrono::duration_cast(end_build - begin).count() << "ms" << std::endl; BuildLibrary::LogBuildTimes(); std::cout << std::endl; } auto* scriptResolver = dynamic_cast(Globals::Library.GetValue()->GetScriptResolver().get()); auto testRunner = TestRunner(scriptResolver); auto* engine = scriptResolver->GetBuilder().GetEngine(); std::chrono::steady_clock::time_point beginTests = std::chrono::steady_clock::now(); 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(end - begin).count() << "ms (of which " << std::chrono::duration_cast(end - beginTests).count() << " ms was test runs)" << std::endl; return v; }