Skip to content
Snippets Groups Projects
Commit 77e504f9 authored by sds's avatar sds
Browse files

untabify

parent f09da70a
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
(defvar *notes* (make-hash-table :test 'equal) (defvar *notes* (make-hash-table :test 'equal)
"A mapping from names of notes to note objects.") "A mapping from names of notes to note objects.")
(defstruct (entry (:conc-name nil)) (defstruct (entry (:conc-name nil))
pend name props form vals) pend name props form vals)
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
;;; of the requirements. ;;; of the requirements.
(defstruct note (defstruct note
name name
contents contents
disabled ;; When true, tests with this note are considered inactive disabled ;; When true, tests with this note are considered inactive
) )
...@@ -79,17 +79,17 @@ ...@@ -79,17 +79,17 @@
(defun entry-notes (entry) (defun entry-notes (entry)
(let* ((props (props entry)) (let* ((props (props entry))
(notes (getf props :notes))) (notes (getf props :notes)))
(if (listp notes) (if (listp notes)
notes notes
(list notes)))) (list notes))))
(defun has-disabled-note (entry) (defun has-disabled-note (entry)
(let ((notes (entry-notes entry))) (let ((notes (entry-notes entry)))
(loop for n in notes (loop for n in notes
for note = (if (note-p n) n for note = (if (note-p n) n
(gethash n *notes*)) (gethash n *notes*))
thereis (and note (note-disabled note))))) thereis (and note (note-disabled note)))))
(defun has-note (entry note) (defun has-note (entry note)
(unless (note-p note) (unless (note-p note)
...@@ -99,8 +99,8 @@ ...@@ -99,8 +99,8 @@
(defun pending-tests () (defun pending-tests ()
(loop for entry in (cdr *entries*) (loop for entry in (cdr *entries*)
when (and (pend entry) (not (has-disabled-note entry))) when (and (pend entry) (not (has-disabled-note entry)))
collect (name entry))) collect (name entry)))
(defun rem-all-tests () (defun rem-all-tests ()
(setq *entries* (list nil)) (setq *entries* (list nil))
...@@ -112,8 +112,8 @@ ...@@ -112,8 +112,8 @@
(let ((pred (gethash name *entries-table*))) (let ((pred (gethash name *entries-table*)))
(when pred (when pred
(if (null (cddr pred)) (if (null (cddr pred))
(setq *entries-tail* pred) (setq *entries-tail* pred)
(setf (gethash (name (caddr pred)) *entries-table*) pred)) (setf (gethash (name (caddr pred)) *entries-table*) pred))
(setf (cdr pred) (cddr pred)) (setf (cdr pred) (cddr pred))
(remhash name *entries-table*) (remhash name *entries-table*)
name))) name)))
...@@ -123,30 +123,30 @@ ...@@ -123,30 +123,30 @@
(defun get-entry (name) (defun get-entry (name)
(let ((entry ;; (find name (the list (cdr *entries*)) (let ((entry ;; (find name (the list (cdr *entries*))
;; :key #'name :test #'equal) ;; :key #'name :test #'equal)
(cadr (gethash name *entries-table*)) (cadr (gethash name *entries-table*))
)) ))
(when (null entry) (when (null entry)
(report-error t (report-error t
"~%No test with name ~:@(~S~)." "~%No test with name ~:@(~S~)."
name)) name))
entry)) entry))
(defmacro deftest (name &rest body) (defmacro deftest (name &rest body)
(let* ((p body) (let* ((p body)
(properties (properties
(loop while (keywordp (first p)) (loop while (keywordp (first p))
unless (cadr p) unless (cadr p)
do (error "Poorly formed deftest: ~A~%" do (error "Poorly formed deftest: ~A~%"
(list* 'deftest name body)) (list* 'deftest name body))
append (list (pop p) (pop p)))) append (list (pop p) (pop p))))
(form (pop p)) (form (pop p))
(vals p)) (vals p))
`(add-entry (make-entry :pend t `(add-entry (make-entry :pend t
:name ',name :name ',name
:props ',properties :props ',properties
:form ',form :form ',form
:vals ',vals)))) :vals ',vals))))
(defun add-entry (entry) (defun add-entry (entry)
(setq entry (copy-entry entry)) (setq entry (copy-entry entry))
...@@ -167,19 +167,19 @@ ...@@ -167,19 +167,19 @@
(setq *test* (name entry))) (setq *test* (name entry)))
(defun report-error (error? &rest args) (defun report-error (error? &rest args)
(cond (*debug* (cond (*debug*
(apply #'format t args) (apply #'format t args)
(if error? (throw '*debug* nil))) (if error? (throw '*debug* nil)))
(error? (apply #'error args)) (error? (apply #'error args))
(t (apply #'warn args))) (t (apply #'warn args)))
nil) nil)
(defun do-test (&optional (name *test*) &rest key-args) (defun do-test (&optional (name *test*) &rest key-args)
(flet ((%parse-key-args (flet ((%parse-key-args
(&key (&key
((:catch-errors *catch-errors*) *catch-errors*) ((:catch-errors *catch-errors*) *catch-errors*)
((:compile *compile-tests*) *compile-tests*)) ((:compile *compile-tests*) *compile-tests*))
(do-entry (get-entry name)))) (do-entry (get-entry name))))
(apply #'%parse-key-args key-args))) (apply #'%parse-key-args key-args)))
(defun my-aref (a &rest args) (defun my-aref (a &rest args)
...@@ -195,104 +195,104 @@ ...@@ -195,104 +195,104 @@
((eq x y) t) ((eq x y) t)
((consp x) ((consp x)
(and (consp y) (and (consp y)
(equalp-with-case (car x) (car y)) (equalp-with-case (car x) (car y))
(equalp-with-case (cdr x) (cdr y)))) (equalp-with-case (cdr x) (cdr y))))
((and (typep x 'array) ((and (typep x 'array)
(= (array-rank x) 0)) (= (array-rank x) 0))
(equalp-with-case (my-aref x) (my-aref y))) (equalp-with-case (my-aref x) (my-aref y)))
((typep x 'vector) ((typep x 'vector)
(and (typep y 'vector) (and (typep y 'vector)
(let ((x-len (length x)) (let ((x-len (length x))
(y-len (length y))) (y-len (length y)))
(and (eql x-len y-len) (and (eql x-len y-len)
(loop (loop
for i from 0 below x-len for i from 0 below x-len
for e1 = (my-aref x i) for e1 = (my-aref x i)
for e2 = (my-aref y i) for e2 = (my-aref y i)
always (equalp-with-case e1 e2)))))) always (equalp-with-case e1 e2))))))
((and (typep x 'array) ((and (typep x 'array)
(typep y 'array) (typep y 'array)
(not (equal (array-dimensions x) (not (equal (array-dimensions x)
(array-dimensions y)))) (array-dimensions y))))
nil) nil)
((typep x 'array) ((typep x 'array)
(and (typep y 'array) (and (typep y 'array)
(let ((size (array-total-size x))) (let ((size (array-total-size x)))
(loop for i from 0 below size (loop for i from 0 below size
always (equalp-with-case (my-row-major-aref x i) always (equalp-with-case (my-row-major-aref x i)
(my-row-major-aref y i)))))) (my-row-major-aref y i))))))
((typep x 'pathname) ((typep x 'pathname)
(equal x y)) (equal x y))
(t (eql x y)))) (t (eql x y))))
(defun do-entry (entry &optional (defun do-entry (entry &optional
(s *standard-output*)) (s *standard-output*))
(catch '*in-test* (catch '*in-test*
(setq *test* (name entry)) (setq *test* (name entry))
(setf (pend entry) t) (setf (pend entry) t)
(let* ((*in-test* t) (let* ((*in-test* t)
;; (*break-on-warnings* t) ;; (*break-on-warnings* t)
(aborted nil) (aborted nil)
r) r)
;; (declare (special *break-on-warnings*)) ;; (declare (special *break-on-warnings*))
(block aborted (block aborted
(setf r (setf r
(flet ((%do () (flet ((%do ()
(handler-bind (handler-bind
#-sbcl nil #-sbcl nil
#+sbcl ((sb-ext:code-deletion-note #'(lambda (c) #+sbcl ((sb-ext:code-deletion-note #'(lambda (c)
(if (has-note entry :do-not-muffle) (if (has-note entry :do-not-muffle)
nil nil
(muffle-warning c))))) (muffle-warning c)))))
(cond (cond
(*compile-tests* (*compile-tests*
(multiple-value-list (multiple-value-list
(funcall (compile (funcall (compile
nil nil
`(lambda () `(lambda ()
(declare (declare
(optimize ,@*optimization-settings*)) (optimize ,@*optimization-settings*))
,(form entry)))))) ,(form entry))))))
(*expanded-eval* (*expanded-eval*
(multiple-value-list (multiple-value-list
(expanded-eval (form entry)))) (expanded-eval (form entry))))
(t (t
(multiple-value-list (multiple-value-list
(eval (form entry)))))))) (eval (form entry))))))))
(if *catch-errors* (if *catch-errors*
(handler-bind (handler-bind
(#-ecl (style-warning #'(lambda (c) (if (has-note entry :do-not-muffle-warnings) (#-ecl (style-warning #'(lambda (c) (if (has-note entry :do-not-muffle-warnings)
c c
(muffle-warning c)))) (muffle-warning c))))
(error #'(lambda (c) (error #'(lambda (c)
(setf aborted t) (setf aborted t)
(setf r (list c)) (setf r (list c))
(return-from aborted nil)))) (return-from aborted nil))))
(%do)) (%do))
(%do))))) (%do)))))
(setf (pend entry) (setf (pend entry)
(or aborted (or aborted
(not (equalp-with-case r (vals entry))))) (not (equalp-with-case r (vals entry)))))
(when (pend entry) (when (pend entry)
(let ((*print-circle* *print-circle-on-failure*)) (let ((*print-circle* *print-circle-on-failure*))
(format s "~&Test ~:@(~S~) failed~ (format s "~&Test ~:@(~S~) failed~
~%Form: ~S~ ~%Form: ~S~
~%Expected value~P: ~ ~%Expected value~P: ~
~{~S~^~%~17t~}~%" ~{~S~^~%~17t~}~%"
*test* (form entry) *test* (form entry)
(length (vals entry)) (length (vals entry))
(vals entry)) (vals entry))
(handler-case (handler-case
(let ((st (format nil "Actual value~P: ~ (let ((st (format nil "Actual value~P: ~
~{~S~^~%~15t~}.~%" ~{~S~^~%~15t~}.~%"
(length r) r))) (length r) r)))
(format s "~A" st)) (format s "~A" st))
(error () (format s "Actual value: #<error during printing>~%"))) (error () (format s "Actual value: #<error during printing>~%")))
(finish-output s))))) (finish-output s)))))
(when (not (pend entry)) *test*)) (when (not (pend entry)) *test*))
(defun expanded-eval (form) (defun expanded-eval (form)
...@@ -304,31 +304,31 @@ ...@@ -304,31 +304,31 @@
(cond (cond
((eq op 'let) ((eq op 'let)
(let* ((bindings (loop for b in (cadr form) (let* ((bindings (loop for b in (cadr form)
collect (if (consp b) b (list b nil)))) collect (if (consp b) b (list b nil))))
(vars (mapcar #'car bindings)) (vars (mapcar #'car bindings))
(binding-forms (mapcar #'cadr bindings))) (binding-forms (mapcar #'cadr bindings)))
(apply (apply
(the function (the function
(eval `(lambda ,vars ,@(cddr form)))) (eval `(lambda ,vars ,@(cddr form))))
(mapcar #'eval binding-forms)))) (mapcar #'eval binding-forms))))
((and (eq op 'let*) (cadr form)) ((and (eq op 'let*) (cadr form))
(let* ((bindings (loop for b in (cadr form) (let* ((bindings (loop for b in (cadr form)
collect (if (consp b) b (list b nil)))) collect (if (consp b) b (list b nil))))
(vars (mapcar #'car bindings)) (vars (mapcar #'car bindings))
(binding-forms (mapcar #'cadr bindings))) (binding-forms (mapcar #'cadr bindings)))
(funcall (funcall
(the function (the function
(eval `(lambda (,(car vars) &aux ,@(cdr bindings)) ,@(cddr form)))) (eval `(lambda (,(car vars) &aux ,@(cdr bindings)) ,@(cddr form))))
(eval (car binding-forms))))) (eval (car binding-forms)))))
((eq op 'progn) ((eq op 'progn)
(loop for e on (cdr form) (loop for e on (cdr form)
do (if (null (cdr e)) (return (eval (car e))) do (if (null (cdr e)) (return (eval (car e)))
(eval (car e))))) (eval (car e)))))
((and (symbolp op) (fboundp op) ((and (symbolp op) (fboundp op)
(not (macro-function op)) (not (macro-function op))
(not (special-operator-p op))) (not (special-operator-p op)))
(apply (symbol-function op) (apply (symbol-function op)
(mapcar #'eval (cdr form)))) (mapcar #'eval (cdr form))))
(t (eval form)))))) (t (eval form))))))
(defun continue-testing () (defun continue-testing ()
...@@ -337,58 +337,58 @@ ...@@ -337,58 +337,58 @@
(do-entries *standard-output*))) (do-entries *standard-output*)))
(defun do-tests (&key (out *standard-output*) (defun do-tests (&key (out *standard-output*)
((:catch-errors *catch-errors*) *catch-errors*) ((:catch-errors *catch-errors*) *catch-errors*)
((:compile *compile-tests*) *compile-tests*)) ((:compile *compile-tests*) *compile-tests*))
(setq *failed-tests* nil (setq *failed-tests* nil
*passed-tests* nil) *passed-tests* nil)
(dolist (entry (cdr *entries*)) (dolist (entry (cdr *entries*))
(setf (pend entry) t)) (setf (pend entry) t))
(if (streamp out) (if (streamp out)
(do-entries out) (do-entries out)
(with-open-file (with-open-file
(stream out :direction :output) (stream out :direction :output)
(do-entries stream)))) (do-entries stream))))
(defun do-entries (s) (defun do-entries (s)
(format s "~&Doing ~A pending test~:P ~ (format s "~&Doing ~A pending test~:P ~
of ~A tests total.~%" of ~A tests total.~%"
(count t (the list (cdr *entries*)) :key #'pend) (count t (the list (cdr *entries*)) :key #'pend)
(length (cdr *entries*))) (length (cdr *entries*)))
(finish-output s) (finish-output s)
(dolist (entry (cdr *entries*)) (dolist (entry (cdr *entries*))
(when (and (pend entry) (when (and (pend entry)
(not (has-disabled-note entry))) (not (has-disabled-note entry)))
(let ((success? (do-entry entry s))) (let ((success? (do-entry entry s)))
(if success? (if success?
(push (name entry) *passed-tests*) (push (name entry) *passed-tests*)
(push (name entry) *failed-tests*)) (push (name entry) *failed-tests*))
(format s "~@[~<~%~:; ~:@(~S~)~>~]" success?)) (format s "~@[~<~%~:; ~:@(~S~)~>~]" success?))
(finish-output s) (finish-output s)
)) ))
(let ((pending (pending-tests)) (let ((pending (pending-tests))
(expected-table (make-hash-table :test #'equal))) (expected-table (make-hash-table :test #'equal)))
(dolist (ex *expected-failures*) (dolist (ex *expected-failures*)
(setf (gethash ex expected-table) t)) (setf (gethash ex expected-table) t))
(let ((new-failures (let ((new-failures
(loop for pend in pending (loop for pend in pending
unless (gethash pend expected-table) unless (gethash pend expected-table)
collect pend))) collect pend)))
(if (null pending) (if (null pending)
(format s "~&No tests failed.") (format s "~&No tests failed.")
(progn (progn
(format t "~&~A out of ~A total tests failed: ~%(~{~a~^~%~})" (format t "~&~A out of ~A total tests failed: ~%(~{~a~^~%~})"
(length pending) (length pending)
(length (cdr *entries*)) (length (cdr *entries*))
pending) pending)
(if (null new-failures) (if (null new-failures)
(format s "~&No unexpected failures.") (format s "~&No unexpected failures.")
(when *expected-failures* (when *expected-failures*
(format s "~&~A unexpected failures: ~ (format s "~&~A unexpected failures: ~
~:@(~{~<~% ~1:;~S~>~ ~:@(~{~<~% ~1:;~S~>~
~^, ~}~)." ~^, ~}~)."
(length new-failures) (length new-failures)
new-failures))) new-failures)))
)) ))
(finish-output s) (finish-output s)
(null pending)))) (null pending))))
...@@ -397,21 +397,21 @@ ...@@ -397,21 +397,21 @@
(defmacro defnote (name contents &optional disabled) (defmacro defnote (name contents &optional disabled)
`(eval-when (:load-toplevel :execute) `(eval-when (:load-toplevel :execute)
(let ((note (make-note :name ',name (let ((note (make-note :name ',name
:contents ',contents :contents ',contents
:disabled ',disabled))) :disabled ',disabled)))
(setf (gethash (note-name note) *notes*) note) (setf (gethash (note-name note) *notes*) note)
note))) note)))
(defun disable-note (n) (defun disable-note (n)
(let ((note (if (note-p n) n (let ((note (if (note-p n) n
(setf n (gethash n *notes*))))) (setf n (gethash n *notes*)))))
(unless note (error "~A is not a note or note name." n)) (unless note (error "~A is not a note or note name." n))
(setf (note-disabled note) t) (setf (note-disabled note) t)
note)) note))
(defun enable-note (n) (defun enable-note (n)
(let ((note (if (note-p n) n (let ((note (if (note-p n) n
(setf n (gethash n *notes*))))) (setf n (gethash n *notes*)))))
(unless note (error "~A is not a note or note name." n)) (unless note (error "~A is not a note or note name." n))
(setf (note-disabled note) nil) (setf (note-disabled note) nil)
note)) note))
...@@ -419,16 +419,15 @@ ...@@ -419,16 +419,15 @@
;;; Extended random regression ;;; Extended random regression
(defun do-extended-tests (&key (tests *passed-tests*) (count nil) (defun do-extended-tests (&key (tests *passed-tests*) (count nil)
((:catch-errors *catch-errors*) *catch-errors*) ((:catch-errors *catch-errors*) *catch-errors*)
((:compile *compile-tests*) *compile-tests*)) ((:compile *compile-tests*) *compile-tests*))
"Execute randomly chosen tests from TESTS until one fails or until "Execute randomly chosen tests from TESTS until one fails or until
COUNT is an integer and that many tests have been executed." COUNT is an integer and that many tests have been executed."
(let ((test-vector (coerce tests 'simple-vector))) (let ((test-vector (coerce tests 'simple-vector)))
(let ((n (length test-vector))) (let ((n (length test-vector)))
(when (= n 0) (error "Must provide at least one test.")) (when (= n 0) (error "Must provide at least one test."))
(loop for i from 0 (loop for i from 0
for name = (svref test-vector (random n)) for name = (svref test-vector (random n))
until (eql i count) until (eql i count)
do (print name) do (print name)
unless (do-test name) return (values name (1+ i)))))) unless (do-test name) return (values name (1+ i))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment