; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3. See distributed LICENSE.txt.
(in-package #:sheep-test)
-(defvar *tests* nil)
+(defparameter *tests* nil)
+
+; Used just for tests
+(defstruct unused-struc)
; This really is just here to check against regressions
(defun run-all-tests ()
(handler-case
(progn
(load ,source)
+ (sheep:pretty-print-validate-packages ,pkg)
(string= (slurp-file ,target) (sheep:export-package ,pkg)))
(sheep:validation-failure (vf)
(format t "Validation failure gotten: ~A~%"
(load ,source)
(let
((result (sheep:validate-package ,pkg)))
+ (let
+ ((*error-output* (make-broadcast-stream))
+ (*standard-output* (make-broadcast-stream)))
+ (sheep:pretty-print-validate-packages ,pkg))
(or
(equal ,expected result)
(format t " Got error:~%~S~% but expected~%~S~%" result ,expected)))))))
(lambda ()
(handler-case
(progn
- (funcall
- (symbol-function (find-symbol "INTERNAL-DOC->AST" :sheep-func))
- 'unused
- ,doc)
+ (setf (documentation 'unused 'function) ,doc)
+ (sheep-func:doc->ast 'unused)
nil)
(sheep:validation-failure (vf)
(let
(lambda ()
(handler-case
(progn
- (funcall
- (symbol-function (find-symbol "INTERNAL-DOC->AST" :sheep-var))
- '*unused*
- ,doc)
+ (setf (documentation '*unused* 'variable) ,doc)
+ (sheep-var:doc->ast '*unused*)
+ nil)
+ (sheep:validation-failure (vf)
+ (let
+ ((result (funcall (symbol-function (find-symbol "VALIDATION-FAILURE-MSG" :sheep)) vf)))
+ (or
+ (string= ,expected result)
+ (format t " Got error:~%~S~% but expected~%~S~%" result ,expected))))))))
+
+(defmacro deffailure-pkg-test (name doc expected)
+ `(deftest
+ ,(format nil "Package - ~A" name)
+ (lambda ()
+ (handler-case
+ (progn
+ (setf (documentation (find-package :sheep-unused) t) ,doc)
+ (sheep-pkg:doc->ast (find-package :sheep-unused))
+ nil)
+ (sheep:validation-failure (vf)
+ (let
+ ((result (funcall (symbol-function (find-symbol "VALIDATION-FAILURE-MSG" :sheep)) vf)))
+ (or
+ (string= ,expected result)
+ (format t " Got error:~%~S~% but expected~%~S~%" result ,expected))))))))
+
+(defmacro deffailure-struc-test (name doc expected)
+ `(deftest
+ ,(format nil "Struct - ~A" name)
+ (lambda ()
+ (handler-case
+ (progn
+ (setf (documentation 'unused-struc 'structure) ,doc)
+ (sheep-struc:doc->ast 'unused-struc)
nil)
(sheep:validation-failure (vf)
(let