Skip to content

Commit

Permalink
Populate result information in TestPair
Browse files Browse the repository at this point in the history
Put the data into the optional. This was surprisingly non-trivial

I really hate C++
  • Loading branch information
Sir-NoChill committed Sep 8, 2024
1 parent 90ff2c1 commit aca76f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/testharness/TestHarness.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace fs = std::filesystem;
namespace tester {

// Test hierarchy types
typedef std::pair<std::unique_ptr<TestFile>, std::reference_wrapper<std::optional<TestResult>>> TestPair;
typedef std::pair<std::unique_ptr<TestFile>, std::optional<TestResult>> TestPair;
typedef std::vector<TestPair> SubPackage;
typedef std::map<std::string, SubPackage> Package;
typedef std::map<std::string, Package> TestSet;
Expand Down
19 changes: 14 additions & 5 deletions include/tests/TestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ struct TestResult {
: name(in.stem()), pass(pass), error(error), diff(diff) {}

// Info about result.
const fs::path name;
const bool pass;
const bool error;
const std::string diff;
};
fs::path name;
bool pass;
bool error;
std::string diff;

TestResult clone() { return TestResult(this->name, this->pass, this->error, this->diff); }

void swap(TestResult &other) {
std::swap(name, other.name);
std::swap(pass, other.pass);
std::swap(error, other.error);
std::swap(diff, other.diff);
}

};
} // End namespace tester

#endif // TESTER_TEST_RESULT_H
8 changes: 8 additions & 0 deletions src/testharness/TestHarness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

namespace tester {

void swap(TestResult& first, TestResult& second) {
std::swap(first, second);
}

// Builds TestSet during object creation.
bool TestHarness::runTests() {
bool failed = false;
Expand Down Expand Up @@ -88,6 +92,10 @@ bool TestHarness::runTestsForToolChain(std::string exeName, std::string tcName)
if (test->getParseError() == ParseError::NoError) {

TestResult result = runTest(test.get(), toolChain, cfg);
// keep the result with the test for pretty printing
std::optional<TestResult> res_clone = std::make_optional(result.clone());
subPackage[i].second.swap(res_clone);

results.addResult(exeName, tcName, subPackageName, result);
printTestResult(test.get(), result);

Expand Down

0 comments on commit aca76f6

Please sign in to comment.