Skip to content
22 changes: 18 additions & 4 deletions dist/pythonlibs/testrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,24 @@ def check_unittests(child, timeout=TIMEOUT, nb_tests=None):
to perform an exact match against that number.
"""
if nb_tests is None:
child.expect(r'OK \((\d+) tests\)', timeout=timeout)
return int(child.match.group(1))
_tests = int(nb_tests)
child.expect_exact('OK ({} tests)'.format(_tests), timeout=timeout)
# need escape sequence so don't use raw string
res = child.expect(['OK(\033\\[21m)? \\((\\d+) tests\\)',
r'<Tests>(\d+)</Tests>'], timeout=timeout)
if res == 0:
_tests = int(child.match.group(2))
else:
_tests = int(child.match.group(1))
else:
_tests = int(nb_tests)
# need escape sequence so don't use raw string
res = child.expect(['OK(\033\\[21m)? \\({} tests\\)'.format(_tests),
r'<Tests>{}</Tests>'.format(_tests)],
timeout=timeout)
if res == 1:
res = child.expect([r'<Failures>\d+</Failures>', '</Statistics>'],
timeout=timeout)
if res == 0:
raise AssertionError("Unittests failed")
return _tests


Expand Down
2 changes: 1 addition & 1 deletion sys/embunit/ColorOutputter.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ColorOutputter_printStatistics(OutputterRef self, TestResultRef result)
else {
printf("\n" BGGREEN SBOLD "OK" SDEFAULT " (%d tests)", result->runCount);
}
printf(LINEFILL BGDEFAULT "\n");
printf(LINEFILL BGDEFAULT "\n" ANSI_RESET);
}

static const OutputterImplement ColorOutputterImplement = {
Expand Down
1 change: 1 addition & 0 deletions sys/embunit/ColorTextColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern "C" {
#define SBOLD "\033[1m"
#define SDEFAULT "\033[21m"
#define LINEFILL "\033[K"
#define ANSI_RESET "\033[0m"

/**
* @}
Expand Down
2 changes: 1 addition & 1 deletion sys/include/embUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

# include "embUnit/TextUIRunner.h"

# define TESTS_START() TextUIRunner_start()
# define TESTS_START() TextUIRunner_startWithOutputter(OUTPUTTER)
# define TESTS_RUN(t) TextUIRunner_runTest(t)
# define TESTS_END() TextUIRunner_end()
#else
Expand Down
13 changes: 10 additions & 3 deletions tests/driver_ds1307/tests-with-config/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
# directory for more details.

import sys
from testrunner import run

import pexpect

from testrunner import run, run_check_unittests


def testfunc(child):
child.expect([r"OK \([0-9]+ tests\)",
r"error: unable to initialize RTC \[I2C initialization error\]"])
res = child.expect([
r"error: unable to initialize RTC \[I2C initialization error\]",
pexpect.TIMEOUT,
])
if res == 1:
run_check_unittests()


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion tests/gnrc_ipv6_ext_frag/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ include ../Makefile.tests_common

export TAP ?= tap0

CFLAGS += -DOUTPUT=TEXT
OUTPUT = TEXT

CFLAGS += -DTEST_SUITES="gnrc_ipv6_ext_frag"

ifeq (native,$(BOARD))
Expand Down
3 changes: 2 additions & 1 deletion tests/gnrc_lorawan/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# name of your application
include ../Makefile.tests_common

CFLAGS += -DOUTPUT=TEXT
# set embunit output to test
OUTPUT = TEXT

# Add unittest framework
USEMODULE += embunit
Expand Down
2 changes: 1 addition & 1 deletion tests/gnrc_rpl_srh/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include ../Makefile.tests_common

export TAP ?= tap0

CFLAGS += -DOUTPUT=TEXT
OUTPUT = TEXT

# use Ethernet as link-layer protocol
ifeq (native,$(BOARD))
Expand Down
8 changes: 2 additions & 6 deletions tests/gnrc_sixlowpan_frag_minfwd/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
# directory for more details.

import sys
from testrunner import run


def testfunc(child):
child.expect(r"OK \(\d+ tests\)")
from testrunner import run_check_unittests


if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())
8 changes: 2 additions & 6 deletions tests/gnrc_sixlowpan_frag_sfr/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
# directory for more details.

import sys
from testrunner import run


def testfunc(child):
child.expect(r"OK \(\d+ tests\)")
from testrunner import run_check_unittests


if __name__ == "__main__":
sys.exit(run(testfunc))
sys.exit(run_check_unittests())
8 changes: 2 additions & 6 deletions tests/pkg_libbase58/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
# directory for more details.

import sys
from testrunner import run


def testfunc(child):
child.expect(u"OK \\([0-9]+ tests\\)")
from testrunner import run_check_unittests


if __name__ == "__main__":
sys.exit(run(testfunc, timeout=120))
sys.exit(run_check_unittests(timeout=120))
4 changes: 2 additions & 2 deletions tests/suit_manifest/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import os
import sys
from testrunner import run
from testrunner import run, check_unittests


def testfunc(child):
Expand All @@ -17,7 +17,7 @@ def testfunc(child):
# 16 seconds on `samr21-xpro`
# >50 seconds on `nrf51dk`
timeout = 60 if board != 'native' else -1
child.expect(r"OK \(\d+ tests\)", timeout=timeout)
assert check_unittests(child, timeout=timeout) > 0


if __name__ == "__main__":
Expand Down
4 changes: 0 additions & 4 deletions tests/unittests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ int main(void)
xtimer_init();
#endif

#ifdef OUTPUT
TextUIRunner_setOutputter(OUTPUTTER);
#endif

TESTS_START();
#ifndef NO_TEST_SUITES
UNCURRY(RUN_TEST_SUITES, TEST_SUITES)
Expand Down