summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/task_cc.h2
-rw-r--r--test/ctor.cc14
-rw-r--r--test/source_type_test.cc77
3 files changed, 92 insertions, 1 deletions
diff --git a/src/task_cc.h b/src/task_cc.h
index 67d8d45..f5ae95d 100644
--- a/src/task_cc.h
+++ b/src/task_cc.h
@@ -33,7 +33,7 @@ public:
std::string toJSON() const override;
-private:
+protected:
std::vector<std::string> flags() const;
std::string flagsString() const;
std::vector<std::string> getCompilerArgs() const;
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;