From c8f4c755c3df8f8a9a304a55036baa9ea20cf943 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Tue, 8 Dec 2015 16:36:26 +0000 Subject: Add testing infrastructure --- .gitignore | 1 + Makefile | 13 +++++++++++-- README.md | 7 +++++++ test/navigator.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 test/navigator.c diff --git a/.gitignore b/.gitignore index 6809670..8b497f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ imv *.o +test_* diff --git a/Makefile b/Makefile index 8088f8e..d589faa 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean install uninstall +.PHONY: clean check install uninstall prefix = /usr @@ -10,6 +10,7 @@ BUILDDIR = build SOURCES = $(wildcard src/*.c) OBJECTS = $(patsubst src/%.c,$(BUILDDIR)/%.o,$(SOURCES)) +TESTS = $(patsubst test/%.c,test_%,$(wildcard test/*.c)) VERSION = "v1.1.0" @@ -27,8 +28,16 @@ $(BUILDDIR)/%.o: src/%.c @echo "COMPILING $@" @$(CC) -c $(CFLAGS) -o $@ $< +test_%: test/%.c src/%.c + @echo "BUILDING $@" + @$(CC) -o $@ -Isrc -W -Wall -std=gnu11 -lcmocka $^ + +check: $(TESTS) + @echo "RUNNING TESTS" + @for t in "$(TESTS)"; do ./$$t; done + clean: - @$(RM) $(TARGET) $(OBJECTS) + @$(RM) $(TARGET) $(OBJECTS) $(TESTS) install: $(TARGET) install -D -m 0755 $(TARGET) $(DESTDIR)$(prefix)/bin/imv diff --git a/README.md b/README.md index 1598ca6..b6199a8 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,13 @@ Installation $ make # make install +Tests +----- + +`imv` has a work-in-progress test suite. The test suite requires `cmocka`. + + $ make check + Contact ------- diff --git a/test/navigator.c b/test/navigator.c new file mode 100644 index 0000000..66f3a43 --- /dev/null +++ b/test/navigator.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +#include "navigator.h" + +static void test_navigator_add(void **state) +{ + (void)state; + struct imv_navigator nav; + imv_navigator_init(&nav); + + assert_false(imv_navigator_poll_changed(&nav)); + imv_navigator_add(&nav, "path/to/some/file", 0); + assert_true(imv_navigator_poll_changed(&nav)); + assert_string_equal(imv_navigator_selection(&nav), "path/to/some/file"); + + imv_navigator_destroy(&nav); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_navigator_add), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} -- cgit v1.2.3