From b3df50082ad427796f4f07dcf8e4512a1273c23e Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Sat, 19 Nov 2016 08:30:00 +0100 Subject: [PATCH] fix(tests): Run unit tests on travis --- .travis.yml | 16 +++++++-- tests/CMakeLists.txt | 1 + tests/unit_tests/components/command_line.cpp | 37 ++++++++++---------- tests/unit_tests/components/di.cpp | 15 ++++---- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4e36c6af..2ec96b88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -97,9 +97,21 @@ before_script: - cmake --version - mkdir -p "${TRAVIS_BUILD_DIR}/build" - cd "${TRAVIS_BUILD_DIR}/build" - - cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_CXX_FLAGS="${CXXFLAGS}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" .. + - cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_CXX_FLAGS="${CXXFLAGS}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" -DBUILD_TESTS:BOOL=ON .. -script: make +script: + - make + - | + for test in tests/unit_test.*; do + if [ -x $test ]; then + echo -n "${test##*/} "; + if $test; then + echo -e "\033[1;32mpassed\033[0m"; + else + echo -e "\033[1;31mfailed\033[0m"; + fi + fi + done notifications: irc: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d7ff0842..cac2a006 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories(${APP_INCLUDE_DIRS}) function(unit_test file) string(REPLACE "/" "_" testname ${file}) add_executable(unit_test.${testname} ${CMAKE_CURRENT_LIST_DIR}/unit_tests/${file}.cpp) + target_link_libraries(unit_test.${testname} ${APP_LIBRARIES}) add_test(unit_test.${testname} unit_test.${testname}) endfunction() diff --git a/tests/unit_tests/components/command_line.cpp b/tests/unit_tests/components/command_line.cpp index b2cb4303..9d031a0d 100644 --- a/tests/unit_tests/components/command_line.cpp +++ b/tests/unit_tests/components/command_line.cpp @@ -3,7 +3,6 @@ int main() { using namespace polybar; - using cli_parser = command_line::parser; // clang-format off const command_line::options opts{ @@ -13,60 +12,60 @@ int main() { // clang-format on "has_short"_test = [&opts] { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("-f", ' ')); expect(cli.has("flag")); expect(!cli.has("option")); - cli = configure_cli_parser("cmd", opts).create(); + cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("-f -o foo", ' ')); expect(cli.has("flag")); expect(cli.has("option")); - cli = configure_cli_parser("cmd", opts).create(); + cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("-o baz", ' ')); expect(!cli.has("flag")); expect(cli.has("option")); }; "has_long"_test = [&opts] { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("--flag", ' ')); expect(cli.has("flag")); expect(!cli.has("option")); - cli = configure_cli_parser("cmd", opts).create(); + cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("--flag --option=foo", ' ')); expect(cli.has("flag")); expect(cli.has("option")); - cli = configure_cli_parser("cmd", opts).create(); + cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("--option=foo --flag", ' ')); expect(cli.has("flag")); expect(cli.has("option")); - cli = configure_cli_parser("cmd", opts).create(); + cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("--option=baz", ' ')); expect(!cli.has("flag")); expect(cli.has("option")); }; "compare"_test = [&opts] { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("-o baz", ' ')); expect(cli.compare("option", "baz")); - cli = configure_cli_parser("cmd", opts).create(); + cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("--option=foo", ' ')); expect(cli.compare("option", "foo")); }; "get"_test = [&opts] { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("--option=baz", ' ')); expect("baz" == cli.get("option")); - cli = configure_cli_parser("cmd", opts).create(); + cli = configure_cliparser("cmd", opts).create(); cli.process_input(string_util::split("--option=foo", ' ')); expect("foo" == cli.get("option")); }; @@ -78,7 +77,7 @@ int main() { bool exception_thrown = false; try { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(input1); } catch (const command_line::value_error&) { exception_thrown = true; @@ -88,7 +87,7 @@ int main() { exception_thrown = false; // reset try { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(input2); } catch (const command_line::value_error&) { exception_thrown = true; @@ -98,7 +97,7 @@ int main() { exception_thrown = false; // reset try { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(input3); } catch (const command_line::value_error&) { exception_thrown = true; @@ -113,7 +112,7 @@ int main() { bool exception_thrown = false; try { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(input1); } catch (const command_line::value_error&) { exception_thrown = true; @@ -123,7 +122,7 @@ int main() { exception_thrown = false; // reset try { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(input2); } catch (const command_line::value_error&) { exception_thrown = true; @@ -138,7 +137,7 @@ int main() { bool exception_thrown = false; try { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(input1); } catch (const command_line::argument_error&) { exception_thrown = true; @@ -148,7 +147,7 @@ int main() { exception_thrown = false; // reset try { - auto cli = configure_cli_parser("cmd", opts).create(); + auto cli = configure_cliparser("cmd", opts).create(); cli.process_input(input2); } catch (const command_line::argument_error&) { exception_thrown = true; diff --git a/tests/unit_tests/components/di.cpp b/tests/unit_tests/components/di.cpp index 836b6cd5..8f85389f 100644 --- a/tests/unit_tests/components/di.cpp +++ b/tests/unit_tests/components/di.cpp @@ -3,6 +3,7 @@ #include "components/logger.hpp" #include "utils/inotify.hpp" +#include "utils/string.hpp" #define CONFIGURE_ARGS(T, V, Args) configure_##T(Args).create() #define CONFIGURE(T, V) configure_##T().create() @@ -18,9 +19,9 @@ int main() { boost::shared_ptr instance4{CONFIGURE(logger, instance4)}; // clang-format on - string mem_addr1{string_util::from_stream(std::stringstream() << &instance1)}; - string mem_addr2{string_util::from_stream(std::stringstream() << &instance2)}; - string mem_addr3{string_util::from_stream(std::stringstream() << instance3.get())}; + string mem_addr1{string_util::from_stream(stringstream() << &instance1)}; + string mem_addr2{string_util::from_stream(stringstream() << &instance2)}; + string mem_addr3{string_util::from_stream(stringstream() << instance3.get())}; expect(mem_addr1 == mem_addr2); expect(mem_addr2 == mem_addr3); @@ -28,10 +29,10 @@ int main() { }; "unique"_test = [] { - unique_ptr instance1{inotify_util::make_watch("A")}; - unique_ptr instance2{inotify_util::make_watch("B")}; - shared_ptr instance3{inotify_util::make_watch("B")}; - shared_ptr instance4{inotify_util::make_watch("B")}; + inotify_util::watch_t instance1{inotify_util::make_watch("A")}; + inotify_util::watch_t instance2{inotify_util::make_watch("B")}; + inotify_util::watch_t instance3{inotify_util::make_watch("B")}; + inotify_util::watch_t instance4{inotify_util::make_watch("B")}; expect(instance1.get() != instance2.get()); expect(instance2.get() != instance3.get());