Add basic testing framework
authorDavid Vázquez <davazp@gmail.com>
Thu, 25 Apr 2013 20:37:30 +0000 (21:37 +0100)
committerDavid Vázquez <davazp@gmail.com>
Thu, 25 Apr 2013 20:37:30 +0000 (21:37 +0100)
jscl.lisp
tests.html [new file with mode: 0644]
tests/eval.lisp [new file with mode: 0644]
tests/tests-report.lisp [new file with mode: 0644]
tests/tests.lisp [new file with mode: 0644]

index 5f1aec2..f31de86 100644 (file)
--- a/jscl.lisp
+++ b/jscl.lisp
     ("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))
     (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 (file)
index 0000000..bd02338
--- /dev/null
@@ -0,0 +1,76 @@
+<!doctype html>
+<html>
+  <head>
+    <style>
+     /* The console container element */
+    body { background-color: black; font-size: 16px; font-family: Courier; overflow: hidden; padding: 0 0 0 0;}
+    #console {
+      position: absolute;
+      top: 0px;
+      bottom: 0px;
+      left: 0px;
+      right: 0px;
+      background-color:black;
+    }
+
+    .parents {
+        font-weight: bold;
+    }
+
+    /* The inner console element. */
+    .jqconsole {
+        padding: 10px;
+    }
+    /* The cursor. */
+    .jqconsole-cursor {
+        background-color: gray;
+    }
+    /* The cursor color when the console looses focus. */
+    .jqconsole-blurred .jqconsole-cursor {
+        background-color: #666;
+    }
+    /* The current prompt text color */
+    .jqconsole-prompt {
+        color: White;
+    }
+    /* The command history */
+    .jqconsole-old-prompt {
+        color: White;
+        font-weight: normal;
+    }
+    /* The text color when in input mode. */
+    .jqconsole-input {
+        color: White;
+    }
+    /* Previously entered input. */
+    .jqconsole-old-input {
+        color: White;
+        font-weight: normal;
+    }
+    /* The text color of the output. */
+    .jqconsole-output {
+        color: green;
+    }
+    .jqconsole-return, .jqconsole-header {
+        color: gray;
+    }
+    .jqconsole-error {
+        color: red;
+    }
+</style>
+  </head>
+  <body>
+    <div id="console"></div>
+    <script src="jquery.js" type="text/javascript" charset="utf-8"></script>
+    <script src="jqconsole.min.js" type="text/javascript" charset="utf-8"></script>
+    <script src="jscl.js" type="text/javascript"></script>
+    <script>
+      var jqconsole = $('#console').jqconsole();
+      lisp.write = function(str){
+           jqconsole.Write(str, 'jqconsole-output', false);
+           return str;
+      };
+    </script>
+    <script src="tests.js" type="text/javascript"></script>
+  </body>
+</html>
diff --git a/tests/eval.lisp b/tests/eval.lisp
new file mode 100644 (file)
index 0000000..9a0e50c
--- /dev/null
@@ -0,0 +1 @@
+(test (= (eval '(+ 1 2)) 3))
diff --git a/tests/tests-report.lisp b/tests/tests-report.lisp
new file mode 100644 (file)
index 0000000..974c4a8
--- /dev/null
@@ -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 (file)
index 0000000..aa94973
--- /dev/null
@@ -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 "")