Skip to content

Commit

Permalink
unittests: use subfolders for different tests
Browse files Browse the repository at this point in the history
Unittests for e.g. different libraries can be put into
`tests/unittests/tests-XXX`, where `XXX` is your test suite.

If `unittests` is made with `make all` (or any explicit argument), then
all test suites get built. If you use `make tests-XXX tests-YYY …` then
only the test suites `XXX` and `YYY` get built.
  • Loading branch information
Kijewski committed May 14, 2014
1 parent 61152df commit 297bc52
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 42 deletions.
17 changes: 16 additions & 1 deletion tests/unittests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ else ifeq ($(OUTPUT),COMPILER)
USEMODULE += embunit_textui
endif

.PHONY : all clean core
ifeq (, $(filter tests-%, $(MAKECMDGOALS)))
UNIT_TESTS := $(shell find -mindepth 1 -maxdepth 1 -type d -name 'tests-*' -printf '%f ')
else
UNIT_TESTS := $(filter tests-%, $(MAKECMDGOALS))
endif

include $(RIOTBASE)/Makefile.include

UNITTEST_LIBS := $(UNIT_TESTS:%=$(BINDIR)%.a)

all: $(UNITTEST_LIBS)
$(UNIT_TESTS): all

$(UNITTEST_LIBS): $(BINDIR)%.a:
"$(MAKE)" -C $(CURDIR)/$*

CFLAGS += $(shell echo $(UNIT_TESTS:tests-%=-DTEST_%_ENABLED) | tr a-z A-Z)
BASELIBS += $(UNITTEST_LIBS)
49 changes: 8 additions & 41 deletions tests/unittests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,26 @@
* details.
*/

#include "embUnit/embUnit.h"
#include "unittests.h"

#include "lpm.h"

#ifdef OUTPUT
#define OUTPUT_XML (1)
#define OUTPUT_TEXT (2)
#define OUTPUT_COMPILER (4)

#if (OUTPUT==OUTPUT_XML)
#include "textui/XMLOutputter.h"

#define OUTPUTTER (XMLOutputter_outputter())
#endif

#if (OUTPUT==OUTPUT_TEXT)
#include "textui/TextOutputter.h"

#define OUTPUTTER (TextOutputter_outputter())
#endif

#if (OUTPUT==OUTPUT_COMPILER)
#include "textui/CompilerOutputter.h"

#define OUTPUTTER (CompilerOutputter_outputter())
#endif

#include "textui/TextUIRunner.h"

#define TESTS_START() TextUIRunner_start()
#define TESTS_RUN(t) TextUIRunner_runTest(t)
#define TESTS_END() TextUIRunner_end()

#else

#define TESTS_START() TestRunner_start()
#define TESTS_RUN(t) TestRunner_runTest(t)
#define TESTS_END() TestRunner_end()

#endif


int main(void)
{
#ifdef OUTPUT
TextUIRunner_setOutputter(OUTPUTTER);
#endif

TESTS_START();
/* put test TEST_RUN() calls here */

/* put test TEST_RUN() calls here: */
/* #ifdef TEST_xxx_ENABLED
* tests_xxx();
* #endif
*/

TESTS_END();

lpm_set(LPM_POWERDOWN);

return 0;
}
52 changes: 52 additions & 0 deletions tests/unittests/unittests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2014 Martin Lenders
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/

/**
* @addtogroup unittests
* @{
*
* @file unittests.h
* @brief Common header file for unittests
*
* @author Freie Universität Berlin, Computer Systems & Telematics
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/

#ifndef __UNITTESTS__H
#define __UNITTESTS__H

#include "embUnit/embUnit.h"

#ifdef OUTPUT
# define OUTPUT_XML (1)
# define OUTPUT_TEXT (2)
# define OUTPUT_COMPILER (4)

# if (OUTPUT==OUTPUT_XML)
# include "textui/XMLOutputter.h"
# define OUTPUTTER (XMLOutputter_outputter())
# elif (OUTPUT==OUTPUT_TEXT)
# include "textui/TextOutputter.h"
# define OUTPUTTER (TextOutputter_outputter())
# elif (OUTPUT==OUTPUT_COMPILER)
# include "textui/CompilerOutputter.h"
# define OUTPUTTER (CompilerOutputter_outputter())
# endif

# include "textui/TextUIRunner.h"

# define TESTS_START() TextUIRunner_start()
# define TESTS_RUN(t) TextUIRunner_runTest(t)
# define TESTS_END() TextUIRunner_end()
#else
# define TESTS_START() TestRunner_start()
# define TESTS_RUN(t) TestRunner_runTest(t)
# define TESTS_END() TestRunner_end()
#endif

#endif

0 comments on commit 297bc52

Please sign in to comment.