Add per-testcase timestamps with an option to disable them

This commit is contained in:
Richard Frith-Macdonald 2021-02-15 09:52:22 +00:00
parent 7ea6ab208d
commit e2df3f4a19
3 changed files with 43 additions and 9 deletions

View file

@ -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).

View file

@ -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 <alexander@malmberg.org>
Updated by: Richard Frith-Macdonald <rfm@gnu.org>
@ -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();

View file

@ -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