From 7b2e15594adac9ac22f8c58e3e57c6014e4d6b06 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Tue, 3 Jul 2012 12:49:56 -0400 Subject: [PATCH] Added basic support for unit test runner. Unit test framework forthcoming --- Makefile | 22 ++++++++++++++++++++-- project.vim | 0 source/buf.scm | 21 +++++++++++++++++++++ source/main.scm | 3 ++- tests/main.scm | 6 ++++++ tests/test_foo.scm | 4 ++++ tools/unit.scm | 4 ++++ 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 project.vim create mode 100644 source/buf.scm create mode 100644 tests/test_foo.scm create mode 100644 tools/unit.scm diff --git a/Makefile b/Makefile index 67a60a4..eb284bd 100644 --- a/Makefile +++ b/Makefile @@ -21,20 +21,24 @@ TEST_RUNNER = test_runner #---------------------------- # Root Directories SRC_ROOT = source/ +TEST_ROOT = tests/ # File Extensions SRC_EXT = scm +TEST_EXT = scm # Source File Lists SRC_FILES = $(call flist, $(SRC_ROOT), $(SRC_EXT)) +TEST_FILES = $(call flist, $(TEST_ROOT), $(TEST_EXT)) # Object File Lists SRC_OBJS = $(SRC_FILES:%.$(SRC_EXT)=%.o) +TEST_OBJS = $(TEST_FILES:%.$(TEST_EXT)=%.o) # Compiler and Linker Options #---------------------------- CSC = csc -CSCFLAGS = -c +CSCFLAGS = -c -explicit-use # Build Rules #------------ @@ -42,22 +46,36 @@ CSCFLAGS = -c # List all rules not named for files/folders on disk .PHONY: all release -all: release +all: release test release: $(PROJ_NAME) +test: $(TEST_RUNNER) + @echo Running unit tests... + @./$(TEST_RUNNER) + # Binaries $(PROJ_NAME): $(SRC_OBJS) @echo Linking $@... @$(CSC) -o $@ $(SRC_OBJS) $(LIBS) +$(TEST_RUNNER): $(SRC_OBJS) $(TEST_OBJS) + @echo Linking $@... + @$(CSC) -o $@ $(TEST_OBJS) $(filter-out source/main.o,$(SRC_OBJS)) + # Object Files $(SRC_OBJS): %.o : %.$(SRC_EXT) @echo $< @$(CSC) $(CSCFLAGS) -o $@ $< +$(TEST_OBJS): %.o : %.$(TEST_EXT) + @echo $< + @$(CSC) $(CSCFLAGS) -o $@ $< + # Cleanup clean: + @$(RM) $(TEST_OBJS) @$(RM) $(SRC_OBJS) @$(RM) $(PROJ_NAME)* + @$(RM) $(TEST_RUNNER)* diff --git a/project.vim b/project.vim new file mode 100644 index 0000000..e69de29 diff --git a/source/buf.scm b/source/buf.scm new file mode 100644 index 0000000..4e62db4 --- /dev/null +++ b/source/buf.scm @@ -0,0 +1,21 @@ +(declare (unit buf)) + +(define-record buf + src + fn + pos + marks + data) + +(define (buf src fn) + (make-buf src fn 0 '() (vector))) + +(define buf-struct? buf?) + +(define (buf? obj) + (and (buf-struct? obj) + (procedure? (buf-fn obj)) + (integer? (buf-pos obj)) + (list? (buf-marks obj)) + (vector? (buf-data obj)))) + diff --git a/source/main.scm b/source/main.scm index 5de66e0..babf12d 100644 --- a/source/main.scm +++ b/source/main.scm @@ -1,3 +1,4 @@ +(declare (uses buf)) -(print "Hello, World!") +(print (buf (current-input-port) (lambda () '()))) diff --git a/tests/main.scm b/tests/main.scm index e69de29..db4f9d2 100644 --- a/tests/main.scm +++ b/tests/main.scm @@ -0,0 +1,6 @@ +(declare + (uses library) + (uses test_foo)) + +(print "Hello, world?") + diff --git a/tests/test_foo.scm b/tests/test_foo.scm new file mode 100644 index 0000000..84ae812 --- /dev/null +++ b/tests/test_foo.scm @@ -0,0 +1,4 @@ +(declare (unit test_foo)) + +(print "Hello, world!") + diff --git a/tools/unit.scm b/tools/unit.scm new file mode 100644 index 0000000..4bc6809 --- /dev/null +++ b/tools/unit.scm @@ -0,0 +1,4 @@ +(declare (unit unit)) + +(define tests-suites '()) + -- 2.52.0