Prims - Implement any?
[clnl] / src / test / main.lisp
index 19c96670f9b5ed81ad790d68da5d83583e6c392e..2a0da536da513f559384131657280564f6066c97 100644 (file)
 (defun run-tests (tests)
  (let
   ((final-result t))
-  (loop for test in tests
-        for result = (run-and-print-test test)
-        do (setf final-result (and final-result result)))
+  (loop
+   :for test :in tests
+   :for result := (run-and-print-test test)
+   :do (setf final-result (and final-result result)))
   final-result))
 
 (defun run-all-tests ()
- (format t "~%~c[1;33mHere we goooooooo~c[0m~%" #\Esc #\Esc)
  (run-tests (reverse *tests*)))
-  
+
 (defun run-tests-matching (match)
- (run-tests (remove-if-not (lambda (test-name) (cl-ppcre:scan (format nil "^~A$" match) test-name)) *tests* :key #'car)))
+ (run-tests
+  (remove-if-not (lambda (test-name) (cl-ppcre:scan (format nil "^~A$" match) test-name)) *tests* :key #'car)))
 
 (defun find-test (name)
  (or
@@ -43,8 +44,8 @@
 
 (defun checksum= (expected got)
  (if (stringp expected)
-     (string= got expected)
-     (find got expected :test #'string=)))
+  (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.
  `(defsimpletest
    (format nil "Simple Command - ~A" ,name)
    (lambda ()
-    (clnl:boot)
+    (clnl:boot "resources/empty.nlogo")
     (clnl:run-commands ,commands)
     (checksum= ,checksum (checksum-world)))
    (lambda ()
-    (clnl:boot)
+    (clnl:boot "resources/empty.nlogo")
     (clnl:run-commands ,commands)
     (format nil "~A~A"
      (clnl-nvm:export-world)
  `(defsimpletest
    (format nil "Simple Reporter - ~A" ,name)
    (lambda ()
-    (clnl:boot)
+    (clnl:boot "resources/empty.nlogo")
+    (and
+     (string= (funcall (intern "DUMP-OBJECT" :clnl-nvm) (clnl:run-reporter ,reporter)) ,value)
+     (checksum= ,checksum (checksum-world))))
+   (lambda ()
+    (clnl:boot "resources/empty.nlogo")
+    (format nil "~A~%~A~A"
+     (funcall (intern "DUMP-OBJECT" :clnl-nvm) (clnl:run-reporter ,reporter))
+     (clnl-nvm:export-world)
+     (checksum-world)))
+   "bin/runcmd.scala"
+   (format nil "~%@#$#@#$#@~A~%" ,reporter)))
+
+(defmacro defreportertestwithsetup (name setup reporter value checksum)
+ `(defsimpletest
+   (format nil "Reporter With Setup - ~A" ,name)
+   (lambda ()
+    (clnl:boot "resources/empty.nlogo")
+    (clnl:run-commands ,setup)
     (and
-     (string= (clnl-nvm:dump-object (clnl:run-reporter ,reporter)) ,value)
+     (string= (funcall (intern "DUMP-OBJECT" :clnl-nvm) (clnl:run-reporter ,reporter)) ,value)
      (checksum= ,checksum (checksum-world))))
    (lambda ()
-    (clnl:boot)
+    (clnl:boot "resources/empty.nlogo")
+    (clnl:run-commands ,setup)
     (format nil "~A~%~A~A"
-     (clnl-nvm:dump-object (clnl:run-reporter ,reporter))
+     (funcall (intern "DUMP-OBJECT" :clnl-nvm) (clnl:run-reporter ,reporter))
      (clnl-nvm:export-world)
      (checksum-world)))
-   "bin/runreporter.scala"
-   (format nil "~A~%" ,reporter)))
+   "bin/runcmd.scala"
+   (format nil "~A~%@#$#@#$#@~A" ,setup ,reporter)))
 
 (defmacro defviewtest (name commands checksum)
  `(defsimpletest
    (format nil "Simple View - ~A" ,name)
    (lambda ()
-    (clnl:boot)
+    (clnl:boot "resources/empty.nlogo")
     (clnl:run-commands ,commands)
     (let
      ((viewsum (checksum-view)))
       (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:boot "resources/empty.nlogo")
     (clnl:run-commands ,commands)
     (save-view-to-ppm)
     (format nil "~A" (checksum-view)))
 (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))
+  (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)
       (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 :clnl-test) (run-tests-matching str))))
+ (loop
+  :for str := (progn (format t "> ") (force-output) (read-line))
+  :while str
+  :do (progn (asdf:load-system :clnl-test) (run-tests-matching str))))