summaryrefslogtreecommitdiff
path: root/c++/test/suite.cpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2023-12-04 12:18:14 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2023-12-04 12:18:14 +0100
commita14896f9ed209dd3f9597722e5a5697bd7dbf531 (patch)
tree089ca5cbbd206d1921f8f6b53292f5bc1902ca5c /c++/test/suite.cpp
parent84ecdcbca9e55b1f57fbb832e12ff4fdbb86e7c9 (diff)
meta: Renamed folder containing source
Diffstat (limited to 'c++/test/suite.cpp')
-rw-r--r--c++/test/suite.cpp107
1 files changed, 0 insertions, 107 deletions
diff --git a/c++/test/suite.cpp b/c++/test/suite.cpp
deleted file mode 100644
index 0fca8f9..0000000
--- a/c++/test/suite.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-#include "suite.h"
-
-#include <map>
-#include <string>
-#include <chrono>
-#include <iostream>
-
-namespace saw {
-namespace test {
- test_case* testCaseHead = nullptr;
- test_case** testCaseTail = &testCaseHead;
-
- test_case::test_case(const std::string& file_, uint line_, const std::string& description_):
- file{file_},
- line{line_},
- description{description_},
- matched_filter{false},
- next{nullptr},
- prev{testCaseTail}
- {
- *prev = this;
- testCaseTail = &next;
- }
-
- test_case::~test_case(){
- *prev = next;
- if( next == nullptr ){
- testCaseTail = prev;
- }else{
- next->prev = prev;
- }
- }
-
- class test_runner {
- private:
- enum Colour {
- RED,
- GREEN,
- BLUE,
- WHITE
- };
-
- void write(Colour colour, const std::string& front, const std::string& message){
- std::string start_col, end_col;
- switch(colour){
- case RED: start_col = "\033[0;1;31m"; break;
- case GREEN: start_col = "\033[0;1;32m"; break;
- case BLUE: start_col = "\033[0;1;34m"; break;
- case WHITE: start_col = "\033[0m"; break;
- }
- end_col = "\033[0m";
- std::cout<<start_col<<front<<end_col<<message<<'\n';
- }
- public:
- void allowAll(){
- for(test_case* testCase = testCaseHead; testCase != nullptr; testCase = testCase->next){
- testCase->matched_filter = true;
- }
- }
-
- int run() {
- size_t passed_count = 0;
- size_t failed_count = 0;
-
- for(test_case* testCase = testCaseHead; testCase != nullptr; testCase =testCase->next){
- if(testCase->matched_filter){
- std::string name = testCase->file + std::string(":") + std::to_string(testCase->line) + std::string(": ") + testCase->description;
- write(BLUE, "[ TEST ] ", name);
- bool failed = true;
- std::string fail_message;
- auto start_clock = std::chrono::steady_clock::now();
- try {
- testCase->run();
- failed = false;
- }catch(std::exception& e){
- fail_message = e.what();
- failed = true;
- }
- auto stop_clock = std::chrono::steady_clock::now();
-
- auto runtime_duration_intern = stop_clock - start_clock;
- auto runtime_duration = std::chrono::duration_cast<std::chrono::microseconds>(runtime_duration_intern);
- std::string message = name + std::string(" (") + std::to_string(runtime_duration.count()) + std::string(" µs)");
- if(failed){
- write(RED, "[ FAIL ] ", message + " " + fail_message);
- ++failed_count;
- }else{
- write(GREEN, "[ PASS ] ", message);
- ++passed_count;
- }
- }
- }
-
- if(passed_count>0) write(GREEN, std::to_string(passed_count) + std::string(" test(s) passed"), "");
- if(failed_count>0) write(RED, std::to_string(failed_count) + std::string(" test(s) failed"), "");
- return -failed_count;
- }
- };
-}
-}
-
-int main() {
- saw::test::test_runner runner;
- runner.allowAll();
- int rv = runner.run();
- return rv<0?-1:0;
-}