From 0b2e8cabbb6e1d291355c712eb9e60c53d27bfd7 Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Thu, 19 Mar 2015 13:40:29 -0500 Subject: [PATCH] Make an automake testsuite Add the existing tests and the examples. The testsuite is then run with "make check". --- examples/c++/Makefile.am | 13 +++++-------- examples/c/Makefile.am | 9 +++------ tests/Makefile.am | 4 +++- tests/tests.c | 8 +++++++- tinytest/tinytest.h | 2 ++ 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/examples/c++/Makefile.am b/examples/c++/Makefile.am index 5e0ae0d..8b62024 100644 --- a/examples/c++/Makefile.am +++ b/examples/c++/Makefile.am @@ -1,13 +1,10 @@ -noinst_PROGRAMS = example1 example2 example3 example4 +check_PROGRAMS = example1 example2 example3 example4 +AM_DEFAULT_SOURCE_EXT = .cpp -example1_SOURCES = example1.cpp - -example2_SOURCES = example2.cpp - -example3_SOURCES = example3.cpp - -example4_SOURCES = example4.cpp +noinst_PROGRAMS=$(check_PROGRAMS) +TESTS = $(check_PROGRAMS) +XFAIL_TESTS = example4 AM_CPPFLAGS = -I $(top_srcdir)/lib diff --git a/examples/c/Makefile.am b/examples/c/Makefile.am index abbcdae..783e255 100644 --- a/examples/c/Makefile.am +++ b/examples/c/Makefile.am @@ -1,11 +1,8 @@ -noinst_PROGRAMS = example1 example2 example3 +check_PROGRAMS = example1 example2 example3 +noinst_PROGRAMS=$(check_PROGRAMS) -example1_SOURCES = example1.c - -example2_SOURCES = example2.c - -example3_SOURCES = example3.c +TESTS = $(check_PROGRAMS) AM_CPPFLAGS = -I $(top_srcdir)/lib diff --git a/tests/Makefile.am b/tests/Makefile.am index cd64cc1..0b7fafc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,7 @@ -noinst_PROGRAMS = libconfig_tests +check_PROGRAMS = libconfig_tests +noinst_PROGRAMS=$(check_PROGRAMS) +TESTS = $(check_PROGRAMS) libconfig_tests_SOURCES = tests.c diff --git a/tests/tests.c b/tests/tests.c index e13e67f..a8cb5b8 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -209,12 +209,18 @@ TT_TEST(ParseInvalidStrings) int main(int argc, char **argv) { + int failures; + TT_SUITE_START(LibConfigTests); TT_SUITE_TEST(LibConfigTests, ParsingAndFormatting); TT_SUITE_TEST(LibConfigTests, ParseInvalidFiles); TT_SUITE_TEST(LibConfigTests, ParseInvalidStrings); TT_SUITE_RUN(LibConfigTests); + failures = TT_SUITE_NUM_FAILURES(LibConfigTests); TT_SUITE_END(LibConfigTests); - return(0); + if (failures) + return EXIT_FAILURE; + + return EXIT_SUCCESS; } diff --git a/tinytest/tinytest.h b/tinytest/tinytest.h index 562600e..10c63c2 100644 --- a/tinytest/tinytest.h +++ b/tinytest/tinytest.h @@ -532,5 +532,7 @@ extern void tt_test_ptr(const char *file, int line, const char *aexpr, #define TT_SUITE_RUN(S) \ tt_suite_run(__suite__ ## S) +#define TT_SUITE_NUM_FAILURES(S) \ + __suite__ ## S->num_failures #endif // __tinytest_h -- 2.7.4