diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-29 14:55:51 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-06-09 22:15:32 +0200 |
commit | b74bd9e24e1205b7449404fd05172664b211d82c (patch) | |
tree | af69d4efbdddee347cd82c774880efa6820a0aa2 /test/tasks_test.cc | |
parent | 15eea63a6e7da37e7b4d643f189e6de150268ff8 (diff) |
Make all task lists std::set instead of std::list to make sure to not contain duplicates.
Diffstat (limited to 'test/tasks_test.cc')
-rw-r--r-- | test/tasks_test.cc | 95 |
1 files changed, 50 insertions, 45 deletions
diff --git a/test/tasks_test.cc b/test/tasks_test.cc index 8a15fcd..0eac0a0 100644 --- a/test/tasks_test.cc +++ b/test/tasks_test.cc @@ -37,6 +37,19 @@ BuildConfigurations ctorTestConfigs2() REG(ctorTestConfigs1); REG(ctorTestConfigs2); +std::size_t count(const std::set<std::shared_ptr<Task>>& tasks, + const std::string& name) +{ + auto cnt{0u}; + for(const auto& task : tasks) + { + if(task->target() == name) + { + cnt++; + } + } + return cnt; +} class TestTask : public Task @@ -100,30 +113,22 @@ public: { auto tasks = getTasks(settings); uASSERT_EQUAL(6u, tasks.size()); - auto task = tasks.begin(); - uASSERT_EQUAL("foo/test/target1-foo_cc.o"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target1-bar_c.o"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target1"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target2"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target3"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target4"s, (*task)->target()); + // 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)); } { auto tasks = getTasks(settings, {"target1", "target3"}); uASSERT_EQUAL(4u, tasks.size()); - auto task = tasks.begin(); - uASSERT_EQUAL("foo/test/target1-foo_cc.o"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target1-bar_c.o"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target1"s, (*task)->target()); - task++; - uASSERT_EQUAL("foo/test/target3"s, (*task)->target()); + 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)); } { auto tasks = getTasks(settings, {"no-such-target"}); @@ -137,8 +142,8 @@ public: Settings settings{}; { // Zero (Empty) - std::list<std::shared_ptr<Task>> allTasks; - std::list<std::shared_ptr<Task>> dirtyTasks; + std::set<std::shared_ptr<Task>> allTasks; + std::set<std::shared_ptr<Task>> dirtyTasks; for(auto& task : dirtyTasks) { @@ -151,10 +156,10 @@ public: { // Zero (One task, no dirty) auto task1 = std::make_shared<TestTask>("task1", false); - std::list<std::shared_ptr<Task>> allTasks; - allTasks.push_back(task1); + std::set<std::shared_ptr<Task>> allTasks; + allTasks.insert(task1); - std::list<std::shared_ptr<Task>> dirtyTasks; + std::set<std::shared_ptr<Task>> dirtyTasks; for(auto& task : dirtyTasks) { @@ -167,11 +172,11 @@ public: { // One (One task, one dirty) auto task1 = std::make_shared<TestTask>("task1", true); - std::list<std::shared_ptr<Task>> allTasks; - allTasks.push_back(task1); + std::set<std::shared_ptr<Task>> allTasks; + allTasks.insert(task1); - std::list<std::shared_ptr<Task>> dirtyTasks; - dirtyTasks.push_back(task1); + std::set<std::shared_ptr<Task>> dirtyTasks; + dirtyTasks.insert(task1); for(auto& task : dirtyTasks) { @@ -186,12 +191,12 @@ public: auto task1 = std::make_shared<TestTask>("task1", false); auto task2 = std::make_shared<TestTask>("task2", true); - std::list<std::shared_ptr<Task>> allTasks; - allTasks.push_back(task1); - allTasks.push_back(task2); + std::set<std::shared_ptr<Task>> allTasks; + allTasks.insert(task1); + allTasks.insert(task2); - std::list<std::shared_ptr<Task>> dirtyTasks; - dirtyTasks.push_back(task2); + std::set<std::shared_ptr<Task>> dirtyTasks; + dirtyTasks.insert(task2); for(auto& task : dirtyTasks) { @@ -208,12 +213,12 @@ public: std::vector<std::string> deps = {"task1"}; auto task2 = std::make_shared<TestTask>("task2", true, deps); - std::list<std::shared_ptr<Task>> allTasks; - allTasks.push_back(task1); - allTasks.push_back(task2); + std::set<std::shared_ptr<Task>> allTasks; + allTasks.insert(task1); + allTasks.insert(task2); - std::list<std::shared_ptr<Task>> dirtyTasks; - dirtyTasks.push_back(task2); + std::set<std::shared_ptr<Task>> dirtyTasks; + dirtyTasks.insert(task2); for(auto& task : dirtyTasks) { @@ -230,13 +235,13 @@ public: std::vector<std::string> deps = {"task1"}; auto task2 = std::make_shared<TestTask>("task2", true, deps); - std::list<std::shared_ptr<Task>> allTasks; - allTasks.push_back(task2); - allTasks.push_back(task1); + std::set<std::shared_ptr<Task>> allTasks; + allTasks.insert(task2); + allTasks.insert(task1); - std::list<std::shared_ptr<Task>> dirtyTasks; - dirtyTasks.push_back(task2); - dirtyTasks.push_back(task1); + std::set<std::shared_ptr<Task>> dirtyTasks; + dirtyTasks.insert(task2); + dirtyTasks.insert(task1); for(auto& task : dirtyTasks) { |