summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ctor.cc14
-rw-r--r--test/source_type_test.cc77
2 files changed, 91 insertions, 0 deletions
diff --git a/test/ctor.cc b/test/ctor.cc
index 8080d61..3d05e7f 100644
--- a/test/ctor.cc
+++ b/test/ctor.cc
@@ -37,6 +37,20 @@ BuildConfigurations ctorTestConfigs()
"-DOUTPUT=\"tasks\"",
},
},
+ {
+ .type = TargetType::UnitTest,
+ .target = "source_type_test",
+ .sources = {
+ "source_type_test.cc",
+ "uunit/uunit.cc",
+ },
+ .depends = {"libctor.a"},
+ .cxxflags = {
+ "-std=c++17", "-O3", "-s", "-Wall", "-Werror",
+ "-I../src", "-Iuunit",
+ "-DOUTPUT=\"source_type\"",
+ },
+ },
};
}
}
diff --git a/test/source_type_test.cc b/test/source_type_test.cc
new file mode 100644
index 0000000..2da1ac4
--- /dev/null
+++ b/test/source_type_test.cc
@@ -0,0 +1,77 @@
+#include <uunit.h>
+
+#include <libctor.h>
+#include <task_cc.h>
+#include <settings.h>
+
+std::ostream& operator<<(std::ostream& stream, const Language& lang)
+{
+ switch(lang)
+ {
+ case Language::Auto:
+ stream << "Language::Auto";
+ break;
+ case Language::C:
+ stream << "Language::C";
+ break;
+ case Language::Cpp:
+ stream << "Language::Cpp";
+ break;
+ case Language::Asm:
+ stream << "Language::Asm";
+ break;
+ }
+
+ return stream;
+}
+class TestableTaskCC
+ : public TaskCC
+{
+public:
+ TestableTaskCC(const Source& source)
+ : TaskCC({}, {}, {}, source)
+ {}
+
+ Language language() const
+ {
+ return source_language;
+ }
+};
+
+class SourceTypeTest
+ : public uUnit
+{
+public:
+ SourceTypeTest()
+ {
+ uTEST(SourceTypeTest::test);
+ }
+
+ void test()
+ {
+ { // c++
+ TestableTaskCC task("hello.cc");
+ uASSERT_EQUAL(Language::Cpp, task.language());
+ }
+
+ { // c
+ TestableTaskCC task("hello.c");
+ uASSERT_EQUAL(Language::C, task.language());
+ }
+
+ { // asm
+ TestableTaskCC task("hello.s");
+ uASSERT_EQUAL(Language::Asm, task.language());
+ }
+
+ { // custom/explicit language
+ TestableTaskCC task( {"hello.foo", Language::Asm} );
+ uASSERT_EQUAL(Language::Asm, task.language());
+ }
+
+ // Note: Failure state will result in exit(1) so cannot be tested
+ }
+};
+
+// Registers the fixture into the 'registry'
+static SourceTypeTest test;