(in-package :fomus-test) (defun interface2-initform-p (form) "Is FORM a call to fomus-init ?" (eq (car form) 'fomus-init)) (defun interface2-form-p (form) "Is FORM a call to fomus interface2 ?" #|(member (car form) '(fomus-newmark fomus-newrest fomus-newnote fomus-newpart fomus-newtimesig))|# (not (member (car form) '(test-checksum)))) (defun test-fomus-split-body (body) "Splits body into fomus-* forms and test forms." (iter (for body-tail on body) (for form = (car body-tail)) (cond ((interface2-initform-p form) (collect (rest form) into init-forms)) ((interface2-form-p form) (collect form into interface2-forms)) (t (terminate))) (finally (return (values (apply #'append init-forms) interface2-forms body-tail))))) (defmacro test-fomus (name backend &body body) (multiple-value-bind (fomus-initform fomus-forms test-forms) (test-fomus-split-body body) `(test ,name (fomus-init :output ',backend :filename *fomus-test-path* :verbose 0 ,@fomus-initform) ,@fomus-forms (fomus-exec) ,@test-forms))) (defun current-test-name () (declare (special 5am::current-test)) (5am::name 5am::current-test)) (defun test-checksum (backend) (let ((actual-checksum (checksum backend)) (test-name (current-test-name))) (is (md5-hash-compare test-name backend actual-checksum) "Backend ~S - the actual checksum is: ~S" backend actual-checksum))) (export '(run-tests run-test learn learn-all test-all save-all)) (defun run-tests () "Run all fomus tests." (setf *md5-learn-checksums* nil) (5am:run! :fomus-test)) (defun run-test (test) "Run one test" (setf *md5-learn-checksums* nil) (5am:run! (find-symbol (symbol-name test) :fomus-test))) (defun learn (test) "Learn checksum for test" (setf *md5-learn-checksums* t) (5am:run! (find-symbol (symbol-name test) :fomus-test))) (defun learn-all () "Learn checksum for all tests" (setf *md5-learn-checksums* t) (setf *md5-hash* (make-hash-table :test #'equal)) (5am:run! :fomus-test)) (defmacro test-all () '(run-tests)) (defmacro save-all () '(save-md5-hash))