1 ;;; -*- show-trailing-whitespace: t; indent-tabs-mode: nil -*-
3 ;;; Copyright (c) 2007,2008 David Lichteblau, Ivan Shvedunov.
4 ;;; All rights reserved.
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials
16 ;;; provided with the distribution.
18 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 (in-package :xuriella
)
32 (defparameter *tests-directory
*
33 "/home/david/src/XSLT-testsuite-04/testsuite/TESTS/")
35 (defclass test-case
()
36 ((id :initarg
:id
:accessor test-id
)
37 (category :initarg
:category
:accessor test-category
)
38 (operation :initarg
:operation
:accessor test-operation
)
39 (data-pathname :initarg
:data-pathname
:accessor test-data-pathname
)
40 (stylesheet-pathname :initarg
:stylesheet-pathname
41 :accessor test-stylesheet-pathname
)
42 (data-pathname-2 :initarg
:data-pathname-2
:accessor test-data-pathname-2
)
43 (stylesheet-pathname-2 :initarg
:stylesheet-pathname-2
44 :accessor test-stylesheet-pathname-2
)
45 (output-pathname :initarg
:output-pathname
46 :accessor test-official-output-pathname
)
47 (output-compare :initarg
:output-compare
48 :accessor test-output-compare
)))
50 (defmethod print-object ((object test-case
) stream
)
51 (print-unreadable-object (object stream
:identity nil
:type t
)
52 (format stream
"~A ~A/~A"
53 (test-operation object
)
54 (test-category object
)
60 ;;; Translate catalog.xml into an actually usable katalog.xml
61 ;;; by running the test cases through xsltproc to see what it thinks
64 (defun simplify-tests (&optional
(d *tests-directory
*))
65 (with-open-file (stream (merge-pathnames "katalog.xml" d
)
68 :element-type
'(unsigned-byte 8))
69 (cxml:with-xml-output
(cxml:make-octet-stream-sink stream
)
70 (cxml:with-element
"simplified-test-suite"
71 (klacks:with-open-source
72 (source (klacks:make-tapping-source
73 (cxml:make-source
(merge-pathnames "catalog.xml" d
))))
74 (let ((*default-pathname-defaults
* (merge-pathnames d
)))
75 (map-original-tests #'simplify-test source
)))))))
77 (defun map-original-tests (run-test source
&key
(test (constantly t
)))
82 while
(klacks:find-event source
:start-element
)
83 for lname
= (klacks:current-lname source
)
86 ((equal lname
"major-path")
87 (klacks:skip source
:start-element
)
90 (merge-pathnames (klacks:consume-characters source
)))))
91 ((equal lname
"test-case")
94 (klacks:serialize-element source
(stp:make-builder
))))
95 (test-case (parse-original-test major-path
<test-case
>)))
96 (when (funcall test test-case
)
98 (when (funcall run-test test-case
)
101 (klacks:skip source
:start-element
))))
102 (format t
"~&Passed ~D/~D tests.~%" pass total
)))
104 (defun parse-original-test (major-path <test-case
>)
107 (stp:find-recursively-if
(stp:of-name
"file-path") <test-case
>)))
108 (base (concatenate 'string major-path
"/" file-path
))
109 (out-base (concatenate 'string major-path
"/REF_OUT/" file-path
))
111 (stp:find-recursively-if
(stp:of-name
"scenario") <test-case
>))
114 supplemental-stylesheet
118 (dolist (<input
> (stp:filter-recursively
(stp:of-name
"input-file")
120 (let ((role (stp:attribute-value
<input
> "role"))
121 (path (concatenate 'string base
"/" (stp:string-value
<input
>))))
123 ((equal role
"principal-data")
125 ((equal role
"principal-stylesheet")
126 (setf stylesheet path
))
127 ((equal role
"supplemental-stylesheet")
128 (setf supplemental-stylesheet path
))
129 ((equal role
"supplemental-data")
130 (setf supplemental-data path
))
132 (error "unrecognized role: ~A" role
)))))
133 (dolist (<output
> (stp:filter-recursively
(stp:of-name
"output-file")
135 (let ((role (stp:attribute-value
<output
> "role"))
136 (path (concatenate 'string out-base
138 (stp:string-value
<output
>))))
140 ((equal role
"principal")
142 (setf compare
(stp:attribute-value
<output
> "compare")))
144 (error "unrecognized role: ~A" role
)))))
145 (make-instance 'test-case
146 :id
(stp:attribute-value
<test-case
> "id")
147 :category
(stp:attribute-value
<test-case
> "category")
148 :operation
(stp:attribute-value scenario
"operation")
150 :stylesheet-pathname stylesheet
151 :stylesheet-pathname-2 supplemental-stylesheet
152 :data-pathname-2 supplemental-data
153 :output-pathname output
154 :output-compare compare
)))
156 (defun write-simplified-test (test-case operation
)
157 (cxml:with-element
"test-case"
158 (cxml:attribute
"id" (test-id test-case
))
159 (cxml:attribute
"category" (test-category test-case
))
161 (cxml:attribute l
(and p
(namestring p
)))))
162 (p "data" (test-data-pathname test-case
))
163 (p "stylesheet" (noindent-stylesheet-pathname test-case
))
164 (p "data-2" (test-data-pathname-2 test-case
))
165 (p "stylesheet-2" (test-stylesheet-pathname-2 test-case
))
166 (p "output" (test-official-output-pathname test-case
))
167 (p "compare" (test-output-compare test-case
)))
168 (cxml:attribute
"operation" operation
)))
170 (defun test-output-pathname (test type
)
171 (make-pathname :name
(test-id test
)
173 :defaults
(test-data-pathname test
)))
175 (defun sanitize-stylesheet (in out
)
178 (let ((d (cxml:parse
(pathname in
) (stp:make-builder
))))
179 (xpath:with-namespaces
((nil #.
*xsl
*))
180 (xpath:do-node-set
(output (xpath:evaluate
"//output" d
))
181 (let ((a (stp:find-attribute-named output
"indent")))
184 (with-open-file (s out
186 :if-exists
:rename-and-delete
187 :element-type
'(unsigned-byte 8))
188 (stp:serialize d
(cxml:make-octet-stream-sink s
))))
190 (warn "ignoring bogus stylesheet ~A: ~A" in c
)
192 (warn "oops, ignoring missing stylesheet: ~A" in
)))
194 (defun noindent-stylesheet-pathname (test-case)
195 (make-pathname :type
"noindent-xsl"
196 :defaults
(test-stylesheet-pathname test-case
)))
198 (defun simplify-test (test-case)
199 (flet ((report (status &optional
(fmt "") &rest args
)
200 (format t
"~&~A ~A [~A]~?~%"
203 (test-category test-case
)
206 (let* ((data (test-data-pathname test-case
))
207 (stylesheet (test-stylesheet-pathname test-case
))
208 (noindent-stylesheet (noindent-stylesheet-pathname test-case
))
210 (out (test-output-pathname test-case
"xsltproc"))
211 (saxon-out (test-output-pathname test-case
"saxon")))
212 (sanitize-stylesheet stylesheet noindent-stylesheet
)
213 (if (equal (test-operation test-case
) "standard")
216 #+xuriella
::xsltproc
(xsltproc noindent-stylesheet data out
)
217 (saxon noindent-stylesheet data saxon-out
)
219 (write-simplified-test test-case
"standard")
222 (report "FAIL" ": ~A" c
)
223 (write-simplified-test test-case
"execution-error")
228 (xsltproc noindent-stylesheet data
"/dev/null")
229 (saxon noindent-stylesheet data
"/dev/null")
230 (report "FAIL" ": expected error not signalled")
231 ;; let's ignore unexpected successes for now
234 (report "PASS" ": expected error ~A" c
)
235 (write-simplified-test test-case
"execution-error")
238 (defun xsltproc (stylesheet input output
)
239 (flet ((full-namestring (x)
240 (namestring (merge-pathnames x
))))
241 (let* ((asdf::*verbose-out
* (make-string-output-stream))
242 (code (asdf:run-shell-command
243 "cd ~S && xsltproc ~S ~S >~S"
245 (full-namestring stylesheet
)
246 (full-namestring input
)
247 (full-namestring output
))))
249 (error "running xsltproc failed with code ~A [~%~A~%]"
251 (get-output-stream-string asdf
::*verbose-out
*))))))
253 (defun saxon (stylesheet input output
)
254 (flet ((full-namestring (x)
255 (namestring (merge-pathnames x
))))
256 (let* ((asdf::*verbose-out
* (make-string-output-stream))
257 (code (asdf:run-shell-command
258 "cd ~S && java -jar /usr/share/java/saxon.jar ~S ~S >~S"
260 (full-namestring input
)
261 (full-namestring stylesheet
)
262 (full-namestring output
))))
264 (error "running saxon failed with code ~A [~%~A~%]"
266 (get-output-stream-string asdf
::*verbose-out
*))))))
269 ;;;; RUN-TESTS and DRIBBLE-TESTS
271 ;;; Process katalog.xml
274 (&key filter
(directory *tests-directory
*) (file "TEST"))
275 (let ((*package
* (find-package 'cl-user
))
276 (*print-circle
* nil
))
277 (with-open-file (dribble
278 (merge-pathnames file
279 (slot-value (asdf:find-system
:xuriella
)
280 'asdf
::relative-pathname
))
282 :if-exists
:supersede
283 :external-format
:utf-8
)
284 (let* ((dribble (make-broadcast-stream dribble
*standard-output
*))
285 (*standard-output
* dribble
)
286 (*trace-output
* dribble
)
287 (*error-output
* dribble
)
288 (*terminal-io
* (make-two-way-stream *standard-input
* dribble
)))
289 (handler-bind ((warning
291 (warn "~A" (replace-junk (princ-to-string c
)))
292 (muffle-warning c
))))
293 (run-tests :filter filter
294 :directory directory
))))))
296 (defparameter *bad-tests
*
297 '( ;; INCONSISTENT TESTS: some tests wants us to recover from this
298 ;; error, yet this one doesn't:
302 ;; I'M TOO LAZY TO FIX THIS: we signal a run-time error when and if it's
303 ;; actually used. The test wants a compilation-time error.
305 "AttributeSets_RefToUndefinedAttributeSet"
307 ;; WE WOULD PASS THIS: we perform recovery, but saxon doesn't. Recovery
308 ;; results in non-XML output, which we can't parse for comparison
309 ;; against the official test case.
312 ;; we pass this test, but saxon doesn't
313 "AttributeSets__91038"
315 ;; we'd pass these tests, but the test authors forgot to declare the
316 ;; entity they're writing, so we can't parse it for comparison.
321 ;; another similar test where the output is unparsable, except that
322 ;; here an entity declaration wouldn't have helped either:
323 "Copying_ResultTreeFragmentWithEscapedText"
325 ;; BROKEN TEST: input document not ns-wf
328 ;; FIXME: should re-enable these at some point:
330 ;; the following tests take a lot of time due to the problems of current matching algorithm:
333 ;; stack exhaustion -- matching problem i think
335 ;; probably the same problem (but I haven't checked):
336 "numbering_numbering03"
337 "numbering_numbering10"
338 "numbering_numbering11"
339 "numbering_numbering80"
340 "numbering_numbering81"
341 "numbering_numbering94"
342 "numbering_numbering95"
345 (defun run-tests (&key filter
(directory *tests-directory
*))
346 (when (typep filter
'(or string cons
))
347 (setf filter
(cl-ppcre:create-scanner filter
)))
348 (klacks:with-open-source
349 (source (klacks:make-tapping-source
350 (cxml:make-source
(merge-pathnames "katalog.xml" directory
))))
351 (let ((*default-pathname-defaults
* (merge-pathnames directory
)))
352 (map-tests #'run-test
355 (and (or (null filter
)
356 (cl-ppcre:all-matches
361 (not (find (test-id test
)
363 :test
#'equal
))))))))
365 (defun run-named-test (name &optional
(d *tests-directory
*))
366 (let ((*break-on-signals
* 'error
))
367 (run-tests :filter
(format nil
"/~A$" name
) :directory d
)))
369 (defun copy-file (p q
)
370 (with-open-file (in p
:element-type
'(unsigned-byte 8))
371 (with-open-file (out q
372 :element-type
'(unsigned-byte 8)
374 :if-exists
:rename-and-delete
)
375 (let ((buf (make-array 8192 :element-type
'(unsigned-byte 8))))
376 (loop for pos
= (read-sequence buf in
)
378 do
(write-sequence buf out
:end pos
))))))
380 (defun find-named-test (name &optional
(d *tests-directory
*))
381 (klacks:with-open-source
382 (source (klacks:make-tapping-source
383 (cxml:make-source
(merge-pathnames "katalog.xml" d
))))
385 (map-tests (lambda (test)
388 :test
(lambda (test) (equal (test-id test
) name
))))))
390 (defun copy-test-files (name &optional
(d *tests-directory
*))
391 (let* ((test (find-named-test name d
))
392 (*default-pathname-defaults
* (merge-pathnames d
))
393 (*break-on-signals
* 'error
)
394 (target-dir (merge-pathnames "copied-test/"
395 (asdf:component-pathname
396 (asdf:find-system
:xuriella
))))
397 (xsl (merge-pathnames "test.xsl" target-dir
))
398 (xml (merge-pathnames "test.xml" target-dir
))
399 (txt (merge-pathnames "official-output.txt" target-dir
))
400 (expected (merge-pathnames "expected.xml" target-dir
))
401 (actual (merge-pathnames "actual.xml" target-dir
)))
402 (ensure-directories-exist target-dir
)
403 (copy-file (test-stylesheet-pathname test
) xsl
)
404 (copy-file (test-data-pathname test
) xml
)
405 (when (test-official-output-pathname test
)
406 (copy-file (test-official-output-pathname test
) txt
))
407 (format t
"Test stylesheet copied to:~% ~A~%~%" xsl
)
408 (format t
"Test data copied to:~% ~A~%~%" xml
)
409 (when (test-official-output-pathname test
)
410 (format t
"Official output file:~% ~A~%~%" txt
))
411 (format t
"Run xsltproc like this:~% cd ~A~% xsltproc ~A ~A >~A~%~%"
412 (namestring target-dir
)
413 (enough-namestring xsl target-dir
)
414 (enough-namestring xml target-dir
)
415 (enough-namestring expected target-dir
))
416 (format t
"Run saxon like this:~% cd ~A~% java -jar /usr/share/java/saxon.jar ~A ~A >~A~%~%"
417 (namestring target-dir
)
418 (enough-namestring xml target-dir
)
419 (enough-namestring xsl target-dir
)
420 (enough-namestring expected target-dir
))
421 (format t
"Run MSXSL like this:~% cd ~A~% wine msxsl.exe ~A ~A >~A~%~%"
422 (namestring target-dir
)
423 (enough-namestring xml target-dir
)
424 (enough-namestring xsl target-dir
)
425 (enough-namestring expected target-dir
))
426 (format t
"Run xuriella like this:~%")
427 `(apply-stylesheet ,xsl
,xml
:output
,actual
)))
429 (defun map-tests (run-test source
&key
(test (constantly t
)))
433 while
(klacks:find-event source
:start-element
)
434 for lname
= (klacks:current-lname source
)
437 ((equal lname
"test-case")
439 (stp:document-element
440 (klacks:serialize-element source
(stp:make-builder
))))
441 (test-case (parse-test <test-case
>)))
442 (when (funcall test test-case
)
444 (when (funcall run-test test-case
)
447 (klacks:skip source
:start-element
))))
448 (format t
"~&Passed ~D/~D tests.~%" pass total
)))
450 (defun parse-test (<test-case
>)
451 (stp:with-attributes
(id category operation
452 data stylesheet data-2 stylesheet-2
455 (make-instance 'test-case
460 :stylesheet-pathname stylesheet
461 :data-pathname-2 data-2
462 :stylesheet-pathname-2 stylesheet-2
463 :output-pathname output
464 :output-compare compare
)))
466 ;; read from file P, skipping the XMLDecl or TextDecl and Doctype at the
467 ;; beginning, if any.
468 (defun slurp-for-comparison (p)
469 (with-open-file (s p
:element-type
'(unsigned-byte 8))
470 (unless (and (eql (read-byte s nil
) #xef
)
471 (eql (read-byte s nil
) #xbb
)
472 (eql (read-byte s nil
) #xbf
))
474 (if (plusp (file-length s
))
475 (slurp-for-comparison-1 p s t
)
478 (defun slurp-for-comparison-1 (p s junk-info
)
479 (let ((pos (file-position s
)) ;for UTF-8 "BOM"
480 (xstream (runes:make-xstream s
:speed
1))
482 (setf (runes:xstream-name xstream
)
483 (cxml::make-stream-name
484 :entity-name
"main document"
486 :uri
(cxml::pathname-to-uri
(merge-pathnames p
))))
490 (flexi-streams:make-in-memory-input-stream
492 (cxml:make-source xstream
494 :entity-resolver
#'er
))))
495 (unless (eq junk-info
:nada
)
498 (setf prev-pos
(runes:xstream-position xstream
))
499 (klacks:peek-next source
))
500 until
(eq key
:start-document
))
501 (cxml::with-source
(source cxml
::context
)
502 (when (eq (cxml::zstream-token-category
503 (cxml::main-zstream cxml
::context
))
505 ;; oops, doesn't look like XML at all
506 (file-position s pos
)
507 (return-from slurp-for-comparison-1
508 (slurp-for-comparison-1 p s
:nada
)))))
511 (dotimes (x junk-info
)
512 (setf prev-pos
(runes:xstream-position xstream
))
513 (klacks:peek-next source
)))
518 (case (klacks:peek-next source
)
519 (:start-element
(return))
521 (if (whitespacep (klacks:current-characters source
))
526 ((or file-error cxml
:xml-parse-error
) ()
530 (with-open-file (u p
:element-type
'(unsigned-byte 8))
531 (file-position u pos
)
532 (return-from slurp-for-comparison-1
533 (slurp-for-comparison-1 p u nskip
)))))
534 ((member nil
:nada
)))
535 (with-output-to-string (r)
537 (cxml::with-source
(source cxml
::context
)
538 (ecase (cxml::zstream-token-category
539 (cxml::main-zstream cxml
::context
))
543 (setf prev-pos
(runes:xstream-position xstream
))
545 (off-by-one-p (or seen-char
(eq junk-info
:nada
)))
546 (new-pos (- prev-pos
(if off-by-one-p
1 0))))
548 (with-open-file (u p
:element-type
'(unsigned-byte 8))
549 (file-position u pos
)
550 (let ((y (runes:make-xstream u
:speed
1)))
552 while
(< (runes:xstream-position y
) new-pos
)
553 do
(write-char (runes:read-rune y
) r
))))
554 (write-line "<wrapper>" r
)
556 (write-char seen-char r
)))
558 for char
= (runes:read-rune xstream
)
560 do
(write-char char r
))
561 (write-line "</wrapper>" r
)))))
563 (defun parse-for-comparison (p)
564 (let* ((d (flet ((er (pub sys
)
566 (flexi-streams:make-in-memory-input-stream
568 (cxml:parse
(slurp-for-comparison p
)
569 (make-text-normalizer (stp:make-builder
))
570 :entity-resolver
#'er
)))
571 (de (stp:document-element d
)))
572 (let ((first (stp:first-child de
)))
573 (when (typep first
'stp
:text
)
575 ((whitespacep (stp:data first
))
576 (stp:delete-child first de
))
578 (setf (stp:data first
)
579 (cl-ppcre:regex-replace
#.
(format nil
"^[~A]+" *whitespace
*)
582 (let ((last (stp:last-child de
)))
583 (when (typep last
'stp
:text
)
585 ((whitespacep (stp:data last
))
586 (stp:delete-child last de
))
588 (setf (stp:data last
)
589 (cl-ppcre:regex-replace
#.
(format nil
"[~A]+$" *whitespace
*)
594 (defun output-equal-p (compare p q
&key normalize
)
597 (:xml
(xml-output-equal-p p q normalize
))
598 (:html
(html-output-equal-p p q
))
599 (:text
(text-output-equal-p p q
)))
600 ((or error parse-number
::invalid-number
) (c)
601 (warn "comparison failed: ~A" c
)
604 ;; Workaround for namespace_namespace23 and other tests:
605 ;; - For these tests, saxon and msxsl output a declaration for the XSL
606 ;; namespace without using that declaration.
607 ;; - I think saxon and msxsl are both wrong.
608 ;; - The official test output agrees with my assessment.
609 ;; (So does libxslt, but that's not to be trusted. :-))
610 ;; - Here's the catch: The official test output is broken in its whitespace
612 ;; So let's normalize spaces in test output that looks like an XSLT
613 ;; stylesheet, allowing us to pass these tests using the official test output.
614 (defun maybe-normalize-test-spaces (wrapper force
)
615 (stp:do-children
(wrapper-child wrapper
)
616 (when (and (typep wrapper-child
'stp
:element
)
617 (or (equal (stp:namespace-uri wrapper-child
) *xsl
*)
619 (strip-stylesheet wrapper-child
)
620 (labels ((recurse (e &optional preserve
)
621 (stp:do-children
(child e
)
624 (setf (stp:data child
)
625 (normalize-whitespace (stp:data child
))))
627 (stp:with-attributes
((space "space" *xml
*))
631 ((namep child
"text") t
)
632 ((not space
) preserve
)
633 ((equal space
"preserve") t
)
635 (recurse child new-preserve
))))))))
636 (recurse wrapper-child
)))))
638 (defun xml-output-equal-p (p q normalize
)
639 (let ((r (parse-for-comparison p
))
640 (s (parse-for-comparison q
)))
641 (maybe-normalize-test-spaces (stp:document-element r
) normalize
)
642 (maybe-normalize-test-spaces (stp:document-element s
) normalize
)
643 (and (let ((u (stp:document-type r
))
644 (v (stp:document-type s
)))
648 (node= (stp:document-element r
) (stp:document-element s
)))))
650 ;; FIXME: don't do this in <pre> etc.
651 (defun normalize-html-whitespace (node)
652 (when (typep node
'stp
:parent-node
)
653 ;; ignore newlines after start tags completely
654 (let ((first (stp:first-child node
)))
655 (when (and (typep first
'stp
:text
)
656 (alexandria:starts-with
#\newline
(stp:data first
)))
657 (setf (stp:data first
) (subseq (stp:data first
) 1))))
658 ;; ignore newlines before end tags completely
659 (let ((last (stp:last-child node
)))
660 (when (and (typep last
'stp
:text
)
661 (alexandria:ends-with
#\newline
(stp:data last
)))
662 (setf (stp:data last
)
663 (subseq (stp:data last
) 0 (length (stp:data last
))))))
664 ;; normalize sequences of whitespace
665 (stp:do-children
(child node
)
666 (if (typep child
'stp
:text
)
667 (setf (stp:data child
)
668 (let ((str (normalize-whitespace (stp:data child
))))
670 ;; FIXME! Here we remove whitespace entirely.
671 ;; Totally incorrect, but I don't see how we could
672 ;; watch Saxon's output otherwise.
676 (normalize-html-whitespace child
)))
677 ;; just to be sure, join adjacent nodes
678 (cxml-stp-impl::normalize-text-nodes
! node
)))
680 ;; FIXME: this check is too lenient, because chtml is an error-correcting
682 (defun html-output-equal-p (p q
)
683 (let ((r (chtml:parse
(pathname p
) (stp:make-builder
)))
684 (s (chtml:parse
(pathname q
) (stp:make-builder
))))
685 (normalize-html-whitespace r
)
686 (normalize-html-whitespace s
)
687 (node= (stp:document-element r
) (stp:document-element s
))))
689 (defun text-output-equal-p (p q
)
690 (with-open-file (a p
:element-type
'(unsigned-byte 8))
691 (with-open-file (b q
:element-type
'(unsigned-byte 8))
692 (let ((len (file-length a
)))
693 (and (eql len
(file-length b
))
694 (let ((d (make-array len
:element-type
'(unsigned-byte 8)))
695 (e (make-array len
:element-type
'(unsigned-byte 8))))
700 (defun strip-addresses (str)
701 (cl-ppcre:regex-replace-all
"{[0-9a-fA-F]+}\\>" str
"{xxxxxxxx}>"))
703 (defun slurp-output-method (p)
704 (xpath:with-namespaces
((nil #.
*xsl
*))
705 (let* ((d (handler-bind
706 ((warning #'muffle-warning
))
707 (cxml:parse
(pathname p
) (stp:make-builder
))))
708 (output (xpath:first-node
(xpath:evaluate
"//output" d
))))
710 (let ((method (stp:attribute-value output
"method")))
712 (intern (string-upcase method
) :keyword
)
716 (defun replace-junk (str)
717 (cl-ppcre:regex-replace-all
718 `(:group
,(namestring *tests-directory
*))
721 (if (or (eql c
#\newline
) (<= 32 (char-code c
) 126))
727 (defun run-test (test)
728 (let ((expected-saxon (test-output-pathname test
"saxon"))
730 (expected-xsltproc (test-output-pathname test
"xsltproc"))
731 (actual (test-output-pathname test
"xuriella"))
732 (official (test-official-output-pathname test
))
734 (find (test-id test
) '("Namespace-alias__91782") :test
#'equal
))
736 (handler-bind ((|hey test suite
, this is an HTML document|
739 (setf output-method
:html
))))
740 (labels ((uri-resolver (uri)
741 (if (search "%5c%5c%5c%5cwebxtest%5c%5cmanagedshadow%5c%5cmanaged_b2%5c%5ctestdata%5c%5cxslt%5c%5celement%5c%5cxslt_element_NSShared.xml"
743 (cxml::pathname-to-uri
745 "MSFT_Conformance_Tests/Elements/xslt_element_NSShared.xml"
749 (with-open-file (s actual
750 :if-exists
:rename-and-delete
752 :element-type
'(unsigned-byte 8))
753 (handler-bind ((xslt-error
756 (when (find-restart 'recover
)
757 (invoke-restart 'recover
)))))
758 (apply-stylesheet (pathname (test-stylesheet-pathname test
))
759 (pathname (test-data-pathname test
))
761 :uri-resolver
#'uri-resolver
))))
764 (format t
" ~A: ~A~%"
766 (enough-namestring pathname
*tests-directory
*))))
767 (report (ok &optional
(fmt "") &rest args
)
771 (format nil
"~&~:[FAIL~;PASS~] ~A [~A]~?~%"
777 (pp "Stylesheet" (test-stylesheet-pathname test
))
778 (pp "Data" (test-data-pathname test
))
779 (pp "Supplemental stylesheet"
780 (test-stylesheet-pathname-2 test
))
781 (pp "Supplemental data" (test-data-pathname-2 test
))
782 (pp "Expected output (1)" expected-saxon
)
784 (pp "Expected output (2)" expected-xsltproc
)
785 (pp "Actual output" actual
)
789 ((equal (test-operation test
) "standard")
792 (when (find (test-id test
)
793 nil
;;'("axes_axes47" "attribset_attribset20")
795 (error "skipping problematic test"))
797 (let* ((output-method
800 (test-stylesheet-pathname test
))))
802 (output-equal-p output-method
807 (output-equal-p output-method
811 (output-equal-p output-method
814 :normalize force-normalization
)))
817 #+xuriella
::xsltproc xsltproc-matches-p
821 (report t
": saxon ~A, xsltproc ~A~:[~; (MISMATCH)~]"
825 (not xsltproc-matches-p
)
826 xsltproc-matches-p
)))
828 (report nil
": output doesn't match")))))
829 ((or error parse-number
::invalid-number
) (c)
830 (report nil
": ~A" c
))))
835 (report t
": raised an xslt-error as expected" c
))
836 ((or error parse-number
::invalid-number
) (c)
837 (report nil
": condition of incorrect type: ~%~A" c
))
840 ((not (and official
(probe-file official
)))
841 (report nil
": expected error not signalled: " result
))
844 (slurp-output-method (test-stylesheet-pathname test
)))
847 :normalize force-normalization
)
850 (report nil
": saxon error not signalled and official output not a match")))))))))))
852 (defun run-xpath-tests ()
853 (run-tests "XPath-Expression/|XSLT-Data-Model/"))
856 ;;;; from cxml-stp-test
858 (defun assert-node= (a b
)
860 (error "assertion failed: ~S and ~S are not NODE=" a b
)))
862 (defun child-count (node)
863 (stp:count-children-if
(constantly t
) node
))
865 (defun named-node-= (a b
)
866 (and (equal (stp:namespace-uri a
) (stp:namespace-uri b
))
867 ;; (equal (stp:namespace-prefix a) (stp:namespace-prefix b))
868 (equal (stp:local-name a
) (stp:local-name b
))))
870 (defun parent-node-= (e f
)
871 (and (eql (child-count e
)
873 (every #'node
= (stp:list-children e
) (stp:list-children f
))))
875 (defmethod node= ((e stp
:element
) (f stp
:element
))
876 (and (named-node-= e f
)
879 (set-exclusive-or (stp:list-attributes e
) (stp:list-attributes f
)
882 (flet ((check-namespaces (a b
)
884 (stp:map-extra-namespaces
886 (unless (equal v
(stp:find-namespace k b
))
890 (check-namespaces e f
)
891 (check-namespaces f e
))
894 (defmethod node= ((a stp
:node
) (b stp
:node
))
897 (defmethod node= ((e stp
:document
) (f stp
:document
))
900 (defmethod node= ((a stp
:attribute
) (b stp
:attribute
))
901 (and (named-node-= a b
)
902 (equal (stp:value a
) (stp:value b
))))
904 (defmethod node= ((a stp
:comment
) (b stp
:comment
))
905 (equal (stp:data a
) (stp:data b
)))
907 (defmethod node= ((a stp
:text
) (b stp
:text
))
908 (equal (stp:data a
) (stp:data b
)))
910 (defmethod node= ((a stp
:processing-instruction
)
911 (b stp
:processing-instruction
))
912 (and (equal (stp:data a
) (stp:data b
))
913 (equal (stp:target a
) (stp:target b
))))
915 (defmethod node= ((a stp
:document-type
) (b stp
:document-type
))
916 (and (equal (stp:root-element-name a
) (stp:root-element-name b
))
917 (equal (stp:public-id a
) (stp:public-id b
))
918 (equal (stp:system-id a
) (stp:system-id b
))
919 (equal (stp:internal-subset a
) (stp:internal-subset b
))))
921 (xpath-sys:define-xpath-function
/eager
924 (if (xpath:node-set-p thing
)
926 initially
(format t
";;; node set:~%")
928 for node in
(xpath:all-nodes thing
)
930 (format t
";;; ~D: ~A~%" i
(type-of node
)))
931 (format t
";;; ~A~%" thing
))