1 ;;; -*- show-trailing-whitespace: t; indent-tabs: nil -*-
3 ;;; Copyright (c) 2007 David Lichteblau. All rights reserved.
5 ;;; Redistribution and use in source and binary forms, with or without
6 ;;; modification, are permitted provided that the following conditions
9 ;;; * Redistributions of source code must retain the above copyright
10 ;;; notice, this list of conditions and the following disclaimer.
12 ;;; * Redistributions in binary form must reproduce the above
13 ;;; copyright notice, this list of conditions and the following
14 ;;; disclaimer in the documentation and/or other materials
15 ;;; provided with the distribution.
17 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
18 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 (in-package :cxml-rng
)
32 (defun run-tests (&optional
(p "/home/david/src/lisp/cxml-rng/spec-split/*"))
33 (dribble "/home/david/src/lisp/cxml-rng/TEST" :if-exists
:rename-and-delete
)
36 (*package
* (find-package :cxml-rng
))
38 (dolist (d (directory p
))
39 (let ((name (car (last (pathname-directory d
)))))
40 (when (parse-integer name
:junk-allowed t
)
41 (let ((xml (directory (merge-pathnames "*.xml" d
))))
42 (incf total
(1+ (length xml
)))
43 (multiple-value-bind (ok grammar
) (test1 d
)
46 (incf pass
(1+ (run-validation-tests name grammar xml
))))
49 (format t
"~A-~D: FAIL: cannot run test~%"
51 (pathname-name x
))))))))))
52 (format t
"Passed ~D/~D tests.~%" pass total
))
55 (defun run-validation-test
56 (m n
&optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
57 (let ((d (merge-pathnames (format nil
"~3,'0D/" m
) p
))
58 (*break-on-signals
* 'error
)
61 (run-validation-tests m
62 (nth-value 1 (test1 d
))
63 (list (let ((v (merge-pathnames
64 (format nil
"~A.v.xml" n
)
69 (format nil
"~A.i.xml" n
)
72 (defun run-validation-tests (name grammar tests
)
75 (format t
"~A-~D: " name
(pathname-name x
))
77 (cxml:parse-file x
(make-validator grammar
))))
78 (if (find #\v (pathname-name x
))
85 (format t
"FAIL: ~A~%" c
)))
89 (format t
"FAIL: didn't detect invalid document~%"))
92 (format t
"PASS: ~A~%" (type-of c
)))
94 (format t
"FAIL: incorrect condition type: ~A~%" c
))))))
97 (defun run-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
98 (test1 (merge-pathnames (format nil
"~3,'0D/" n
) p
)))
100 (defun parse-test (n &optional
(p "/home/david/src/lisp/cxml-rng/spec-split/"))
102 (d (merge-pathnames (format nil
"~3,'0D/" n
) p
))
103 (i (merge-pathnames "i.rng" d
))
104 (c (merge-pathnames "c.rng" d
))
105 (rng (if (probe-file c
) c i
)))
106 (format t
"~A: " (car (last (pathname-directory d
))))
111 (let* ((i (merge-pathnames "i.rng" d
))
112 (c (merge-pathnames "c.rng" d
)))
113 (format t
"~A: " (car (last (pathname-directory d
))))
116 (let ((grammar (parse-schema c
)))
120 (format t
" FAIL: ~A~%" c
)
125 (format t
" FAIL: didn't detect invalid schema~%")
128 (format t
" PASS: ~S~%" (type-of c
))
131 (format t
" FAIL: incorrect condition type: ~A~%" c
)
134 (defvar *test-xmllint
*)
136 (defun run-nist-tests
138 &optional
(p #p
"/home/david/NISTSchemaTests/NISTXMLSchemaTestSuite.xml"))
139 (dribble (if *test-xmllint
*
140 "/home/david/src/lisp/cxml-rng/NIST-xmllint"
141 "/home/david/src/lisp/cxml-rng/NIST")
142 :if-exists
:rename-and-delete
)
143 (klacks:with-open-source
(s (cxml:make-source p
))
147 while
(klacks:find-element s
"Link")
149 (multiple-value-bind (n i
)
150 (run-nist-tests/link
(klacks:get-attribute s
"href") p
)
154 (format t
"Passed ~D/~D tests.~%" pass total
)))
157 (defun run-nist-tests/link
(href base
)
158 (klacks:with-open-source
(r (cxml:make-source
(merge-pathnames href base
)))
163 (multiple-value-bind (key uri lname
)
168 (when (eq key
:start-element
)
170 ((equal lname
"Schema")
172 (let ((href (klacks:get-attribute r
"href")))
174 (if (or (search "-enumeration-" href
)
175 (search "-whiteSpace-" href
))
177 (read-nist-grammar href base
))))
180 ((equal lname
"Instance")
182 (when (run-nist-test/Instance schema
183 (klacks:get-attribute r
"href")
186 (values total pass
))))
188 (defun run-nist-test/Instance
(schema href base
)
191 (format t
"PASS INSTANCE ~A: (ignored)~%" href
)
194 (assert *test-xmllint
*)
195 (let ((asdf::*VERBOSE-OUT
* (make-string-output-stream)))
197 ((zerop (asdf:run-shell-command
198 "xmllint -relaxng ~A ~A"
200 (namestring (merge-pathnames href base
))))
201 (format t
"PASS INSTANCE ~A~%" href
)
204 (format t
"FAIL INSTANCE ~A: failed to validate:~_ ~A~%"
206 (get-output-stream-string asdf
::*VERBOSE-OUT
*))
211 (cxml:parse-file
(merge-pathnames href base
)
212 (make-validator schema
))
213 (format t
"PASS INSTANCE ~A~%" href
)
216 (format t
"FAIL INSTANCE ~A: failed to validate:~_ ~A~%" href c
)
219 (format t
"FAIL INSTANCE ~A: (BOGUS CONDITON) failed to validate:~_ ~A~%" href c
)
222 (format t
"FAIL ~A: no schema~%" href
)
225 (defun read-nist-grammar (href base
)
226 (let ((p (make-pathname :type
"rng" :defaults href
)))
230 (namestring (merge-pathnames p base
))
231 (parse-schema (merge-pathnames p base
)))
232 (format t
"PASS ~A~%" href
)
236 ((search ":NAME whiteSpace" (princ-to-string c
))
237 (format t
"PASS ~A: whiteSpace forbidden~%" href
)
239 ((search ":NAME enumeration" (princ-to-string c
))
240 (format t
"PASS ~A: enumeration forbidden~%" href
)
243 (format t
"FAIL ~A: failed to parse:~_ ~A~%" href c
)
246 (format t
"FAIL ~A: (BOGUS CONDITION) failed to parse:~_ ~A~%" href c
)