From aca76f6395cc4f398a6b402a0739eed78fc9055d Mon Sep 17 00:00:00 2001 From: Ayrton Chilibeck Date: Sun, 8 Sep 2024 06:12:16 -0600 Subject: [PATCH] Populate result information in TestPair Put the data into the optional. This was surprisingly non-trivial I really hate C++ --- include/testharness/TestHarness.h | 2 +- include/tests/TestResult.h | 19 ++++++++++++++----- src/testharness/TestHarness.cpp | 8 ++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/testharness/TestHarness.h b/include/testharness/TestHarness.h index d4e8e969..3c2d2079 100644 --- a/include/testharness/TestHarness.h +++ b/include/testharness/TestHarness.h @@ -18,7 +18,7 @@ namespace fs = std::filesystem; namespace tester { // Test hierarchy types -typedef std::pair, std::reference_wrapper>> TestPair; +typedef std::pair, std::optional> TestPair; typedef std::vector SubPackage; typedef std::map Package; typedef std::map TestSet; diff --git a/include/tests/TestResult.h b/include/tests/TestResult.h index 62ff9c19..8a1621a1 100644 --- a/include/tests/TestResult.h +++ b/include/tests/TestResult.h @@ -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 diff --git a/src/testharness/TestHarness.cpp b/src/testharness/TestHarness.cpp index d56247da..c702d4fa 100644 --- a/src/testharness/TestHarness.cpp +++ b/src/testharness/TestHarness.cpp @@ -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; @@ -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 res_clone = std::make_optional(result.clone()); + subPackage[i].second.swap(res_clone); + results.addResult(exeName, tcName, subPackageName, result); printTestResult(test.get(), result);