From cc4e14d243f4e7e1ad487d8865c5ffc8423e473d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 28 Dec 2022 13:49:53 +0100 Subject: Add detected toolchain to configuration.cc --- test/tools_test.cc | 249 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 168 insertions(+), 81 deletions(-) (limited to 'test') diff --git a/test/tools_test.cc b/test/tools_test.cc index 5a0e994..4cc9a77 100644 --- a/test/tools_test.cc +++ b/test/tools_test.cc @@ -2,26 +2,33 @@ #include #include +#include + std::ostream& operator<<(std::ostream& stream, const std::vector& vs); +std::ostream& operator<<(std::ostream& stream, const ctor::toolchain& tool_chain); #include #include #include -#include - using namespace std::string_literals; -std::ostream& operator<<(std::ostream& stream, const ToolChain& tool_chain) +std::ostream& operator<<(std::ostream& stream, const ctor::toolchain& tool_chain) { switch(tool_chain) { - case ToolChain::gcc: - stream << "ToolChain::gcc"; + case ctor::toolchain::none: + stream << "ctor::toolchain::none"; + break; + case ctor::toolchain::any: + stream << "ctor::toolchain::any"; break; - case ToolChain::clang: - stream << "ToolChain::clang"; + case ctor::toolchain::gcc: + stream << "ctor::toolchain::gcc"; + break; + case ctor::toolchain::clang: + stream << "ctor::toolchain::clang"; break; } return stream; @@ -79,9 +86,7 @@ std::ostream& operator<<(std::ostream& stream, const std::pair return stream; } -// Controllable getConfiguration stub: -namespace -{ +namespace { std::string conf_host_cxx{}; std::string conf_build_cxx{}; } @@ -123,94 +128,176 @@ public: void getToolChain_test() { - // host - conf_host_cxx = "/usr/bin/g++"; - uASSERT_EQUAL(ToolChain::gcc, getToolChain(ctor::output_system::host)); + uASSERT_EQUAL(ctor::toolchain::gcc, getToolChain("/usr/bin/g++")); + uASSERT_EQUAL(ctor::toolchain::gcc, getToolChain("/usr/bin/g++-10")); + uASSERT_EQUAL(ctor::toolchain::gcc, getToolChain("/usr/bin/x86_64-pc-linux-gnu-g++-9.3.0")); + uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/bin/clang++")); + uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/bin/clang++-10")); + uASSERT_EQUAL(ctor::toolchain::clang, getToolChain("/usr/lib/llvm/12/bin/i686-pc-linux-gnu-clang++-12")); + } + + void getOption_toolchain_test() + { + std::vector exp; + std::vector act; - conf_host_cxx = "/usr/bin/g++-10"; - uASSERT_EQUAL(ToolChain::gcc, getToolChain(ctor::output_system::host)); + exp = { "-o", "foo" }; + act = getOption(ctor::toolchain::clang, opt::output, "foo"); + uASSERT_EQUAL(exp, act); - conf_host_cxx = "/usr/bin/x86_64-pc-linux-gnu-g++-9.3.0"; - uASSERT_EQUAL(ToolChain::gcc, getToolChain(ctor::output_system::host)); + exp = { "-g" }; + act = getOption(ctor::toolchain::clang, opt::debug); + uASSERT_EQUAL(exp, act); - conf_host_cxx = "/usr/bin/clang++"; - uASSERT_EQUAL(ToolChain::clang, getToolChain(ctor::output_system::host)); + exp = { "-s" }; + act = getOption(ctor::toolchain::clang, opt::strip); + uASSERT_EQUAL(exp, act); - conf_host_cxx = "/usr/bin/clang++-10"; - uASSERT_EQUAL(ToolChain::clang, getToolChain(ctor::output_system::host)); + exp = { "-Wall" }; + act = getOption(ctor::toolchain::clang, opt::warn_all); + uASSERT_EQUAL(exp, act); - conf_host_cxx = "/usr/lib/llvm/12/bin/i686-pc-linux-gnu-clang++-12"; - uASSERT_EQUAL(ToolChain::clang, getToolChain(ctor::output_system::host)); + exp = { "-Werror" }; + act = getOption(ctor::toolchain::clang, opt::warnings_as_errors); + uASSERT_EQUAL(exp, act); - // build - conf_build_cxx = "/usr/bin/g++"; - uASSERT_EQUAL(ToolChain::gcc, getToolChain(ctor::output_system::build)); + exp = { "-MMD" }; + act = getOption(ctor::toolchain::clang, opt::generate_dep_tree); + uASSERT_EQUAL(exp, act); - conf_build_cxx = "/usr/bin/g++-10"; - uASSERT_EQUAL(ToolChain::gcc, getToolChain(ctor::output_system::build)); + exp = { "-c" }; + act = getOption(ctor::toolchain::clang, opt::no_link); + uASSERT_EQUAL(exp, act); - conf_build_cxx = "/usr/bin/x86_64-pc-linux-gnu-g++-9.3.0"; - uASSERT_EQUAL(ToolChain::gcc, getToolChain(ctor::output_system::build)); + exp = { "-Ifoo" }; + act = getOption(ctor::toolchain::clang, opt::include_path, "foo"); + uASSERT_EQUAL(exp, act); - conf_build_cxx = "/usr/bin/clang++"; - uASSERT_EQUAL(ToolChain::clang, getToolChain(ctor::output_system::build)); + exp = { "-Lfoo" }; + act = getOption(ctor::toolchain::clang, opt::library_path, "foo"); + uASSERT_EQUAL(exp, act); - conf_build_cxx = "/usr/bin/clang++-10"; - uASSERT_EQUAL(ToolChain::clang, getToolChain(ctor::output_system::build)); + exp = { "-lfoo" }; + act = getOption(ctor::toolchain::clang, opt::link, "foo"); + uASSERT_EQUAL(exp, act); - conf_build_cxx = "/usr/lib/llvm/12/bin/i686-pc-linux-gnu-clang++-12"; - uASSERT_EQUAL(ToolChain::clang, getToolChain(ctor::output_system::build)); - } + exp = { "-std=foo" }; + act = getOption(ctor::toolchain::clang, opt::cpp_std, "foo"); + uASSERT_EQUAL(exp, act); - void getOption_toolchain_test() - { - using sv = std::vector; - - uUnit::assert_equal(sv{ "-o", "foo" }, getOption(ToolChain::clang, opt::output, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-g" }, getOption(ToolChain::clang, opt::debug), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-s" }, getOption(ToolChain::clang, opt::strip), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Wall" }, getOption(ToolChain::clang, opt::warn_all), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Werror" }, getOption(ToolChain::clang, opt::warnings_as_errors), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-MMD" }, getOption(ToolChain::clang, opt::generate_dep_tree), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-c" }, getOption(ToolChain::clang, opt::no_link), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Ifoo" }, getOption(ToolChain::clang, opt::include_path, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Lfoo" }, getOption(ToolChain::clang, opt::library_path, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-lfoo" }, getOption(ToolChain::clang, opt::link, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-std=foo" }, getOption(ToolChain::clang, opt::cpp_std, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-shared" }, getOption(ToolChain::clang, opt::build_shared), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-pthread" }, getOption(ToolChain::clang, opt::threads), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Ofoo" }, getOption(ToolChain::clang, opt::optimization, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-fPIC" }, getOption(ToolChain::clang, opt::position_independent_code), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-fPIE" }, getOption(ToolChain::clang, opt::position_independent_executable), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-foo" }, getOption(ToolChain::clang, opt::custom, "-foo"), __FILE__, __LINE__); - - uUnit::assert_equal(sv{ "-o", "foo" }, getOption(ToolChain::gcc, opt::output, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-g" }, getOption(ToolChain::gcc, opt::debug), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-s" }, getOption(ToolChain::gcc, opt::strip), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Wall" }, getOption(ToolChain::gcc, opt::warn_all), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Werror" }, getOption(ToolChain::gcc, opt::warnings_as_errors), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-MMD" }, getOption(ToolChain::gcc, opt::generate_dep_tree), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-c" }, getOption(ToolChain::gcc, opt::no_link), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Ifoo" }, getOption(ToolChain::gcc, opt::include_path, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Lfoo" }, getOption(ToolChain::gcc, opt::library_path, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-lfoo" }, getOption(ToolChain::gcc, opt::link, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-std=foo" }, getOption(ToolChain::gcc, opt::cpp_std, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-shared" }, getOption(ToolChain::gcc, opt::build_shared), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-pthread" }, getOption(ToolChain::gcc, opt::threads), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-Ofoo" }, getOption(ToolChain::gcc, opt::optimization, "foo"), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-fPIC" }, getOption(ToolChain::gcc, opt::position_independent_code), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-fPIE" }, getOption(ToolChain::gcc, opt::position_independent_executable), __FILE__, __LINE__); - uUnit::assert_equal(sv{ "-foo" }, getOption(ToolChain::gcc, opt::custom, "-foo"), __FILE__, __LINE__); + exp = { "-shared" }; + act = getOption(ctor::toolchain::clang, opt::build_shared); + uASSERT_EQUAL(exp, act); + + exp = { "-pthread" }; + act = getOption(ctor::toolchain::clang, opt::threads); + uASSERT_EQUAL(exp, act); + + exp = { "-Ofoo" }; + act = getOption(ctor::toolchain::clang, opt::optimization, "foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-fPIC" }; + act = getOption(ctor::toolchain::clang, opt::position_independent_code); + uASSERT_EQUAL(exp, act); + + exp = { "-fPIE" }; + act = getOption(ctor::toolchain::clang, opt::position_independent_executable); + uASSERT_EQUAL(exp, act); + + exp = { "-foo" }; + act = getOption(ctor::toolchain::clang, opt::custom, "-foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-o", "foo" }; + act = getOption(ctor::toolchain::gcc, opt::output, "foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-g" }; + act = getOption(ctor::toolchain::gcc, opt::debug); + uASSERT_EQUAL(exp, act); + + exp = { "-s" }; + act = getOption(ctor::toolchain::gcc, opt::strip); + uASSERT_EQUAL(exp, act); + + exp = { "-Wall" }; + act = getOption(ctor::toolchain::gcc, opt::warn_all); + uASSERT_EQUAL(exp, act); + + exp = { "-Werror" }; + act = getOption(ctor::toolchain::gcc, opt::warnings_as_errors); + uASSERT_EQUAL(exp, act); + + exp = { "-MMD" }; + act = getOption(ctor::toolchain::gcc, opt::generate_dep_tree); + uASSERT_EQUAL(exp, act); + + exp = { "-c" }; + act = getOption(ctor::toolchain::gcc, opt::no_link); + uASSERT_EQUAL(exp, act); + + exp = { "-Ifoo" }; + act = getOption(ctor::toolchain::gcc, opt::include_path, "foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-Lfoo" }; + act = getOption(ctor::toolchain::gcc, opt::library_path, "foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-lfoo" }; + act = getOption(ctor::toolchain::gcc, opt::link, "foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-std=foo" }; + act = getOption(ctor::toolchain::gcc, opt::cpp_std, "foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-shared" }; + act = getOption(ctor::toolchain::gcc, opt::build_shared); + uASSERT_EQUAL(exp, act); + + exp = { "-pthread" }; + act = getOption(ctor::toolchain::gcc, opt::threads); + uASSERT_EQUAL(exp, act); + + exp = { "-Ofoo" }; + act = getOption(ctor::toolchain::gcc, opt::optimization, "foo"); + uASSERT_EQUAL(exp, act); + + exp = { "-fPIC" }; + act = getOption(ctor::toolchain::gcc, opt::position_independent_code); + uASSERT_EQUAL(exp, act); + + exp = { "-fPIE" }; + act = getOption(ctor::toolchain::gcc, opt::position_independent_executable); + uASSERT_EQUAL(exp, act); + + exp = { "-foo" }; + act = getOption(ctor::toolchain::gcc, opt::custom, "-foo"); + uASSERT_EQUAL(exp, act); } void getOption_str_test() { - using p = std::pair; - uUnit::assert_equal(p{ opt::include_path, "foo" }, getOption("-Ifoo", ToolChain::gcc), __FILE__, __LINE__); - uUnit::assert_equal(p{ opt::library_path, "foo" }, getOption("-Lfoo", ToolChain::gcc), __FILE__, __LINE__); + std::pair exp; + std::pair act; + + exp = { opt::include_path, "foo" }; + act = getOption("-Ifoo", ctor::toolchain::gcc); + uASSERT_EQUAL(exp, act); + + exp = { opt::library_path, "foo" }; + act = getOption("-Lfoo", ctor::toolchain::gcc); + uASSERT_EQUAL(exp, act); + + exp = { opt::include_path, "foo" }; + act = getOption("-Ifoo", ctor::toolchain::clang); + uASSERT_EQUAL(exp, act); - uUnit::assert_equal(p{ opt::include_path, "foo" }, getOption("-Ifoo", ToolChain::clang), __FILE__, __LINE__); - uUnit::assert_equal(p{ opt::library_path, "foo" }, getOption("-Lfoo", ToolChain::clang), __FILE__, __LINE__); + exp = { opt::library_path, "foo" }; + act = getOption("-Lfoo", ctor::toolchain::clang); + uASSERT_EQUAL(exp, act); } -- cgit v1.2.3