--- /dev/null
+(defpackage #:emptydocs (:use :cl)
+ (:export #:no-doc-func))
+
+(in-package #:emptydocs)
+
+(defun no-doc-func (path x) path)
(define-condition validation-failure nil ((msg :initarg :msg :reader validation-failure-msg)))
+(defun get-symb-type (symb)
+ (cond
+ ;((documentation symb 'variable) :variable)
+ ;((documentation symb 'structure) :structure)
+ ((documentation symb 'function) :function)))
+
(defun validate-package (pkg)
(macrolet
((with-success-check (&rest f)
`(handler-case
(progn ,@f :success)
- (validation-failure (v) (list :failure :msg (validation-failure-msg v))))))
+ (validation-failure (v) (list :failure (validation-failure-msg v))))))
(let
((symbs nil))
(do-external-symbols (symb pkg) (push symb symbs))
(setf symbs (sort symbs #'string< :key #'symbol-name))
(remove :success
(append
- (list (with-success-check (docgen-pkg:doc->ast pkg)))
+ (list (with-success-check (docgen-pkg:doc->ast (find-package pkg))))
(mapcar
- (lambda (symb) (with-success-check (docgen-func:doc->ast symb)))
+ (lambda (symb)
+ (with-success-check
+ (case (get-symb-type symb)
+ (:function (docgen-func:doc->ast symb))
+ (t (error (make-condition 'validation-failure :msg (format nil "Symbol ~A has no documentation" symb)))))))
symbs))))))
+(defun pretty-print-validate-packages (&rest pkgs)
+ (mapcar
+ (lambda (pkg)
+ (let
+ ((failures (validate-package pkg)))
+ (mapcar
+ (lambda (failure)
+ (format t "In package ~A, documentation error found:~% ~A" pkg (cadr failure)))
+ failures)
+ (not failures)))
+ pkgs))
+
(defun export-package (pkg)
(let
((symbs nil))
(setf symbs (sort symbs #'string< :key #'symbol-name))
(with-output-to-string (str)
(format str "~A~%~%" (docgen-pkg:ast->md (docgen-pkg:doc->ast (find-package pkg))))
- (format str "~{~A~^~%~}" (mapcar (lambda (symb) (docgen-func:ast->md (docgen-func:doc->ast symb))) symbs)))))
+ (format str "~{~A~^~%~}"
+ (mapcar
+ (lambda (symb)
+ (case (get-symb-type symb)
+ (:function (docgen-func:ast->md (docgen-func:doc->ast symb)))))
+ symbs)))))
(defpackage #:docgen (:use :cl)
- (:export #:validate-package #:export-package #:validation-failure))
+ (:export #:validate-package #:export-package #:validation-failure #:pretty-print-validate-packages))
(defpackage #:docgen-func (:use :cl)
(:export #:doc->ast #:ast->md))
(defun fire-error (msg) (error (make-instance 'docgen:validation-failure :msg msg)))
(defun doc->ast (pkg)
+ (when (not (documentation pkg t)) (fire-error (format nil "Package ~A has no documentation" (package-name pkg))))
(labels
((validate (strs)
(mapcar
`(push
(lambda ()
(let
- ((success (funcall ,f)))
+ ((success
+ (handler-case
+ (funcall ,f)
+ (error (e) (format t "Got unexpected error in tests: ~A" e)))))
(if success
(format t "~c[1;32m- ~A passed~c[0m~%" #\Esc ,name #\Esc)
(format t "~c[1;31m- ~A failed~c[0m~%" #\Esc ,name #\Esc))
(load ,source)
(string= (slurp-file ,target) (docgen:export-package ,pkg)))
(docgen:validation-failure (vf)
- (format t "Error gotten: ~A~%"
- (funcall (symbol-function (find-symbol "VALIDATION-FAILURE-MSG" :docgen)) vf)))
- (error (e) (format t "Error gotten: ~A~%" e))))))
+ (format t "Validation failure gotten: ~A~%"
+ (funcall (symbol-function (find-symbol "VALIDATION-FAILURE-MSG" :docgen)) vf)))))))
+
+(defmacro deffailuretest (pkg source expected)
+ `(deftest
+ ,source
+ (lambda ()
+ (progn
+ (load ,source)
+ (let
+ ((result (docgen:validate-package ,pkg)))
+ (or
+ (equal ,expected result)
+ (format t " Got error:~%~S~% but expected~%~S~%" result ,expected)))))))
(defmacro deffailure-func-test (name doc expected)
`(deftest
(format t " Got error:~%~S~% but expected~%~S~%" result ,expected))))))))
(defsuccesstest :success1 "resources/success1.lisp" "resources/success1.md")
+(deffailuretest :emptydocs "resources/emptydocs.lisp"
+ '((:failure "Package EMPTYDOCS has no documentation")
+ (:failure "Symbol NO-DOC-FUNC has no documentation")))