summaryrefslogtreecommitdiff
path: root/test/cycle_test.cc
blob: 3b456323966cd977aa7ef696e91b51e2230069f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <uunit.h>

#include <ctor.h>
#include <build.h>

namespace
{
ctor::build_configurations ctorTestConfigsCyclic(const ctor::settings&)
{
	return
	{
		// No dependency
		{
			.target = "target0",
		},

		// Direct (self-depends)
		{
			.target = "target1",
			.depends = { "target1" },
		},

		// Indirect cyclic depends
		{
			.target = "target2",
			.depends = { "target3" },
		},
		{
			.target = "target3",
			.depends = { "target2" },
		},
	};
}
}

REG(ctorTestConfigsCyclic);

class CycleTest
	: public uUnit
{
public:
	CycleTest()
	{
		uTEST(CycleTest::getTargets_test);
	}

	void getTargets_test()
	{
		using namespace std::string_literals;
		ctor::settings settings{};
		const auto& tasks = getTasks(settings);
		uASSERT_EQUAL(4u, tasks.size());

		uASSERT_EQUAL("target0"s, tasks[0]->target());
		uASSERT_EQUAL("target1"s, tasks[1]->target());
		uASSERT_EQUAL("target2"s, tasks[2]->target());
		uASSERT_EQUAL("target3"s, tasks[3]->target());

		for(auto task : tasks)
		{
			if(task->registerDepTasks(tasks))
			{
				uASSERT(false);
			}
		}

		bool exc;
		exc = false;
		try { getDepTasks(tasks[0]); } catch(...) { exc = true; }
		uASSERT(!exc);

		exc = false;
		try { getDepTasks(tasks[1]); } catch(...) { exc = true; }
		uASSERT(exc);

		exc = false;
		try { getDepTasks(tasks[2]); } catch(...) { exc = true; }
		uASSERT(exc);

		exc = false;
		try { getDepTasks(tasks[3]); } catch(...) { exc = true; }
		uASSERT(exc);
	}
};

// Registers the fixture into the 'registry'
static CycleTest test;