diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-09-25 15:14:45 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-09-25 15:14:45 +0200 |
commit | f30d40ec44e7bb4dda5cdd75e9761d67288af4a7 (patch) | |
tree | 8383509abf4a6d0fafa233c2cd891df309f43b36 | |
parent | 019ee9f3026a419cd25916974d32fe1ebcff9578 (diff) |
Add unit-test for source language deduction.
-rw-r--r-- | src/task_cc.h | 2 | ||||
-rw-r--r-- | test/ctor.cc | 14 | ||||
-rw-r--r-- | test/source_type_test.cc | 77 |
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; |