diff --git a/geometrize/cli/commandlineparser.cpp b/geometrize/cli/commandlineparser.cpp index ae9ae847..4514fcac 100644 --- a/geometrize/cli/commandlineparser.cpp +++ b/geometrize/cli/commandlineparser.cpp @@ -13,12 +13,14 @@ #include "script/chaiscriptcreator.h" #include "script/scriptrunner.h" #include "task/taskutil.h" +#include "test/functionaltestrunner.h" namespace { const QString scriptFileFlag{"script_file"}; const QString scriptSourceFlag{"script_inline"}; const QString localeOverrideFlag{"locale_override"}; + const QString selfTestsFlag{"functional_tests"}; /** * @brief setupCommandLineParser Sets up a command line parser to handle application arguments. @@ -35,6 +37,7 @@ namespace parser.addOption(QCommandLineOption(scriptFileFlag, "Executes the ChaiScript script file at the given file path", "File path to ChaiScript script file")); parser.addOption(QCommandLineOption(scriptSourceFlag, "Executes the inline ChaiScript source code unmodified", "Inline ChaiScript source code")); parser.addOption(QCommandLineOption(localeOverrideFlag, "Overrides the locale and translation that the application launches with", "Locale code")); + parser.addOption(QCommandLineOption(selfTestsFlag, "Executes the Geometrize functional tests suite", "Flag to additional test scripts folder")); if(!parser.parse(arguments)) { assert(0 && "Failed to parse command line arguments"); @@ -60,6 +63,9 @@ namespace std::unique_ptr engine{geometrize::script::createImageTaskEngine()}; geometrize::script::runScript(code, *engine); + } else if(parser.isSet(selfTestsFlag)) { + const std::string testScriptsDirectory{parser.value(selfTestsFlag).toStdString()}; + geometrize::test::runSelfTests(testScriptsDirectory); } } } diff --git a/geometrize/test/functionaltestrunner.cpp b/geometrize/test/functionaltestrunner.cpp new file mode 100644 index 00000000..9679065f --- /dev/null +++ b/geometrize/test/functionaltestrunner.cpp @@ -0,0 +1,41 @@ +#include "test/functionaltestrunner.h" + +#include +#include +#include + +#include "common/util.h" +#include "script/scriptrunner.h" + +namespace geometrize +{ + +namespace test +{ + +void runSelfTests(const std::string& testScriptsDirectory) +{ + if(!geometrize::util::directoryExists(testScriptsDirectory)) { + assert(0 && "Given test scripts directory does not exist"); + return; + } + + const std::vector testScripts{geometrize::util::getScriptsForPath(testScriptsDirectory)}; + + if(testScripts.empty()) { + assert(0 && "Did not find any test scripts in the given test directory"); + return; + } + + for(const auto& scriptPath : testScripts) { + const std::string scriptCode = geometrize::util::readFileAsString(scriptPath); + if(scriptCode.empty()) { + assert(0 && "Failed to read script file or it was empty"); + } + geometrize::script::runScript(scriptCode); + } +} + +} + +} diff --git a/geometrize/test/functionaltestrunner.h b/geometrize/test/functionaltestrunner.h new file mode 100644 index 00000000..83a7c358 --- /dev/null +++ b/geometrize/test/functionaltestrunner.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace geometrize +{ + +namespace test +{ + +void runSelfTests(const std::string& testScriptsDirectory); + +} + +}