diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-01-17 09:49:35 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-01-17 09:49:35 +0100 |
commit | a9a8bcf32232a99740d9c23b7c5f8af20de09741 (patch) | |
tree | 15c32c9c2f0b88f90a56831d95e5e749a1ec517c | |
parent | 4f77a82425f60ff928880048dfa79fdd6fba56d8 (diff) |
Refactor task == std::string comparisondiverse
-rw-r--r-- | src/task.cc | 9 | ||||
-rw-r--r-- | src/task.h | 2 | ||||
-rw-r--r-- | src/task_cc.cc | 5 | ||||
-rw-r--r-- | src/task_cc.h | 1 | ||||
-rw-r--r-- | test/tasks_test.cc | 44 |
5 files changed, 49 insertions, 12 deletions
diff --git a/src/task.cc b/src/task.cc index cd03fce..ef7731b 100644 --- a/src/task.cc +++ b/src/task.cc @@ -48,10 +48,11 @@ bool Task::operator==(const std::string& depStr) std::filesystem::path generated_output = sourceDir; generated_output /= target(); return - name() == depStr || - target() == depStr || - generated_output == depStr || - targetFile().string() == depStr + (!derived() && name() == depStr) || // compare to name + (!derived() && config.target == depStr) || // compare to stated target (ex. foo.a) + target() == depStr || // compare to derived (derived to foo.lib on msvc) + generated_output == depStr || // not sure what this is for?! + targetFile().string() == depStr // compare to target output file ; } @@ -32,7 +32,7 @@ public: bool operator==(const std::string& dep); - virtual std::string name() const; + std::string name() const; bool dirty(); bool ready(); int run(); diff --git a/src/task_cc.cc b/src/task_cc.cc index 9de2657..f4a754f 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -90,11 +90,6 @@ int TaskCC::registerDepTasksInner(const std::vector<std::shared_ptr<Task>>& task return 0; } -std::string TaskCC::name() const -{ - return {}; -} - bool TaskCC::dirtyInner() { if(!std::filesystem::exists(sourceFile)) diff --git a/src/task_cc.h b/src/task_cc.h index 6c4683a..2299fcd 100644 --- a/src/task_cc.h +++ b/src/task_cc.h @@ -21,7 +21,6 @@ public: int registerDepTasksInner(const std::vector<std::shared_ptr<Task>>& tasks) override; - std::string name() const override; bool dirtyInner() override; int runInner() override; diff --git a/test/tasks_test.cc b/test/tasks_test.cc index 3de6982..555fcc6 100644 --- a/test/tasks_test.cc +++ b/test/tasks_test.cc @@ -10,6 +10,7 @@ ctor::build_configurations ctorTestConfigs1(const ctor::settings&) return { { + .name = "Target1", .target = "target1", .sources = {"foo.cc", "bar.c"}, }, @@ -63,7 +64,6 @@ public: { } - std::string name() const override { return task_name; } int clean() override { return 0; } std::vector<std::string> depends() const override { return task_deps; } std::string target() const override { return task_name; } @@ -86,6 +86,7 @@ public: uTEST(TasksTest::getTargets_test); uTEST(TasksTest::getTasks_test); uTEST(TasksTest::getNextTask_test); + uTEST(TasksTest::comparison_test); } void getTargets_test() @@ -250,7 +251,48 @@ public: uASSERT_EQUAL(task1, getNextTask(allTasks, dirtyTasks)); uASSERT_EQUAL(1u, dirtyTasks.size()); } + } + void comparison_test() + { + using namespace std::string_literals; + ctor::settings settings{ .builddir = "foo" }; + { // Test Task::operator== + auto tasks = getTasks(settings, {"target1"}); + uASSERT_EQUAL(3u, tasks.size()); + uASSERT_EQUAL(1u, count(tasks, "target1"s)); + uASSERT_EQUAL(1u, count(tasks, "test/target1-foo_cc.o"s)); + uASSERT_EQUAL(1u, count(tasks, "test/target1-bar_c.o"s)); + + int cnt1{}; + int cnt2{}; + int cnt3{}; + for(const auto& task : tasks) + { + if(task->target() == "target1"s) + { + ++cnt1; + uASSERT(*task == "target1"); + uASSERT(*task == "Target1"); + } + if(task->target() == "test/target1-foo_cc.o"s) + { + ++cnt2; + uASSERT(*task != "target1"); + uASSERT(*task != "Target1"); + } + if(task->target() == "test/target1-bar_c.o"s) + { + ++cnt3; + uASSERT(*task != "target1"); + uASSERT(*task != "Target1"); + } + } + // Assert that we did actually perform all three tests exactly once + uASSERT_EQUAL(1, cnt1); + uASSERT_EQUAL(1, cnt2); + uASSERT_EQUAL(1, cnt3); + } } }; |