]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Added basic support for unit test runner. Unit test framework forthcoming
authorMike D. Lowis <mike@mdlowis.com>
Tue, 3 Jul 2012 16:49:56 +0000 (12:49 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Tue, 3 Jul 2012 16:49:56 +0000 (12:49 -0400)
Makefile
project.vim [new file with mode: 0644]
source/buf.scm [new file with mode: 0644]
source/main.scm
tests/main.scm
tests/test_foo.scm [new file with mode: 0644]
tools/unit.scm [new file with mode: 0644]

index 67a60a44b1af62866793678cbd80205dfdfcb422..eb284bd81d7c913345c19d0518f727d39dbce8d8 100644 (file)
--- 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 (file)
index 0000000..e69de29
diff --git a/source/buf.scm b/source/buf.scm
new file mode 100644 (file)
index 0000000..4e62db4
--- /dev/null
@@ -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))))
+
index 5de66e086224f039169cd831f14dad96d7935398..babf12d9e93fa66e7e7dc4e4644f4390f6a011c3 100644 (file)
@@ -1,3 +1,4 @@
+(declare (uses buf))
 
-(print "Hello, World!")
+(print (buf (current-input-port) (lambda () '())))
 
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..db4f9d23f003c2a3f71244ed2a55c668559b0c29 100644 (file)
@@ -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 (file)
index 0000000..84ae812
--- /dev/null
@@ -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 (file)
index 0000000..4bc6809
--- /dev/null
@@ -0,0 +1,4 @@
+(declare (unit unit))
+
+(define tests-suites '())
+