1 (in-package #:cl-nl-test)
3 (defparameter *tests* nil)
5 (defun run-and-print-test (test)
7 ((green (format nil "~c[1;32m" #\Esc))
8 (red (format nil "~c[1;31m" #\Esc))
9 (result (funcall (cadr test))))
10 (format t "~A- ~S ~A~c[0m~%" (if result green red) (car test) (if result "passed" "failed") #\Esc)
13 (defun run-tests (tests)
16 (loop for test in tests
17 for result = (run-and-print-test test)
18 do (setf final-result (and final-result result)))
21 (defun run-all-tests ()
22 (format t "~%Here we goooooooo~%")
23 (run-tests (reverse *tests*)))
25 (defun run-tests-matching (match)
26 (run-tests (remove-if-not (lambda (test-name) (cl-ppcre:scan (format nil "^~A$" match) test-name)) *tests* :key #'car)))
28 (defun find-test (name)
30 (find name *tests* :test #'string= :key #'car)
31 (error "Couldn't find test with name: ~A" name)))
33 (defun test-debug (name) (format t "----~%~A~%" (funcall (third (find-test name)))))
34 (defun test-scala-prog (name) (format t "----~%~A~%" (fourth (find-test name))))
35 (defun test-scala-input (name) (format t "----~%~A~%" (fifth (find-test name))))
37 (defmacro defsimpletest (name test-fn debug-fn scala-prog scala-input)
39 ;(when (find-test ,name) (error "Test with name ~S already exists, abort, abort" ,name))
41 (list ,name ,test-fn ,debug-fn ,scala-prog ,scala-input)
44 ; To be used only with the simplest of tests, just a list of commands and a checksum of the
45 ; world after they've been run.
46 (defmacro defsimplecommandtest (name commands checksum)
51 (cl-nl:run-commands ,commands)
52 (string= ,checksum (checksum-world)))
55 (cl-nl:run-commands ,commands)
57 (cl-nl.nvm:export-world)
60 (format nil "~A~%" ,commands)))
62 (defmacro defsimplereportertest (name reporter value checksum)
68 (string= (cl-nl.nvm:dump-object (cl-nl:run-reporter ,reporter)) ,value)
69 (string= ,checksum (checksum-world))))
72 (format nil "~A~%~A~A"
73 (cl-nl.nvm:dump-object (cl-nl:run-reporter ,reporter))
74 (cl-nl.nvm:export-world)
76 "bin/runreporter.scala"
77 (format nil "~A~%" ,reporter)))
79 (defun checksum-world ()
80 (format nil "~{~2,'0X~}"
82 (ironclad:digest-sequence
84 (map '(vector (unsigned-byte 8)) #'char-code (cl-nl.nvm:export-world))))))
87 (loop for str = (progn (format t "> ") (force-output) (read-line))
89 do (progn (asdf:load-system :cl-nl-test) (run-tests-matching str))))