From 5680cfbda0db138e9a8d357c7f8b708ff4b8b559 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 8 Nov 2024 15:14:35 -0700 Subject: [PATCH] Working --- tst/CMakeLists.txt | 13 +++++++++ tst/unit/CMakeLists.txt | 16 ++++++++++- tst/unit/main.cpp | 63 +++++++++++++++++++++++++++++++++++------ 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/tst/CMakeLists.txt b/tst/CMakeLists.txt index 269aea0..3316052 100644 --- a/tst/CMakeLists.txt +++ b/tst/CMakeLists.txt @@ -1 +1,14 @@ +# ======================================================================================== +# (C) (or copyright) 2024. Triad National Security, LLC. All rights reserved. +# +# This program was produced under U.S. Government contract 89233218CNA000001 for Los +# Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC +# for the U.S. Department of Energy/National Nuclear Security Administration. All rights +# in the program are reserved by Triad National Security, LLC, and the U.S. Department +# of Energy/National Nuclear Security Administration. The Government is granted for +# itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide +# license in this material to reproduce, prepare derivative works, distribute copies to +# the public, perform publicly and display publicly, and to permit others to do so. +# ======================================================================================== + add_subdirectory(unit) diff --git a/tst/unit/CMakeLists.txt b/tst/unit/CMakeLists.txt index 86aae3f..02194c6 100644 --- a/tst/unit/CMakeLists.txt +++ b/tst/unit/CMakeLists.txt @@ -1,4 +1,18 @@ -# CMakeLists.txt +# ======================================================================================== +# (C) (or copyright) 2024. Triad National Security, LLC. All rights reserved. +# +# This program was produced under U.S. Government contract 89233218CNA000001 for Los +# Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC +# for the U.S. Department of Energy/National Nuclear Security Administration. All rights +# in the program are reserved by Triad National Security, LLC, and the U.S. Department +# of Energy/National Nuclear Security Administration. The Government is granted for +# itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide +# license in this material to reproduce, prepare derivative works, distribute copies to +# the public, perform publicly and display publicly, and to permit others to do so. +# ======================================================================================== + +# This file was generated in part or in whole by one of OpenAI's generative AI models. + cmake_minimum_required(VERSION 3.10) project(unit_tests) diff --git a/tst/unit/main.cpp b/tst/unit/main.cpp index 79873aa..01dfb69 100644 --- a/tst/unit/main.cpp +++ b/tst/unit/main.cpp @@ -11,29 +11,59 @@ // the public, perform publicly and display publicly, and to permit others to do so. //======================================================================================== -// This code was generated in whole or in part by one of OpenAI's generative AI models. +// This file was generated in part or in whole by one of OpenAI's generative AI models. #include #include #include #include +struct UnitTestResult { + bool success; + std::string message; +}; + // Temporary testing -void test_function1() {} -void test_function2() {} +UnitTestResult test_function1() { + UnitTestResult result; + result.success = true; + return result; +} +UnitTestResult test_function2() { + UnitTestResult result; + result.success = false; + return result; +} + +UnitTestResult run_test(std::pair> test) { + auto test_name = test.first; + std::cout << "Running " << test_name << "..." << std::endl; + auto result = test.second(); + if (result.success == true) { + printf("Test succeeded!\n"); + } else { + printf("Test FAILED!\n"); + } + return result; +} int main(int argc, char *argv[]) { // Map of test names to test functions - std::map> tests = { + std::map> tests = { {"test1", test_function1}, {"test2", test_function2}, // Add more test mappings here }; + std::map results; + bool all_tests_succeeded = true; + if (argc == 1) { // No test name provided, run all tests for (const auto &test : tests) { - std::cout << "Running " << test.first << "..." << std::endl; - test.second(); + results[test.first] = run_test(test); + if (!results.at(test.first).success) { + all_tests_succeeded = false; + } } } else { // Run specified test(s) @@ -41,13 +71,30 @@ int main(int argc, char *argv[]) { std::string test_name = argv[i]; auto it = tests.find(test_name); if (it != tests.end()) { - std::cout << "Running " << test_name << "..." << std::endl; - it->second(); + results[(*it).first] = run_test(*it); + if (!results.at((*it).first).success) { + all_tests_succeeded = false; + } } else { std::cerr << "Test \"" << test_name << "\" not found." << std::endl; } } } + printf("\n"); + if (results.size() == 0) { + printf("No tests found!\n"); + } else { + if (all_tests_succeeded) { + printf("All tests SUCCEEDED!\n"); + } else { + printf("Some tests FAILED!\n"); + } + for (auto result : results) { + printf(" %s: %s\n", result.first.c_str(), + result.second.success ? "SUCCESS" : "FAILURE"); + } + } + return 0; }