From 286eac393cc00aa69c4bca9fa47f7d645013617a Mon Sep 17 00:00:00 2001
From: patrick96
Date: Fri, 11 Jan 2019 14:35:13 +0100
Subject: [PATCH] tests: Build and run all tests with make check
Simplifies the building and running of tests
Also exports the proper env variables so that the googletest output is
colored
ctest can use env variables for some of its options so we can for
example run
CTEST_PROGRESS_OUTPUT=1 make check
to run ctest with the --progress flag
This also makes the travis test.sh script obsolete
---
.travis.yml | 2 +-
common/travis/tests.sh | 16 ----------------
tests/CMakeLists.txt | 6 ++++++
3 files changed, 7 insertions(+), 17 deletions(-)
delete mode 100755 common/travis/tests.sh
diff --git a/.travis.yml b/.travis.yml
index ffaf579e..52d7b3eb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -46,7 +46,7 @@ matrix:
- compiler: gcc
env: BUILD_TYPE=Coverage POLYBAR_BUILD_TYPE=tests BUILD_TESTS=ON
addons: {apt: {packages: [*base_deps, *optional_deps]}}
- script: ${TRAVIS_BUILD_DIR}/common/travis/tests.sh
+ script: make check
after_success:
- cd ${TRAVIS_BUILD_DIR}
- bash <(curl -s https://codecov.io/bash) -F unittests -a "-ap" -Z || echo "Codecov did not collect coverage reports"
diff --git a/common/travis/tests.sh b/common/travis/tests.sh
deleted file mode 100755
index 2c0191c2..00000000
--- a/common/travis/tests.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-r=0
-
-make all_unit_tests || exit $?
-
-for test in tests/unit_test.*; do
- [ -x "$test" ] || continue
-
- if $test; then
- printf "\033[1;32m%s\033[0m\n" "${test##*/} passed"
- else
- r=1
- printf "\033[1;31m%s\033[0m\n" "${test##*/} failed"
- fi
-done
-exit $r
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b5916d8e..e787fa82 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -57,3 +57,9 @@ add_unit_test(components/command_line)
add_unit_test(components/bar)
add_unit_test(components/builder)
add_unit_test(components/parser)
+
+# Run make check to build and run all unit tests
+add_custom_target(check
+ COMMAND GTEST_COLOR=1 ctest --output-on-failure
+ DEPENDS all_unit_tests
+ )