summaryrefslogtreecommitdiff
path: root/test/tasks_test.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2025-01-17 09:49:35 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2025-01-20 17:24:44 +0100
commitc034ebb36e5d23ba1a4e7e123c7dce4f3ea7bba9 (patch)
tree5b3f8a6ab78815e0437a70c785fe737f360dd667 /test/tasks_test.cc
parent4f77a82425f60ff928880048dfa79fdd6fba56d8 (diff)
Refactor task == std::string comparison
Diffstat (limited to 'test/tasks_test.cc')
-rw-r--r--test/tasks_test.cc73
1 files changed, 62 insertions, 11 deletions
diff --git a/test/tasks_test.cc b/test/tasks_test.cc
index 3de6982..8e00974 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"},
},
@@ -54,16 +55,17 @@ class TestTask
: public Task
{
public:
- TestTask(const std::string& name, bool dirty,
+ TestTask(const ctor::build_configuration& config,
+ const ctor::settings& settings,
+ const std::string& name, bool dirty,
const std::vector<std::string>& deps = {})
- : Task({}, {}, {})
+ : Task(config, settings, {})
, task_name(name)
, task_dirty(dirty)
, task_deps(deps)
{
}
- 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 +88,7 @@ public:
uTEST(TasksTest::getTargets_test);
uTEST(TasksTest::getTasks_test);
uTEST(TasksTest::getNextTask_test);
+ uTEST(TasksTest::comparison_test);
}
void getTargets_test()
@@ -153,7 +156,8 @@ public:
}
{ // Zero (One task, no dirty)
- auto task1 = std::make_shared<TestTask>("task1", false);
+ ctor::build_configuration config;
+ auto task1 = std::make_shared<TestTask>(config, settings, "task1", false);
std::vector<std::shared_ptr<Task>> allTasks;
allTasks.push_back(task1);
@@ -169,7 +173,8 @@ public:
}
{ // One (One task, one dirty)
- auto task1 = std::make_shared<TestTask>("task1", true);
+ ctor::build_configuration config;
+ auto task1 = std::make_shared<TestTask>(config, settings, "task1", true);
std::vector<std::shared_ptr<Task>> allTasks;
allTasks.push_back(task1);
@@ -187,8 +192,9 @@ public:
}
{ // One (Two tasks, one dirty)
- auto task1 = std::make_shared<TestTask>("task1", false);
- auto task2 = std::make_shared<TestTask>("task2", true);
+ ctor::build_configuration config;
+ auto task1 = std::make_shared<TestTask>(config, settings, "task1", false);
+ auto task2 = std::make_shared<TestTask>(config, settings, "task2", true);
std::vector<std::shared_ptr<Task>> allTasks;
allTasks.push_back(task1);
@@ -207,10 +213,12 @@ public:
}
{ // One (Two tasks, one dirty which depends on the other)
- auto task1 = std::make_shared<TestTask>("task1", false);
+ ctor::build_configuration config;
+ auto task1 = std::make_shared<TestTask>(config, settings, "task1", false);
std::vector<std::string> deps = {"task1"};
- auto task2 = std::make_shared<TestTask>("task2", true, deps);
+ auto task2 =
+ std::make_shared<TestTask>(config, settings, "task2", true, deps);
std::vector<std::shared_ptr<Task>> allTasks;
allTasks.push_back(task1);
@@ -229,10 +237,12 @@ public:
}
{ // One (Two tasks, Both dirty, one depends on the other)
- auto task1 = std::make_shared<TestTask>("task1", true);
+ ctor::build_configuration config{};
+ auto task1 = std::make_shared<TestTask>(config, settings, "task1", true);
std::vector<std::string> deps = {"task1"};
- auto task2 = std::make_shared<TestTask>("task2", true, deps);
+ auto task2 =
+ std::make_shared<TestTask>(config, settings, "task2", true, deps);
std::vector<std::shared_ptr<Task>> allTasks;
allTasks.push_back(task2);
@@ -250,7 +260,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);
+ }
}
};