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~%")
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) (find name *tests* :test #'string= :key #'car))
30 (defun diagnose-test (name)
31 (when (not (find-test name)) (error "Couldn't find test with name: ~A" name))
32 (format t "----~%~A~%" (funcall (caddr (find-test name)))))
34 (defun test-commands (name)
36 ((test (find-test name)))
37 (when (not test) (error "Couldn't find test with name: ~A" name))
39 (format t "~A~%" (funcall (fourth test)))))
41 ; To be used only with the simplest of tests, just a list of commands and a checksum of the
42 ; world after they've been run.
43 (defmacro defsimpletest (name commands checksum)
45 ;(when (find-test ,name) (error "Test with name ~S already exists, abort, abort" ,name))
51 (cl-nl:run-commands ,commands)
52 (string= ,checksum (checksum-world)))
55 (cl-nl:run-commands ,commands)
56 (cl-nl.nvm:export-world)
58 (lambda () ,commands))
61 (defun checksum-world ()
62 (format nil "~{~2,'0X~}"
64 (ironclad:digest-sequence
66 (map '(vector (unsigned-byte 8)) #'char-code (cl-nl.nvm:export-world))))))
69 (loop for str = (progn (format t "> ") (force-output) (read-line))
71 do (progn (asdf:load-system :cl-nl-test) (run-tests-matching str))))