Skip to content

Commit f496af6

Browse files
author
sam
committed
Add option to run test scripts (will use for script-based testing later)
1 parent b3387cb commit f496af6

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

geometrize/cli/commandlineparser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
#include "script/chaiscriptcreator.h"
1414
#include "script/scriptrunner.h"
1515
#include "task/taskutil.h"
16+
#include "test/functionaltestrunner.h"
1617

1718
namespace
1819
{
1920
const QString scriptFileFlag{"script_file"};
2021
const QString scriptSourceFlag{"script_inline"};
2122
const QString localeOverrideFlag{"locale_override"};
23+
const QString selfTestsFlag{"functional_tests"};
2224

2325
/**
2426
* @brief setupCommandLineParser Sets up a command line parser to handle application arguments.
@@ -35,6 +37,7 @@ namespace
3537
parser.addOption(QCommandLineOption(scriptFileFlag, "Executes the ChaiScript script file at the given file path", "File path to ChaiScript script file"));
3638
parser.addOption(QCommandLineOption(scriptSourceFlag, "Executes the inline ChaiScript source code unmodified", "Inline ChaiScript source code"));
3739
parser.addOption(QCommandLineOption(localeOverrideFlag, "Overrides the locale and translation that the application launches with", "Locale code"));
40+
parser.addOption(QCommandLineOption(selfTestsFlag, "Executes the Geometrize functional tests suite", "Flag to additional test scripts folder"));
3841

3942
if(!parser.parse(arguments)) {
4043
assert(0 && "Failed to parse command line arguments");
@@ -60,6 +63,9 @@ namespace
6063

6164
std::unique_ptr<chaiscript::ChaiScript> engine{geometrize::script::createImageTaskEngine()};
6265
geometrize::script::runScript(code, *engine);
66+
} else if(parser.isSet(selfTestsFlag)) {
67+
const std::string testScriptsDirectory{parser.value(selfTestsFlag).toStdString()};
68+
geometrize::test::runSelfTests(testScriptsDirectory);
6369
}
6470
}
6571
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "test/functionaltestrunner.h"
2+
3+
#include <cassert>
4+
#include <string>
5+
#include <vector>
6+
7+
#include "common/util.h"
8+
#include "script/scriptrunner.h"
9+
10+
namespace geometrize
11+
{
12+
13+
namespace test
14+
{
15+
16+
void runSelfTests(const std::string& testScriptsDirectory)
17+
{
18+
if(!geometrize::util::directoryExists(testScriptsDirectory)) {
19+
assert(0 && "Given test scripts directory does not exist");
20+
return;
21+
}
22+
23+
const std::vector<std::string> testScripts{geometrize::util::getScriptsForPath(testScriptsDirectory)};
24+
25+
if(testScripts.empty()) {
26+
assert(0 && "Did not find any test scripts in the given test directory");
27+
return;
28+
}
29+
30+
for(const auto& scriptPath : testScripts) {
31+
const std::string scriptCode = geometrize::util::readFileAsString(scriptPath);
32+
if(scriptCode.empty()) {
33+
assert(0 && "Failed to read script file or it was empty");
34+
}
35+
geometrize::script::runScript(scriptCode);
36+
}
37+
}
38+
39+
}
40+
41+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace geometrize
6+
{
7+
8+
namespace test
9+
{
10+
11+
void runSelfTests(const std::string& testScriptsDirectory);
12+
13+
}
14+
15+
}

0 commit comments

Comments
 (0)