-(in-package #:cl-nl-test)
+(in-package #:clnl-test)
(defparameter *tests* nil)
final-result))
(defun run-all-tests ()
- (format t "~%Here we goooooooo~%")
+ (format t "~%~c[1;33mHere we goooooooo~c[0m~%" #\Esc #\Esc)
(run-tests (reverse *tests*)))
(defun run-tests-matching (match)
(list ,name ,test-fn ,debug-fn ,scala-prog ,scala-input)
*tests*)))
+(defun checksum= (expected got)
+ (if (stringp expected)
+ (string= got expected)
+ (find got expected :test #'string=)))
+
; To be used only with the simplest of tests, just a list of commands and a checksum of the
; world after they've been run.
(defmacro defsimplecommandtest (name commands checksum)
`(defsimpletest
- ,name
+ (format nil "Simple Command - ~A" ,name)
(lambda ()
- (cl-nl:boot)
- (cl-nl:run-commands ,commands)
- (string= ,checksum (checksum-world)))
+ (clnl:boot)
+ (clnl:run-commands ,commands)
+ (checksum= ,checksum (checksum-world)))
(lambda ()
- (cl-nl:boot)
- (cl-nl:run-commands ,commands)
+ (clnl:boot)
+ (clnl:run-commands ,commands)
(format nil "~A~A"
- (cl-nl.nvm:export-world)
+ (clnl-nvm:export-world)
(checksum-world)))
"bin/runcmd.scala"
(format nil "~A~%" ,commands)))
(defmacro defsimplereportertest (name reporter value checksum)
`(defsimpletest
- ,name
+ (format nil "Simple Reporter - ~A" ,name)
(lambda ()
- (cl-nl:boot)
+ (clnl:boot)
(and
- (string= (cl-nl.nvm:dump-object (cl-nl:run-reporter ,reporter)) ,value)
- (string= ,checksum (checksum-world))))
+ (string= (clnl-nvm:dump-object (clnl:run-reporter ,reporter)) ,value)
+ (checksum= ,checksum (checksum-world))))
(lambda ()
- (cl-nl:boot)
+ (clnl:boot)
(format nil "~A~%~A~A"
- (cl-nl.nvm:dump-object (cl-nl:run-reporter ,reporter))
- (cl-nl.nvm:export-world)
+ (clnl-nvm:dump-object (clnl:run-reporter ,reporter))
+ (clnl-nvm:export-world)
(checksum-world)))
"bin/runreporter.scala"
(format nil "~A~%" ,reporter)))
+(defmacro defviewtest (name commands checksum)
+ `(defsimpletest
+ (format nil "Simple View - ~A" ,name)
+ (lambda ()
+ (clnl:boot)
+ (clnl:run-commands ,commands)
+ (let
+ ((viewsum (checksum-view)))
+ (when (not (checksum= ,checksum viewsum))
+ (format t "~c[1;35m-- For ~A, got ~A but expected ~A~c[0m~%" #\Esc ,name viewsum ,checksum #\Esc))
+ (checksum= ,checksum (checksum-view))))
+ (lambda ()
+ (clnl:boot)
+ (clnl:run-commands ,commands)
+ (save-view-to-ppm)
+ (format nil "~A" (checksum-view)))
+ ""
+ (format nil "~A~%" ,commands)))
+
(defun checksum-world ()
(format nil "~{~2,'0X~}"
(map 'list #'identity
(ironclad:digest-sequence
:sha1
- (map '(vector (unsigned-byte 8)) #'char-code (cl-nl.nvm:export-world))))))
+ (map '(vector (unsigned-byte 8)) #'char-code (clnl-nvm:export-world))))))
+
+(defun checksum-view ()
+ (format nil "~{~2,'0X~}"
+ (map 'list #'identity
+ (ironclad:digest-sequence :sha1 (coerce (clnl-interface:export-view) '(vector (unsigned-byte 8)))))))
+
+(defun save-view-to-ppm ()
+ (let
+ ((height 143) (width 143)) ; hardcoded in interface, hardcoded here, cry for me
+ (with-open-file (str "cl.ppm" :direction :output :if-exists :supersede :if-does-not-exist :create :element-type '(unsigned-byte 8))
+ (write-sequence (map 'vector #'char-code (format nil "P6~%")) str)
+ (write-sequence (map 'vector #'char-code (format nil "143 143~%")) str)
+ (write-sequence (map 'vector #'char-code (format nil "255~%")) str)
+ (let
+ ((image-data (clnl-interface:export-view)))
+ (dotimes (i width)
+ (dotimes (j height)
+ (write-byte (aref image-data (+ 0 (* 4 (+ (* (- (1- height) i) width) j)))) str)
+ (write-byte (aref image-data (+ 1 (* 4 (+ (* (- (1- height) i) width) j)))) str)
+ (write-byte (aref image-data (+ 2 (* 4 (+ (* (- (1- height) i) width) j)))) str)))))))
(defun run ()
(loop for str = (progn (format t "> ") (force-output) (read-line))
while str
- do (progn (asdf:load-system :cl-nl-test) (run-tests-matching str))))
+ do (progn (asdf:load-system :clnl-test) (run-tests-matching str))))