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"
|
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"
|
2021-09-07 17:13:10 +00:00
|
|
|
#include <gitversion/version.h>
|
2021-08-22 17:03:03 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2021-09-07 17:13:10 +00:00
|
|
|
std::cout << "PokemonScript Tester version: " << version::VERSION_STRING << std::endl;
|
2021-08-22 17:03:03 +00:00
|
|
|
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"});
|
2021-08-28 14:53:05 +00:00
|
|
|
args::Flag logTimeFlag(parser, "time-log", "Whether to show time logging.", {'t', "time-log"});
|
2021-09-07 17:17:00 +00:00
|
|
|
args::Flag forceColorFlag(parser, "force-color", "Whether to force color text output.", {'c', "force-color"});
|
2021-08-22 17:03:03 +00:00
|
|
|
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()) {
|
2021-08-29 10:14:27 +00:00
|
|
|
chdir((const char*)std::filesystem::path(workingDirectory).c_str());
|
2021-08-22 17:03:03 +00:00
|
|
|
}
|
2021-09-07 17:17:00 +00:00
|
|
|
if (forceColorFlag.Get()){
|
|
|
|
termcolor::colorize(std::cout);
|
|
|
|
}
|
2021-08-22 17:03:03 +00:00
|
|
|
|
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);
|
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);
|
2021-08-28 14:53:05 +00:00
|
|
|
std::chrono::steady_clock::time_point end_build = std::chrono::steady_clock::now();
|
2021-08-23 19:44:59 +00:00
|
|
|
if (!Globals::Library.HasValue()) {
|
2021-08-22 17:03:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2021-08-28 14:53:05 +00:00
|
|
|
if (logTimeFlag.Get()) {
|
|
|
|
std::cout << "Finished building library in: "
|
|
|
|
<< std::chrono::duration_cast<std::chrono::milliseconds>(end_build - begin).count() << "ms"
|
|
|
|
<< std::endl;
|
|
|
|
BuildLibrary::LogBuildTimes();
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
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();
|
2021-08-28 14:53:05 +00:00
|
|
|
std::chrono::steady_clock::time_point beginTests = std::chrono::steady_clock::now();
|
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()
|
2021-08-28 14:53:05 +00:00
|
|
|
<< "ms (of which " << std::chrono::duration_cast<std::chrono::milliseconds>(end - beginTests).count()
|
|
|
|
<< " ms was test runs)" << std::endl;
|
2021-08-26 17:24:35 +00:00
|
|
|
return v;
|
2021-08-22 17:03:03 +00:00
|
|
|
}
|