aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile13
-rw-r--r--README.md7
-rw-r--r--test/navigator.c29
4 files changed, 48 insertions, 2 deletions
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 <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);
+}