diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | test/navigator.c | 29 |
4 files changed, 48 insertions, 2 deletions
@@ -1,2 +1,3 @@ imv *.o +test_* @@ -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 @@ -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 <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#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); +} |