From d441e950d8db03052aa1c79a49ec4d55dfd4215b Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Sat, 19 Nov 2016 12:26:00 +0200 Subject: [PATCH] Implement test target and add the first test make test will now compile the tests to test/test. The first test, testing string_replace_char from utils.c, was added. --- Makefile | 13 ++++++++++++- test/test.c | 12 ++++++++++++ test/utils.c | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/test.c create mode 100644 test/utils.c diff --git a/Makefile b/Makefile index 0e4f604..18c8e18 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ clean-dunstify: clean-doc: rm -f dunst.1 -clean: clean-dunst clean-dunstify clean-doc +clean: clean-dunst clean-dunstify clean-doc test-clean doc: dunst.1 dunst.1: README.pod @@ -89,4 +89,15 @@ uninstall: @echo Removing documentation directory ${DESTDIR}${PREFIX}/share/dunst rm -rf ${DESTDIR}${PREFIX}/share/dunst +test: test/test + +TEST_SRC = $(shell ls test/*.c) +TEST_OBJ = $(TEST_SRC:.c=.o) + +test/test: ${OBJ} ${TEST_OBJ} + ${CC} ${CFLAGS} -o $@ ${TEST_OBJ} ${OBJ} ${LDFLAGS} + +test-clean: + rm -f test/test test/*.o + .PHONY: all options clean dist install uninstall diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..5cfd346 --- /dev/null +++ b/test/test.c @@ -0,0 +1,12 @@ +#include "greatest.h" + +SUITE_EXTERN(utils); + +GREATEST_MAIN_DEFS(); + +int main(int argc, char *argv[]) { + GREATEST_MAIN_BEGIN(); + RUN_SUITE(utils); + GREATEST_MAIN_END(); +} +/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/test/utils.c b/test/utils.c new file mode 100644 index 0000000..dcfcb05 --- /dev/null +++ b/test/utils.c @@ -0,0 +1,19 @@ +#include "greatest.h" +#include "src/utils.h" + +TEST test_string_replace_char(void) +{ + char *text = calloc(128, sizeof(char)); + strcpy(text, "a aa aaa"); + ASSERT_STR_EQ(string_replace_char('a', 'b', text), "b bb bbb"); + strcpy(text, ""); + ASSERT_STR_EQ(string_replace_char('a', 'b', text), ""); + free(text); + PASS(); +} + +SUITE(utils) +{ + RUN_TEST(test_string_replace_char); +} +/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */