From 1d669532c55e448eded7c085a29cca314daeeb95 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Thu, 25 Apr 2013 21:37:30 +0100 Subject: [PATCH] Add basic testing framework --- jscl.lisp | 16 ++++++++-- tests.html | 76 +++++++++++++++++++++++++++++++++++++++++++++++ tests/eval.lisp | 1 + tests/tests-report.lisp | 15 ++++++++++ tests/tests.lisp | 15 ++++++++++ 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 tests.html create mode 100644 tests/eval.lisp create mode 100644 tests/tests-report.lisp create mode 100644 tests/tests.lisp diff --git a/jscl.lisp b/jscl.lisp index 5f1aec2..f31de86 100644 --- a/jscl.lisp +++ b/jscl.lisp @@ -23,7 +23,11 @@ ("print" :target) ("read" :both) ("compiler" :both) - ("toplevel" :target))) + ("toplevel" :target) + ;; Tests + ("tests" :test) + ("eval" :test) + ("tests-report" :test))) (defun source-pathname (filename &key (directory '(:relative "src")) (type nil) (defaults filename)) @@ -73,4 +77,12 @@ (write-string (read-whole-file (source-pathname "prelude.js")) out) (dolist (input *source*) (when (member (cadr input) '(:target :both)) - (ls-compile-file (source-pathname (car input) :type "lisp") out))))) + (ls-compile-file (source-pathname (car input) :type "lisp") out)))) + ;; Tests + (with-open-file (out "tests.js" :direction :output :if-exists :supersede) + (dolist (input *source*) + (when (member (cadr input) '(:test)) + (ls-compile-file (source-pathname (car input) + :directory '(:relative "tests") + :type "lisp") + out))))) diff --git a/tests.html b/tests.html new file mode 100644 index 0000000..bd02338 --- /dev/null +++ b/tests.html @@ -0,0 +1,76 @@ + + + + + + +
+ + + + + + + diff --git a/tests/eval.lisp b/tests/eval.lisp new file mode 100644 index 0000000..9a0e50c --- /dev/null +++ b/tests/eval.lisp @@ -0,0 +1 @@ +(test (= (eval '(+ 1 2)) 3)) diff --git a/tests/tests-report.lisp b/tests/tests-report.lisp new file mode 100644 index 0000000..974c4a8 --- /dev/null +++ b/tests/tests-report.lisp @@ -0,0 +1,15 @@ +(write-line "") +(write-string "Finished. The execution took ") +(write-string (prin1-to-string (- (get-universal-time) *timestaup*))) +(write-line " seconds.") + +(cond + ((zerop *failed-tets*) + (write-string "All tests (") + (write-string (prin1-to-string *passed-tets*)) + (write-line ") passed successfully")) + (t + (write-string (prin1-to-string *failed-tets*)) + (write-string "/") + (write-string (prin1-to-string (+ *passed-tets* *failed-tets*))) + (write-line " failed."))) diff --git a/tests/tests.lisp b/tests/tests.lisp new file mode 100644 index 0000000..aa94973 --- /dev/null +++ b/tests/tests.lisp @@ -0,0 +1,15 @@ +(defvar *passed-tets* 0) +(defvar *failed-tets* 0) +(defvar *timestaup* (get-universal-time)) + +(defmacro test (condition) + `(cond + (,condition + (write-line ,(concat "Test `" (prin1-to-string condition) "' passed")) + (incf *passed-tets*)) + (t + (write-line ,(concat "Test `" (prin1-to-string condition) "' failed.")) + (incf *failed-tets*)))) + +(write-line "Running tests...") +(write-line "") -- 1.7.10.4