|
|
|
@ -1,19 +1,51 @@ |
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
|
#include <fmt/core.h> |
|
|
|
#include <fmt/core.h> |
|
|
|
#include <fuc2/run.hpp> |
|
|
|
#include <fuc2/run.hpp> |
|
|
|
|
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
|
|
|
|
namespace fuc2 { |
|
|
|
namespace fuc2 { |
|
|
|
int run(const Set& test_set) { |
|
|
|
Options parse_options(int argc, char* argv[]) { |
|
|
|
|
|
|
|
Options result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int opt = 0; |
|
|
|
|
|
|
|
while((opt = getopt(argc, argv, "fvn:")) != -1) { |
|
|
|
|
|
|
|
switch(opt) { |
|
|
|
|
|
|
|
case 'f': |
|
|
|
|
|
|
|
result.fail_fast = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'v': |
|
|
|
|
|
|
|
result.verbose = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'n': |
|
|
|
|
|
|
|
result.matching = std::string(optarg); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int run(const Set& test_set, const Options& cli_opts, bool gave_opts) { |
|
|
|
int fail_count = 0; |
|
|
|
int fail_count = 0; |
|
|
|
std::vector<std::string> errors; |
|
|
|
std::vector<std::string> errors; |
|
|
|
std::string file_name = test_set.location.file_name(); |
|
|
|
std::string file_name = test_set.location.file_name(); |
|
|
|
|
|
|
|
Options opts = gave_opts ? cli_opts : test_set.options; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(opts.disabled) { |
|
|
|
|
|
|
|
fmt::println("! DISABLED: {}", file_name); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(opts.verbose) { |
|
|
|
|
|
|
|
fmt::println("################# {} \"{}\" ###############", file_name, test_set.name); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fmt::println("> {} \"{}\"", file_name, test_set.name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt::println("################# {} \"{}\" ###############", |
|
|
|
|
|
|
|
file_name, test_set.name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(const auto& [name, test] : test_set.tests) { |
|
|
|
for(const auto& [name, test] : test_set.tests) { |
|
|
|
bool did_fail = false; |
|
|
|
bool did_fail = false; |
|
|
|
fmt::println("----------- START {}", name); |
|
|
|
if(opts.verbose) fmt::println("----------- START {}", name); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
test(); |
|
|
|
test(); |
|
|
|
@ -23,20 +55,24 @@ namespace fuc2 { |
|
|
|
fmt::println("🚨 FAIL! {}", e.what()); |
|
|
|
fmt::println("🚨 FAIL! {}", e.what()); |
|
|
|
errors.push_back(e.what()); |
|
|
|
errors.push_back(e.what()); |
|
|
|
|
|
|
|
|
|
|
|
if(test_set.options.fail_fast) { |
|
|
|
if(opts.fail_fast) { |
|
|
|
|
|
|
|
fmt::println("FAIL FAST (-f) SET, STOPPING"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string pass_fail = did_fail ? "🔴" : "🟢"; |
|
|
|
std::string pass_fail = did_fail ? "🔴" : "🟢"; |
|
|
|
fmt::println("{} {}:{}\n==========", pass_fail, file_name, name); |
|
|
|
fmt::println("{} {}:{}", pass_fail, file_name, name); |
|
|
|
|
|
|
|
if(opts.verbose) fmt::println("=========="); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(fail_count > 0) { |
|
|
|
if(fail_count > 0) { |
|
|
|
fmt::println("🚨🚨🚨🚨🚨 FAIL COUNT: {} in {}", fail_count, file_name); |
|
|
|
fmt::println("🚨🚨🚨🚨🚨 FAIL COUNT: {} in {}", fail_count, file_name); |
|
|
|
|
|
|
|
|
|
|
|
for(auto& msg : errors) { |
|
|
|
if(opts.verbose) { |
|
|
|
fmt::println("---------\n{}", msg); |
|
|
|
for(auto& msg : errors) { |
|
|
|
|
|
|
|
fmt::println("---------\n{}", msg); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt::println("👍 ALL PASS: {}", file_name); |
|
|
|
fmt::println("👍 ALL PASS: {}", file_name); |
|
|
|
@ -44,4 +80,15 @@ namespace fuc2 { |
|
|
|
|
|
|
|
|
|
|
|
return fail_count; |
|
|
|
return fail_count; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int run_tests(const std::vector<Set>& tests, int argc, char* argv[]) { |
|
|
|
|
|
|
|
int fail_count = 0; |
|
|
|
|
|
|
|
auto opts = parse_options(argc, argv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto& test : tests) { |
|
|
|
|
|
|
|
fail_count += run(test, opts, argc > 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fail_count; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|