summaryrefslogtreecommitdiff
path: root/test/source_type_test.cc
blob: 288f1e5b346ee666d5bb05c92112cb0c5aa512ac (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
#include <ctor.h>
#include <task_cc.h>

std::ostream& operator<<(std::ostream& stream, const ctor::language& lang);

#include <uunit.h>

std::ostream& operator<<(std::ostream& stream, const ctor::language& lang)
{
	switch(lang)
	{
	case ctor::language::automatic:
		stream << "ctor::language::automatic";
		break;
	case ctor::language::c:
		stream << "ctor::language::c";
		break;
	case ctor::language::cpp:
		stream << "ctor::language::cpp";
		break;
	case ctor::language::assembler:
		stream << "ctor::language::assembler";
		break;
	}

	return stream;
}

class TestableTaskCC
	: public TaskCC
{
public:
	TestableTaskCC(const ctor::source& source)
		: TaskCC({}, {}, "build", source)
	{}

	ctor::language language() const
	{
		return source_language;
	}
};

class SourceTypeTest
	: public uUnit
{
public:
	SourceTypeTest()
	{
		uTEST(SourceTypeTest::test);
	}

	void test()
	{
		{ // c++
			TestableTaskCC task("hello.cc");
			uASSERT_EQUAL(ctor::language::cpp, task.language());
		}

		{ // c
			TestableTaskCC task("hello.c");
			uASSERT_EQUAL(ctor::language::c, task.language());
		}

		{ // asm
			TestableTaskCC task("hello.s");
			uASSERT_EQUAL(ctor::language::assembler, task.language());
		}

		{ // custom/explicit language
			TestableTaskCC task( {"hello.foo", ctor::language::assembler} );
			uASSERT_EQUAL(ctor::language::assembler, task.language());
		}

		// Note: Failure state will result in exit(1) so cannot be tested
	}
};

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