#include #include #include #include #include #include #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); assert_equal(1u, res.size(), __FILE__, __LINE__); assert_equal("x.cc"s, res[0], __FILE__, __LINE__); } { auto res = readDeps(no_newline.string(), ctor::toolchain::gcc); assert_equal(1u, res.size(), __FILE__, __LINE__); assert_equal("x.cc"s, res[0], __FILE__, __LINE__); } { auto res = readDeps(no_deps.string(), ctor::toolchain::gcc); assert_equal(0u, res.size(), __FILE__, __LINE__); } { auto res = readDeps(spaces.string(), ctor::toolchain::gcc); assert_equal(2u, res.size(), __FILE__, __LINE__); assert_equal("x y.cc"s, res[0], __FILE__, __LINE__); assert_equal("x y.h"s, res[1], __FILE__, __LINE__); } { auto res = readDeps(multiline.string(), ctor::toolchain::gcc); assert_equal(12u, res.size(), __FILE__, __LINE__); assert_equal("src/configure.cc"s, res[0], __FILE__, __LINE__); assert_equal("src/configure.h"s, res[1], __FILE__, __LINE__); assert_equal("src/getoptpp/getoptpp.hpp"s, res[2], __FILE__, __LINE__); assert_equal("src/execute.h"s, res[3], __FILE__, __LINE__); assert_equal("src/ctor.h"s, res[4], __FILE__, __LINE__); assert_equal("src/tasks.h"s, res[5], __FILE__, __LINE__); assert_equal("src/task.h"s, res[6], __FILE__, __LINE__); assert_equal("src/rebuild.h"s, res[7], __FILE__, __LINE__); assert_equal("src/externals.h"s, res[8], __FILE__, __LINE__); assert_equal("src/externals_manual.h"s, res[9], __FILE__, __LINE__); assert_equal("src/tools.h"s, res[10], __FILE__, __LINE__); assert_equal("src/util.h"s, res[11], __FILE__, __LINE__); } { 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;