From: Mike Lowis Date: Fri, 26 Aug 2016 18:16:59 +0000 (-0400) Subject: Restructured repo and combined .c file with header to ease integration with new projects X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=bea2ece61ed2f548ff11d59c061d14c442a18e80;p=projs%2Fatf.git Restructured repo and combined .c file with header to ease integration with new projects --- diff --git a/Makefile b/Makefile index a30c21e..619de45 100644 --- a/Makefile +++ b/Makefile @@ -1,100 +1,19 @@ -#------------------------------------------------------------------------------ -# Build Configuration -#------------------------------------------------------------------------------ -# Update these variables according to your requirements. - -# version VERSION = 0.0.1 - -# tools -CC = c99 -LD = ${CC} -AR = ar - -# flags -INCS = -Isource/ -Itests/ -CPPFLAGS = -D_XOPEN_SOURCE=700 -CFLAGS = ${INCS} ${CPPFLAGS} -LDFLAGS = ${LIBS} -ARFLAGS = rcs - -# commands -COMPILE = @echo CC $@; ${CC} ${CFLAGS} -c -o $@ $< -LINK = @echo LD $@; ${LD} -o $@ $^ ${LDFLAGS} -ARCHIVE = @echo AR $@; ${AR} ${ARFLAGS} $@ $^ -CLEAN = @rm -f - -#------------------------------------------------------------------------------ -# Build-Specific Macros -#------------------------------------------------------------------------------ -# Library macros -LIBNAME = atf -LIB = lib${LIBNAME}.a -DEPS = ${OBJS:.o=.d} -OBJS = source/atf.o - -# Test binary macros -TEST_BIN = test${LIBNAME} -TEST_DEPS = ${TEST_OBJS:.o=.d} -TEST_OBJS = tests/main.o tests/test_signals.o - -# Distribution dir and tarball settings -DISTDIR = ${LIBNAME}-${VERSION} +DISTDIR = atf-${VERSION} DISTTAR = ${DISTDIR}.tar DISTGZ = ${DISTTAR}.gz -DISTFILES = config.mk LICENSE.md Makefile README.md source tests - -# load user-specific settings --include config.mk - -#------------------------------------------------------------------------------ -# Phony Targets -#------------------------------------------------------------------------------ -.PHONY: all options tests +DISTFILES = atf.h LICENSE.md Makefile README.md tests.c -all: options ${LIB} tests - -options: - @echo "Toolchain Configuration:" - @echo " CC = ${CC}" - @echo " CFLAGS = ${CFLAGS}" - @echo " LD = ${LD}" - @echo " LDFLAGS = ${LDFLAGS}" - @echo " AR = ${AR}" - @echo " ARFLAGS = ${ARFLAGS}" - -tests: ${TEST_BIN} - -./${TEST_BIN} - @echo "Note: It is expected that exactly 2 of the tests will fail." - -dist: clean - @echo DIST ${DISTGZ} - @mkdir -p ${DISTDIR} - @cp -R ${DISTFILES} ${DISTDIR} - @tar -cf ${DISTTAR} ${DISTDIR} - @gzip ${DISTTAR} - @rm -rf ${DISTDIR} +tests: tests.c + $(CC) -I. -o $@ $^ + -./$@ clean: - ${CLEAN} ${LIB} ${TEST_BIN} ${OBJS} ${TEST_OBJS} - ${CLEAN} ${OBJS:.o=.gcno} ${OBJS:.o=.gcda} - ${CLEAN} ${TEST_OBJS:.o=.gcno} ${TEST_OBJS:.o=.gcda} - ${CLEAN} ${DEPS} ${TEST_DEPS} - ${CLEAN} ${DISTTAR} ${DISTGZ} - -#------------------------------------------------------------------------------ -# Target-Specific Rules -#------------------------------------------------------------------------------ -.c.o: - ${COMPILE} - -${LIB}: ${OBJS} - ${ARCHIVE} - -${TEST_BIN}: ${TEST_OBJS} ${LIB} - ${LINK} - -# load dependency files --include ${DEPS} --include ${TEST_DEPS} + $(RM) tests $(DISTGZ) +dist: clean + mkdir -p ${DISTDIR} + cp -R ${DISTFILES} ${DISTDIR} + tar -cf ${DISTTAR} ${DISTDIR} + gzip ${DISTTAR} + rm -rf ${DISTDIR} diff --git a/source/atf.c b/atf.h similarity index 68% rename from source/atf.c rename to atf.h index e1017e8..fccdd09 100755 --- a/source/atf.c +++ b/atf.h @@ -1,11 +1,48 @@ /** - @file atf.c - @brief See header for details + @file atf.h + @brief Aardvark Test Framework main interface file. $Revision$ $HeadURL$ */ -#include "atf.h" +#ifndef TEST_H +#define TEST_H + #include +#include + +extern char* Curr_Test; + +void atf_init(int argc, char** argv); + +void atf_test_start(char* file, unsigned int line, char* name); + +bool atf_test_assert(bool success, char* expr_str, char* file, int line); + +void atf_test_fail(char* expr, char* file, int line); + +int atf_print_results(void); + +#define CHECK(expr) \ + if(atf_test_assert((expr), #expr, __FILE__, __LINE__)) break + +#define TEST_SUITE(name) \ + void name(void) + +#define TEST(desc) \ + for(atf_test_start(__FILE__,__LINE__,#desc); Curr_Test != NULL; Curr_Test = NULL) + +#define RUN_TEST_SUITE(name) \ + name(); + +#define RUN_EXTERN_TEST_SUITE(name) \ + do { extern TEST_SUITE(name); RUN_TEST_SUITE(name); } while(0) + +#define PRINT_TEST_RESULTS \ + atf_print_results + +/* Function Definitions + *****************************************************************************/ +#ifdef INCLUDE_DEFS #include #include #ifndef NO_SIGNALS @@ -58,10 +95,6 @@ void atf_init(int argc, char** argv) { #endif } -void atf_run_suite(suite_t suite) { - suite(); -} - void atf_test_start(char* file, unsigned int line, char* name) { Curr_File = file; Curr_Line = line; @@ -92,3 +125,7 @@ int atf_print_results(void) { return Failed; } +#undef INCLUDE_DEFS +#endif + +#endif /* TEST_H */ diff --git a/source/atf.h b/source/atf.h deleted file mode 100755 index 0e2d2f1..0000000 --- a/source/atf.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - @file atf.h - @brief Aardvark Test Framework main interface file. - $Revision$ - $HeadURL$ -*/ -#ifndef TEST_H -#define TEST_H - -#include -#include - -typedef void (*suite_t)(void); - -extern char* Curr_Test; - -void atf_init(int argc, char** argv); - -void atf_run_suite(suite_t suite); - -void atf_test_start(char* file, unsigned int line, char* name); - -bool atf_test_assert(bool success, char* expr_str, char* file, int line); - -void atf_test_fail(char* expr, char* file, int line); - -int atf_print_results(void); - -#define CHECK(expr) \ - if(atf_test_assert((expr), #expr, __FILE__, __LINE__)) break - -#define TEST_SUITE(name) void name(void) - -#define TEST(desc) \ - for(atf_test_start(__FILE__,__LINE__,#desc); Curr_Test != NULL; Curr_Test = NULL) - -#define RUN_EXTERN_TEST_SUITE(name) \ - do { extern TEST_SUITE(name); atf_run_suite(&name); } while(0) - -#define RUN_TEST_SUITE(name) \ - atf_run_suite(&name) - -#define PRINT_TEST_RESULTS atf_print_results - -#endif /* TEST_H */ diff --git a/tests/main.c b/tests.c similarity index 69% rename from tests/main.c rename to tests.c index 3938272..807e8e0 100644 --- a/tests/main.c +++ b/tests.c @@ -1,4 +1,5 @@ -#include "atf.h" +#define INCLUDE_DEFS +#include TEST_SUITE(Local_Suite) { TEST(Passing_Test) { @@ -16,3 +17,9 @@ int main(int argc, char** argv) { RUN_EXTERN_TEST_SUITE(External_Suite); return atf_print_results(); } + +TEST_SUITE(External_Suite) { + TEST(Should_handle_SIGABRT) { + raise(SIGABRT); + } +} diff --git a/tests/test_signals.c b/tests/test_signals.c deleted file mode 100644 index 7b8cacf..0000000 --- a/tests/test_signals.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "atf.h" -#include - -TEST_SUITE(External_Suite) { - TEST(Should_handle_SIGABRT) { - raise(SIGABRT); - } -}