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.
This commit is contained in:
parent
7ba0fe03ae
commit
d441e950d8
13
Makefile
13
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
|
||||
|
12
test/test.c
Normal file
12
test/test.c
Normal file
@ -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: */
|
19
test/utils.c
Normal file
19
test/utils.c
Normal file
@ -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: */
|
Loading…
x
Reference in New Issue
Block a user