From e2df3f4a19e723726acd85a62d4a2ebce57aff9d Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Mon, 15 Feb 2021 09:52:22 +0000 Subject: [PATCH] Add per-testcase timestamps with an option to disable them --- TestFramework/README | 4 ++++ TestFramework/Testing.h | 31 ++++++++++++++++++++++++++----- TestFramework/gnustep-tests.in | 17 +++++++++++++---- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/TestFramework/README b/TestFramework/README index 53d85673..eec7c7c1 100644 --- a/TestFramework/README +++ b/TestFramework/README @@ -135,6 +135,10 @@ option to have testing stopped at the first failure and the gdb debugger automatically launched to debug the failed testcase with a breakpoint set in the testStart() function for that testcase. +You can use the --notimestamps command line option to turn off timestamps of +individual testcases if you want a less verbose output (though test code may +override this default by setting the testTimestamps variable itself). + You can also use the --developer command line option to define the TESTDEV pre-processor variable (to turn on developer only test cases, and to have all 'hopes' treated as actual 'tests' with pass/fail results). diff --git a/TestFramework/Testing.h b/TestFramework/Testing.h index 9202d7ce..bfa2727c 100644 --- a/TestFramework/Testing.h +++ b/TestFramework/Testing.h @@ -1,6 +1,6 @@ /* Testing - Include basic tests macros for the GNUstep Testsuite - Copyright (C) 2005-2011 Free Software Foundation, Inc. + Copyright (C) 2005-2021 Free Software Foundation, Inc. Written by: Alexander Malmberg Updated by: Richard Frith-Macdonald @@ -57,6 +57,15 @@ static BOOL testPassed __attribute__((unused)) = NO; */ static unsigned testLineNumber __attribute__((unused)) = 0; +/* A flag indicating whether timestamps should be produced in the output + * for each testcase. By default it is set to TEST_TS if defined, but + * test code may override that default. + */ +#if !defined(TEST_TS) +#define TEST_TS 0 +#endif +static BOOL testTimestamps __attribute__((unused)) = TEST_TS; + /* A variable storing the indentation of the set currently being run. * Do not modify this directly. */ @@ -104,7 +113,11 @@ static void (*setEnded)(const char *name, BOOL completed, double duration) * The global variable 'testHopeful' can be set to a non-zero value before * calling this function in order to specify that if the condition is * not true it should be treated as a dashed hope rather than a failure - * (unless the tests are bing performed in 'developer' mode). + * (unless the tests are being performed in 'developer' mode). + * + * The global variable 'testTimestamps' can be set to a non-zero value before + * calling this function in order to specify that the output logged is to + * include the timestamp of the testcase completion (entry into this function). * * If there is a better higher-level test macro available, please use * that instead. In particular, please use the PASS_EQUAL() macro wherever @@ -124,22 +137,30 @@ static void pass(int passed, const char *format, ...) { va_list args; va_start(args, format); + const char *ts = ""; + if (testTimestamps) + { + NSCalendarDate *d = [NSCalendarDate date]; + + [d setCalendarFormat: @"(%Y-%m-%d %H:%M:%S.%F %z) "]; + ts = [[d description] cString]; + } if (passed) { - fprintf(stderr, "Passed test: "); + fprintf(stderr, "Passed test: %s", ts); testPassed = YES; } #if !defined(TESTDEV) else if (YES == testHopeful) { - fprintf(stderr, "Dashed hope: "); + fprintf(stderr, "Dashed hope: %s", ts); testPassed = NO; } #endif else { - fprintf(stderr, "Failed test: "); + fprintf(stderr, "Failed test: %s", ts); testPassed = NO; } testIndent(); diff --git a/TestFramework/gnustep-tests.in b/TestFramework/gnustep-tests.in index 486b0dde..eabd41aa 100755 --- a/TestFramework/gnustep-tests.in +++ b/TestFramework/gnustep-tests.in @@ -77,6 +77,9 @@ do --sequential) GSSEQUENTIAL=yes ;; + --notimestamps) + GSTEST_TS=0 + ;; --verbose) GSVERBOSE=yes ;; @@ -96,6 +99,7 @@ do echo "Use 'gnustep-tests --developer' to treat hopes as real tests." echo "Use 'gnustep-tests --verbose' for full/detailed log output." echo "Use 'gnustep-tests --sequential' to disable parallel building." + echo "Use 'gnustep-tests --notimestamps' to disable testcase timestamps." echo echo "Interpreting the output" echo "-----------------------" @@ -154,18 +158,23 @@ else OBJCXX= fi -GSTESTFLAGS= +if test x"$GSTEST_TS" = x"no" +then + GSTESTFLAGS="-DTEST_TS=0" +else + GSTESTFLAGS="-DTEST_TS=1" +fi if test "$GSTESTMODE" = "failfast" then if test x"$GSTESTDEV" = x"yes" then - GSTESTFLAGS="-DTESTDEV=1 -DFAILFAST=1" + GSTESTFLAGS="$GSTESTFLAGS -DTESTDEV=1 -DFAILFAST=1" else - GSTESTFLAGS="-DFAILFAST=1" + GSTESTFLAGS="$GSTESTFLAGS -DFAILFAST=1" fi elif test x"$GSTESTDEV" = x"yes" then - GSTESTFLAGS="-DTESTDEV=1" + GSTESTFLAGS="$GSTESTFLAGS -DTESTDEV=1" fi if test x"$GSTESTFLAGS" != x