From ba04d2889a4e017c6043bac9951f722e60b63bc5 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 14 Sep 2021 07:46:43 +0200 Subject: Add suport for building and running unittests with the 'check' target. --- src/libctor.cc | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) (limited to 'src/libctor.cc') diff --git a/src/libctor.cc b/src/libctor.cc index c7a7400..e166e51 100644 --- a/src/libctor.cc +++ b/src/libctor.cc @@ -22,6 +22,7 @@ #include "rebuild.h" #include "tasks.h" #include "build.h" +#include "unittest.h" int main(int argc, char* argv[]) { if(argc > 1 && std::string(argv[1]) == "configure") @@ -46,6 +47,7 @@ int main(int argc, char* argv[]) bool list_files{false}; bool list_targets{false}; bool no_relaunch{false}; // true means no re-launch after rebuild. + bool run_unittests{false}; dg::Options opt; int key{128}; @@ -206,12 +208,10 @@ Options: if(list_targets) { no_default_build = true; - for(const auto& task : all_tasks) + auto& targets = getTargets(settings); + for(const auto& target : targets) { - if(task->targetType() != TargetType::Object) - { - std::cout << task->name() << "\n"; - } + std::cout << target.config.target << "\n"; } } @@ -286,13 +286,44 @@ Options: } } } + else if(arg == "check") + { + build_all = false; + run_unittests = true; + + std::vector unittest_targets; + auto& targets = getTargets(settings); + for(const auto& target : targets) + { + if(target.config.type == TargetType::UnitTest) + { + unittest_targets.push_back(target); + } + } + + auto ret = build(settings, "check", unittest_targets, all_tasks); + if(ret != 0) + { + return ret; + } + } else { build_all = false; if(arg == "all") { - auto ret = build(settings, "all", all_tasks, all_tasks); + std::vector non_unittest_targets; + auto& targets = getTargets(settings); + for(const auto& target : targets) + { + if(target.config.type != TargetType::UnitTest) + { + non_unittest_targets.push_back(target); + } + } + + auto ret = build(settings, "all", non_unittest_targets, all_tasks); if(ret != 0) { return ret; @@ -311,12 +342,27 @@ Options: if(build_all) { - auto ret = build(settings, "all", all_tasks, all_tasks); + std::vector non_unittest_targets; + auto& targets = getTargets(settings); + for(const auto& target : targets) + { + if(target.config.type != TargetType::UnitTest) + { + non_unittest_targets.push_back(target); + } + } + + auto ret = build(settings, "all", non_unittest_targets, all_tasks); if(ret != 0) { return ret; } } + if(run_unittests) + { + return runUnitTests(all_tasks, settings); + } + return 0; } -- cgit v1.2.3