diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ctor.cc | 20 | ||||
-rw-r--r-- | test/deps_test.cc | 97 | ||||
-rw-r--r-- | test/deps_test_data/empty.d | 0 | ||||
-rw-r--r-- | test/deps_test_data/missing_colon.d | 1 | ||||
-rw-r--r-- | test/deps_test_data/multiline.d | 4 | ||||
-rw-r--r-- | test/deps_test_data/no_deps.d | 1 | ||||
-rw-r--r-- | test/deps_test_data/no_newline.d | 1 | ||||
-rw-r--r-- | test/deps_test_data/spaces.d | 1 | ||||
-rw-r--r-- | test/deps_test_data/trivial.d | 1 |
9 files changed, 126 insertions, 0 deletions
diff --git a/test/ctor.cc b/test/ctor.cc index ccf1c31..1951a30 100644 --- a/test/ctor.cc +++ b/test/ctor.cc @@ -12,6 +12,25 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) { .type = ctor::target_type::unit_test, .system = ctor::output_system::build, + .target = "deps_test", + .sources = { + "deps_test.cc", + "testmain.cc", + "../src/deps.cc", + "../src/util.cc", + }, + .depends = { "testprog", }, + .flags = { + .cxxflags = { + "-std=c++20", "-O3", "-Wall", "-Werror", + "-I../src", "-Iuunit", + "-DOUTPUT=\"deps\"", + }, + }, + }, + { + .type = ctor::target_type::unit_test, + .system = ctor::output_system::build, .target = "testprog", .sources = { "testprog.cc", @@ -104,6 +123,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) .sources = { "../src/build.cc", "../src/configure.cc", + "../src/deps.cc", "../src/execute.cc", "../src/rebuild.cc", "../src/tasks.cc", diff --git a/test/deps_test.cc b/test/deps_test.cc new file mode 100644 index 0000000..762b0e5 --- /dev/null +++ b/test/deps_test.cc @@ -0,0 +1,97 @@ +#include <uunit.h> + +#include <fstream> +#include <map> +#include <vector> + +#include <deps.h> +#include <algorithm> + +#include "paths.h" +#include "tmpfile.h" + +class DepsTest + : public uUnit +{ +public: + DepsTest() + { + uTEST(DepsTest::parser_test); + } + + void parser_test() + { + using namespace std::string_literals; + + auto test_data = paths::top_srcdir / "test" / "deps_test_data"; + + auto empty = test_data / "empty.d"; + auto trivial = test_data / "trivial.d"; + auto no_newline = test_data / "no_newline.d"; + auto no_deps = test_data / "no_deps.d"; + auto trailing_whitespace = test_data / "trailing_whitespace.d"; + auto spaces = test_data / "spaces.d"; + auto multiline = test_data / "multiline.d"; + auto no_such_file = test_data / "no_such_file.d"; // doesn't exist + auto missing_colon = test_data / "missing_colon.d"; + + { + auto res = readDeps(empty.string(), ctor::toolchain::gcc); + uASSERT(res.empty()); + } + + { + auto res = readDeps(trivial.string(), ctor::toolchain::gcc); + uASSERT_EQUAL(1u, res.size()); + uASSERT_EQUAL("x.cc"s, res[0]); + } + + { + auto res = readDeps(no_newline.string(), ctor::toolchain::gcc); + uASSERT_EQUAL(1u, res.size()); + uASSERT_EQUAL("x.cc"s, res[0]); + } + + { + auto res = readDeps(no_deps.string(), ctor::toolchain::gcc); + uASSERT_EQUAL(0u, res.size()); + } + + { + auto res = readDeps(spaces.string(), ctor::toolchain::gcc); + uASSERT_EQUAL(2u, res.size()); + uASSERT_EQUAL("x y.cc"s, res[0]); + uASSERT_EQUAL("x y.h"s, res[1]); + } + + { + auto res = readDeps(multiline.string(), ctor::toolchain::gcc); + uASSERT_EQUAL(12u, res.size()); + uASSERT_EQUAL("src/configure.cc"s, res[0]); + uASSERT_EQUAL("src/configure.h"s, res[1]); + uASSERT_EQUAL("src/getoptpp/getoptpp.hpp"s, res[2]); + uASSERT_EQUAL("src/execute.h"s, res[3]); + uASSERT_EQUAL("src/ctor.h"s, res[4]); + uASSERT_EQUAL("src/tasks.h"s, res[5]); + uASSERT_EQUAL("src/task.h"s, res[6]); + uASSERT_EQUAL("src/rebuild.h"s, res[7]); + uASSERT_EQUAL("src/externals.h"s, res[8]); + uASSERT_EQUAL("src/externals_manual.h"s, res[9]); + uASSERT_EQUAL("src/tools.h"s, res[10]); + uASSERT_EQUAL("src/util.h"s, res[11]); + } + + { + auto res = readDeps(no_such_file.string(), ctor::toolchain::gcc); + uASSERT(res.empty()); + } + + { + auto res = readDeps(missing_colon.string(), ctor::toolchain::gcc); + uASSERT(res.empty()); + } + } +}; + +// Registers the fixture into the 'registry' +static DepsTest test; diff --git a/test/deps_test_data/empty.d b/test/deps_test_data/empty.d new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/deps_test_data/empty.d diff --git a/test/deps_test_data/missing_colon.d b/test/deps_test_data/missing_colon.d new file mode 100644 index 0000000..e46996c --- /dev/null +++ b/test/deps_test_data/missing_colon.d @@ -0,0 +1 @@ +x.cc x.h diff --git a/test/deps_test_data/multiline.d b/test/deps_test_data/multiline.d new file mode 100644 index 0000000..8862ab0 --- /dev/null +++ b/test/deps_test_data/multiline.d @@ -0,0 +1,4 @@ +build/src/libctor_a-configure_cc.o: src/configure.cc src/configure.h \ + src/getoptpp/getoptpp.hpp src/execute.h src/ctor.h src/tasks.h \ + src/task.h src/rebuild.h src/externals.h src/externals_manual.h \ + src/tools.h src/util.h diff --git a/test/deps_test_data/no_deps.d b/test/deps_test_data/no_deps.d new file mode 100644 index 0000000..e7cccf6 --- /dev/null +++ b/test/deps_test_data/no_deps.d @@ -0,0 +1 @@ +x.o: diff --git a/test/deps_test_data/no_newline.d b/test/deps_test_data/no_newline.d new file mode 100644 index 0000000..88829ea --- /dev/null +++ b/test/deps_test_data/no_newline.d @@ -0,0 +1 @@ +x.o: x.cc
\ No newline at end of file diff --git a/test/deps_test_data/spaces.d b/test/deps_test_data/spaces.d new file mode 100644 index 0000000..c53fd64 --- /dev/null +++ b/test/deps_test_data/spaces.d @@ -0,0 +1 @@ +x\ y.o: x\ y.cc x\ y.h diff --git a/test/deps_test_data/trivial.d b/test/deps_test_data/trivial.d new file mode 100644 index 0000000..15a0c29 --- /dev/null +++ b/test/deps_test_data/trivial.d @@ -0,0 +1 @@ +x.o: x.cc |