diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-30 19:30:29 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-06-09 22:24:44 +0200 |
commit | d9cb571fe126e7e94a52361d733161aa25f23597 (patch) | |
tree | d8d43f18a98ea648bd25cd46921d64d0a96c2802 | |
parent | dafd592cf44c184f9d24e2216bbed5c23e4b23c2 (diff) |
Add UnitTestLib target type, for unit-test only libraries. And fix unit-test linkage.
-rw-r--r-- | src/bootstrap.cc | 3 | ||||
-rw-r--r-- | src/libctor.cc | 9 | ||||
-rw-r--r-- | src/libctor.h | 1 | ||||
-rw-r--r-- | src/tasks.cc | 1 | ||||
-rw-r--r-- | src/unittest.cc | 13 | ||||
-rw-r--r-- | test/ctor.cc | 29 | ||||
-rw-r--r-- | test/tasks_test.cc | 20 |
7 files changed, 56 insertions, 20 deletions
diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 08f7b1f..64f11fc 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -66,7 +66,8 @@ int main(int argc, char* argv[]) auto& targets = getTargets(settings); for(const auto& target : targets) { - if(target.config.type != TargetType::UnitTest) + if(target.config.type != TargetType::UnitTest && + target.config.type != TargetType::UnitTestLib) { non_unittest_targets.push_back(target); } diff --git a/src/libctor.cc b/src/libctor.cc index a2c873e..a4aec86 100644 --- a/src/libctor.cc +++ b/src/libctor.cc @@ -316,7 +316,8 @@ Options: auto& targets = getTargets(settings); for(const auto& target : targets) { - if(target.config.type == TargetType::UnitTest) + if(target.config.type == TargetType::UnitTest || + target.config.type == TargetType::UnitTestLib) { unittest_targets.push_back(target); } @@ -338,7 +339,8 @@ Options: auto& targets = getTargets(settings); for(const auto& target : targets) { - if(target.config.type != TargetType::UnitTest) + if(target.config.type != TargetType::UnitTest && + target.config.type != TargetType::UnitTestLib) { non_unittest_targets.push_back(target); } @@ -367,7 +369,8 @@ Options: auto& targets = getTargets(settings); for(const auto& target : targets) { - if(target.config.type != TargetType::UnitTest) + if(target.config.type != TargetType::UnitTest && + target.config.type != TargetType::UnitTestLib) { non_unittest_targets.push_back(target); } diff --git a/src/libctor.h b/src/libctor.h index 721ac6a..70f2c3e 100644 --- a/src/libctor.h +++ b/src/libctor.h @@ -18,6 +18,7 @@ enum class TargetType DynamicLibrary, Object, UnitTest, + UnitTestLib, }; enum class Language diff --git a/src/tasks.cc b/src/tasks.cc index f24f3cb..af364b9 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -122,6 +122,7 @@ std::set<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config, break; case TargetType::StaticLibrary: + case TargetType::UnitTestLib: tasks.insert(std::make_shared<TaskAR>(config, settings, config.target, objects, sourceDir)); break; diff --git a/src/unittest.cc b/src/unittest.cc index ab82ab9..02f4229 100644 --- a/src/unittest.cc +++ b/src/unittest.cc @@ -19,16 +19,21 @@ int runUnitTests(std::set<std::shared_ptr<Task>>& tasks, { if(task->targetType() == TargetType::UnitTest) { - std::cout << task->name() << ": "; - auto ret = execute(task->targetFile(), {}, false); + auto name = task->name(); + if(name.empty()) + { + name = task->target(); + } + std::cout << name << ": " << std::flush; + auto ret = execute(task->targetFile(), {}, settings.verbose > 0); ok &= ret == 0; if(ret == 0) { - std::cout << "OK\n"; + std::cout << " OK\n"; } else { - std::cout << "FAILED\n"; + std::cout << " FAILED\n"; } } } diff --git a/test/ctor.cc b/test/ctor.cc index 6515c72..66f20f2 100644 --- a/test/ctor.cc +++ b/test/ctor.cc @@ -33,7 +33,7 @@ BuildConfigurations ctorTestConfigs() "tasks_test.cc", "testmain.cc", }, - .depends = {"libctor.a"}, + .depends = { "libctor_nomain.a" }, .flags = { .cxxflags = { "-std=c++20", "-O3", "-s", "-Wall", "-Werror", @@ -50,7 +50,7 @@ BuildConfigurations ctorTestConfigs() "source_type_test.cc", "testmain.cc", }, - .depends = {"libctor.a"}, + .depends = { "libctor_nomain.a" }, .flags = { .cxxflags = { "-std=c++20", "-O3", "-s", "-Wall", "-Werror", @@ -60,6 +60,31 @@ BuildConfigurations ctorTestConfigs() .ldflags = { "-pthread" }, }, }, + { + .type = TargetType::UnitTestLib, + .target = "libctor_nomain.a", + .sources = { + "../src/build.cc", + "../src/configure.cc", + "../src/execute.cc", + "../src/rebuild.cc", + "../src/tasks.cc", + "../src/task.cc", + "../src/task_ar.cc", + "../src/task_cc.cc", + "../src/task_ld.cc", + "../src/task_so.cc", + "../src/util.cc", + "../src/externals_manual.cc", + }, + .flags = { + .cxxflags = { + "-std=c++20", "-O3", "-s", "-Wall", "-Werror", + "-I../src", + }, + .ldflags = { "-pthread" }, + }, + }, }; } } diff --git a/test/tasks_test.cc b/test/tasks_test.cc index 82296b7..a807d32 100644 --- a/test/tasks_test.cc +++ b/test/tasks_test.cc @@ -116,20 +116,20 @@ public: uASSERT_EQUAL(6u, tasks.size()); // Note: count() is used here because the order of // std::set<std::shared_ptr<T>> is not deterministic. - uASSERT_EQUAL(1u, count(tasks, "foo/test/target1"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target2"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target3"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target4"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target1-foo_cc.o"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target1-bar_c.o"s)); + uASSERT_EQUAL(1u, count(tasks, "target1"s)); + uASSERT_EQUAL(1u, count(tasks, "target2"s)); + uASSERT_EQUAL(1u, count(tasks, "target3"s)); + uASSERT_EQUAL(1u, count(tasks, "target4"s)); + uASSERT_EQUAL(1u, count(tasks, "test/target1-foo_cc.o"s)); + uASSERT_EQUAL(1u, count(tasks, "test/target1-bar_c.o"s)); } { auto tasks = getTasks(settings, {"target1", "target3"}); uASSERT_EQUAL(4u, tasks.size()); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target1"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target3"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target1-foo_cc.o"s)); - uASSERT_EQUAL(1u, count(tasks, "foo/test/target1-bar_c.o"s)); + uASSERT_EQUAL(1u, count(tasks, "target1"s)); + uASSERT_EQUAL(1u, count(tasks, "target3"s)); + uASSERT_EQUAL(1u, count(tasks, "test/target1-foo_cc.o"s)); + uASSERT_EQUAL(1u, count(tasks, "test/target1-bar_c.o"s)); } { auto tasks = getTasks(settings, {"no-such-target"}); |