fixed AVT escaping
[xuriella.git] / test.lisp
blobe712bdc2acc5c2731ef08c0f77f7875670e6e33c
1 ;;; -*- show-trailing-whitespace: t; indent-tabs: 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
8 ;;; are met:
9 ;;;
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
12 ;;;
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.
17 ;;;
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)
55 (test-id object))))
58 ;;;; SIMPLIFY-TESTS
60 ;;; Translate catalog.xml into an actually usable katalog.xml
61 ;;; by running the test cases through xsltproc to see what it thinks
62 ;;; about them.
64 (defun simplify-tests (&optional (d *tests-directory*))
65 (with-open-file (stream (merge-pathnames "katalog.xml" d)
66 :direction :output
67 :if-exists :supersede
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)))
78 (let ((total 0)
79 (pass 0)
80 major-path)
81 (loop
82 while (klacks:find-event source :start-element)
83 for lname = (klacks:current-lname source)
85 (cond
86 ((equal lname "major-path")
87 (klacks:skip source :start-element)
88 (setf major-path
89 (namestring
90 (merge-pathnames (klacks:consume-characters source)))))
91 ((equal lname "test-case")
92 (let* ((<test-case>
93 (stp:document-element
94 (klacks:serialize-element source (stp:make-builder))))
95 (test-case (parse-original-test major-path <test-case>)))
96 (when (funcall test test-case)
97 (incf total)
98 (when (funcall run-test test-case)
99 (incf pass)))))
101 (klacks:skip source :start-element))))
102 (format t "~&Passed ~D/~D tests.~%" pass total)))
104 (defun parse-original-test (major-path <test-case>)
105 (let* ((file-path
106 (stp:string-value
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))
110 (scenario
111 (stp:find-recursively-if (stp:of-name "scenario") <test-case>))
112 data
113 stylesheet
114 supplemental-stylesheet
115 supplemental-data
116 output
117 compare)
118 (dolist (<input> (stp:filter-recursively (stp:of-name "input-file")
119 <test-case>))
120 (let ((role (stp:attribute-value <input> "role"))
121 (path (concatenate 'string base "/" (stp:string-value <input>))))
122 (cond
123 ((equal role "principal-data")
124 (setf data path))
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")
134 <test-case>))
135 (let ((role (stp:attribute-value <output> "role"))
136 (path (concatenate 'string out-base
138 (stp:string-value <output>))))
139 (cond
140 ((equal role "principal")
141 (setf output path)
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")
149 :data-pathname data
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))
160 (flet ((p (l p)
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)
172 :type type
173 :defaults (test-data-pathname test)))
175 (defun sanitize-stylesheet (in out)
176 (if (probe-file in)
177 (handler-case
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")))
182 (when a
183 (stp:detach a)))))
184 (with-open-file (s out
185 :direction :output
186 :if-exists :rename-and-delete
187 :element-type '(unsigned-byte 8))
188 (stp:serialize d (cxml:make-octet-stream-sink s))))
189 (error (c)
190 (warn "ignoring bogus stylesheet ~A: ~A" in c)
191 (copy-file in out)))
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]~?~%"
201 status
202 (test-id test-case)
203 (test-category test-case)
205 args)))
206 (let* ((data (test-data-pathname test-case))
207 (stylesheet (test-stylesheet-pathname test-case))
208 (noindent-stylesheet (noindent-stylesheet-pathname test-case))
209 #+xuriella::xsltproc
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")
214 (handler-case
215 (progn
216 #+xuriella::xsltproc (xsltproc noindent-stylesheet data out)
217 (saxon noindent-stylesheet data saxon-out)
218 (report "PASS")
219 (write-simplified-test test-case "standard")
221 (error (c)
222 (report "FAIL" ": ~A" c)
223 (write-simplified-test test-case "execution-error")
224 nil))
225 (handler-case
226 (progn
227 #+xuriella::xsltproc
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
232 nil)
233 (error (c)
234 (report "PASS" ": expected error ~A" c)
235 (write-simplified-test test-case "execution-error")
236 t))))))
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"
244 (full-namestring "")
245 (full-namestring stylesheet)
246 (full-namestring input)
247 (full-namestring output))))
248 (unless (zerop code)
249 (error "running xsltproc failed with code ~A [~%~A~%]"
250 code
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"
259 (full-namestring "")
260 (full-namestring input)
261 (full-namestring stylesheet)
262 (full-namestring output))))
263 (unless (zerop code)
264 (error "running saxon failed with code ~A [~%~A~%]"
265 code
266 (get-output-stream-string asdf::*verbose-out*))))))
269 ;;;; RUN-TESTS and DRIBBLE-TESTS
271 ;;; Process katalog.xml
273 ;; temporary configuration until we support enough XSLT that it's worth
274 ;; running all tests:
275 (defparameter *default-categories*
276 ;; '("XSLT-Data-Model" "XPath-Expression" "XPath-Data-Model")
277 nil)
279 (defun dribble-tests (&optional (category *default-categories*)
280 (d *tests-directory*))
281 (let ((*package* (find-package 'cl-user)))
282 (with-open-file (dribble
283 (merge-pathnames "TEST"
284 (slot-value (asdf:find-system :xuriella)
285 'asdf::relative-pathname))
286 :direction :output
287 :if-exists :supersede
288 :external-format :utf-8)
289 (let* ((dribble (make-broadcast-stream dribble *standard-output*))
290 (*standard-output* dribble)
291 (*trace-output* dribble)
292 (*error-output* dribble)
293 (*terminal-io* (make-two-way-stream *standard-input* dribble)))
294 (run-tests category d)))))
296 (defparameter *bad-tests*
297 '( ;; some tests wants us to recover from this error, yet this one doesn't:
298 "copy_copy61"
299 "copy_copy62"))
301 (defun run-tests (&optional (categories *default-categories*)
302 (d *tests-directory*))
303 (unless (listp categories)
304 (setf categories (list categories)))
305 (klacks:with-open-source
306 (source (klacks:make-tapping-source
307 (cxml:make-source (merge-pathnames "katalog.xml" d))))
308 (let ((*default-pathname-defaults* (merge-pathnames d)))
309 (map-tests #'run-test
310 source
311 :test (lambda (test)
312 (and (or (null categories)
313 (find (test-category test)
314 categories
315 :test #'equal))
316 (not (find (test-id test)
317 *bad-tests*
318 :test #'equal))))))))
320 (defun run-named-test (name &optional (d *tests-directory*))
321 (klacks:with-open-source
322 (source (klacks:make-tapping-source
323 (cxml:make-source (merge-pathnames "katalog.xml" d))))
324 (let ((*default-pathname-defaults* (merge-pathnames d))
325 (*break-on-signals* 'error))
326 (map-tests #'run-test
327 source
328 :test (lambda (test) (equal (test-id test) name))))))
330 (defun copy-file (p q)
331 (with-open-file (in p :element-type '(unsigned-byte 8))
332 (with-open-file (out q
333 :element-type '(unsigned-byte 8)
334 :direction :output
335 :if-exists :rename-and-delete)
336 (let ((buf (make-array 8192 :element-type '(unsigned-byte 8))))
337 (loop for pos = (read-sequence buf in)
338 until (zerop pos)
339 do (write-sequence buf out :end pos))))))
341 (defun find-named-test (name &optional (d *tests-directory*))
342 (klacks:with-open-source
343 (source (klacks:make-tapping-source
344 (cxml:make-source (merge-pathnames "katalog.xml" d))))
345 (block nil
346 (map-tests (lambda (test)
347 (return test))
348 source
349 :test (lambda (test) (equal (test-id test) name))))))
351 (defun copy-test-files (name &optional (d *tests-directory*))
352 (let* ((test (find-named-test name d))
353 (*default-pathname-defaults* (merge-pathnames d))
354 (*break-on-signals* 'error)
355 (target-dir (merge-pathnames "copied-test/"
356 (asdf:component-pathname
357 (asdf:find-system :xuriella))))
358 (xsl (merge-pathnames "test.xsl" target-dir))
359 (xml (merge-pathnames "test.xml" target-dir))
360 (txt (merge-pathnames "official-output.txt" target-dir))
361 (expected (merge-pathnames "expected.xml" target-dir))
362 (actual (merge-pathnames "actual.xml" target-dir)))
363 (ensure-directories-exist target-dir)
364 (copy-file (test-stylesheet-pathname test) xsl)
365 (copy-file (test-data-pathname test) xml)
366 (when (test-official-output-pathname test)
367 (copy-file (test-official-output-pathname test) txt))
368 (format t "Test stylesheet copied to:~% ~A~%~%" xsl)
369 (format t "Test data copied to:~% ~A~%~%" xml)
370 (when (test-official-output-pathname test)
371 (format t "Official output file:~% ~A~%~%" txt))
372 (format t "Run xsltproc like this:~% cd ~A~% xsltproc ~A ~A >~A~%~%"
373 (namestring target-dir)
374 (enough-namestring xsl target-dir)
375 (enough-namestring xml target-dir)
376 (enough-namestring expected target-dir))
377 (format t "Run saxon like this:~% cd ~A~% java -jar /usr/share/java/saxon.jar ~A ~A >~A~%~%"
378 (namestring target-dir)
379 (enough-namestring xml target-dir)
380 (enough-namestring xsl target-dir)
381 (enough-namestring expected target-dir))
382 (format t "Run MSXSL like this:~% cd ~A~% wine msxsl.exe ~A ~A >~A~%~%"
383 (namestring target-dir)
384 (enough-namestring xml target-dir)
385 (enough-namestring xsl target-dir)
386 (enough-namestring expected target-dir))
387 (format t "Run xuriella like this:~%")
388 `(apply-stylesheet ,xsl ,xml :output ,actual)))
390 (defun map-tests (run-test source &key (test (constantly t)))
391 (let ((total 0)
392 (pass 0))
393 (loop
394 while (klacks:find-event source :start-element)
395 for lname = (klacks:current-lname source)
397 (cond
398 ((equal lname "test-case")
399 (let* ((<test-case>
400 (stp:document-element
401 (klacks:serialize-element source (stp:make-builder))))
402 (test-case (parse-test <test-case>)))
403 (when (funcall test test-case)
404 (incf total)
405 (when (funcall run-test test-case)
406 (incf pass)))))
408 (klacks:skip source :start-element))))
409 (format t "~&Passed ~D/~D tests.~%" pass total)))
411 (defun parse-test (<test-case>)
412 (stp:with-attributes (id category operation
413 data stylesheet data-2 stylesheet-2
414 output compare)
415 <test-case>
416 (make-instance 'test-case
417 :id id
418 :category category
419 :operation operation
420 :data-pathname data
421 :stylesheet-pathname stylesheet
422 :data-pathname-2 data-2
423 :stylesheet-pathname-2 stylesheet-2
424 :output-pathname output
425 :output-compare compare)))
427 ;; read from file P, skipping the XMLDecl or TextDecl and Doctype at the
428 ;; beginning, if any.
429 (defun slurp-for-comparison (p)
430 (with-open-file (s p :element-type '(unsigned-byte 8))
431 (unless (and (eql (read-byte s nil) #xef)
432 (eql (read-byte s nil) #xbb)
433 (eql (read-byte s nil) #xbf))
434 (file-position s 0))
435 (if (plusp (file-length s))
436 (let ((xstream (runes:make-xstream s :speed 1)))
437 (setf (runes:xstream-name xstream)
438 (cxml::make-stream-name
439 :entity-name "main document"
440 :entity-kind :main
441 :uri (cxml::pathname-to-uri (merge-pathnames p))))
442 (let ((source (cxml:make-source xstream :pathname p)))
443 (loop
444 for key = (klacks:peek-next source)
445 until (eq key :start-document))
446 (with-output-to-string (r)
447 (write-line "<wrapper>" r)
448 (cxml::with-source (source cxml::context)
449 (when (eq (cxml::zstream-token-category
450 (cxml::main-zstream cxml::context))
451 :seen-<)
452 (write-char #\< r)))
453 (loop
454 for char = (runes:read-rune xstream)
455 until (eq char :eof)
456 do (write-char char r))
457 (write-line "</wrapper>" r))))
458 "<wrapper/>")))
460 (defun parse-for-comparison (p)
461 (let* ((d (cxml:parse (slurp-for-comparison p)
462 (make-text-normalizer (stp:make-builder))))
463 (de (stp:document-element d)))
464 (let ((first (stp:first-child de)))
465 (when (typep first 'stp:text)
466 (cond
467 ((whitespacep (stp:data first))
468 (stp:delete-child first de))
470 (setf (stp:data first)
471 (cl-ppcre:regex-replace #.(format nil "^[~A]+" *whitespace*)
472 (stp:data first)
473 ""))))))
474 (let ((last (stp:last-child de)))
475 (when (typep last 'stp:text)
476 (cond
477 ((whitespacep (stp:data last))
478 (stp:delete-child last de))
480 (setf (stp:data last)
481 (cl-ppcre:regex-replace #.(format nil "[~A]+$" *whitespace*)
482 (stp:data last)
483 ""))))))
486 (defun output-equal-p (compare p q)
487 (handler-case
488 (ecase compare
489 (:xml (xml-output-equal-p p q))
490 (:html (html-output-equal-p p q)))
491 ((or error parse-number::invalid-number) (c)
492 (warn "comparison failed: ~A" c)
493 nil)))
495 (defun xml-output-equal-p (p q)
496 (let ((r (parse-for-comparison p))
497 (s (parse-for-comparison q)))
498 (node= (stp:document-element r) (stp:document-element s))))
500 ;; FIXME: don't do this in <pre> etc.
501 (defun normalize-html-whitespace (node)
502 (when (typep node 'stp:parent-node)
503 ;; ignore newlines after start tags completely
504 (let ((first (stp:first-child node)))
505 (when (and (typep first 'stp:text)
506 (alexandria:starts-with #\newline (stp:data first)))
507 (setf (stp:data first) (subseq (stp:data first) 1))))
508 ;; ignore newlines before end tags completely
509 (let ((last (stp:last-child node)))
510 (when (and (typep last 'stp:text)
511 (alexandria:ends-with #\newline (stp:data last)))
512 (setf (stp:data last)
513 (subseq (stp:data last) 0 (length (stp:data last))))))
514 ;; normalize sequences of whitespace
515 (stp:do-children (child node)
516 (if (typep child 'stp:text)
517 (setf (stp:data child)
518 (let ((str (normalize-whitespace (stp:data child))))
519 (when
520 ;; FIXME! Here we remove whitespace entirely.
521 ;; Totally incorrect, but I don't see how we could
522 ;; watch Saxon's output otherwise.
523 (equal str " ")
524 (setf str ""))
525 str))
526 (normalize-html-whitespace child)))
527 ;; just to be sure, join adjacent nodes
528 (cxml-stp-impl::normalize-text-nodes! node)))
530 ;; FIXME: this check is too lenient, because chtml is an error-correcting
531 ;; parser.
532 (defun html-output-equal-p (p q)
533 (let ((r (chtml:parse (pathname p) (stp:make-builder)))
534 (s (chtml:parse (pathname q) (stp:make-builder))))
535 (normalize-html-whitespace r)
536 (normalize-html-whitespace s)
537 (node= (stp:document-element r) (stp:document-element s))))
539 (defun strip-addresses (str)
540 (cl-ppcre:regex-replace-all "{[0-9a-fA-F]+}\\>" str "{xxxxxxxx}>"))
542 (xpath:with-namespaces ((nil #.*xsl*))
543 (defun slurp-output-method (p)
544 (let* ((d (handler-bind
545 ((warning #'muffle-warning))
546 (cxml:parse (pathname p) (stp:make-builder))))
547 (output (xpath:first-node (xpath:evaluate "//output" d))))
548 (if output
549 (let ((method (stp:attribute-value output "method")))
550 (if method
551 (intern (string-upcase method) :keyword)
552 :xml))
553 :xml))))
555 (defun run-test (test)
556 (let ((expected-saxon (test-output-pathname test "saxon"))
557 #+xuriella::xsltproc
558 (expected-xsltproc (test-output-pathname test "xsltproc"))
559 (actual (test-output-pathname test "xuriella"))
560 (official (test-official-output-pathname test)))
561 (labels ((uri-resolver (uri)
562 (describe uri)
563 (if (search "%5c%5c%5c%5cwebxtest%5c%5cmanagedshadow%5c%5cmanaged_b2%5c%5ctestdata%5c%5cxslt%5c%5celement%5c%5cxslt_element_NSShared.xml"
564 uri)
565 (cxml::pathname-to-uri
566 (merge-pathnames
567 "MSFT_Conformance_Tests/Elements/xslt_element_NSShared.xml"
568 *tests-directory*))
569 uri))
570 (doit ()
571 (with-open-file (s actual
572 :if-exists :rename-and-delete
573 :direction :output
574 :element-type '(unsigned-byte 8))
575 (handler-bind ((xslt-error
576 (lambda (c)
577 (declare (ignore c))
578 (when (find-restart 'recover)
579 (invoke-restart 'recover)))))
580 (apply-stylesheet (pathname (test-stylesheet-pathname test))
581 (pathname (test-data-pathname test))
582 :output s
583 :uri-resolver #'uri-resolver))))
584 (pp (label pathname)
585 (when pathname
586 (format t " ~A: ~A~%"
587 label
588 (enough-namestring pathname *tests-directory*))))
589 (report (ok &optional (fmt "") &rest args)
590 (write-string
591 (strip-addresses
592 (format nil "~&~:[FAIL~;PASS~] ~A [~A]~?~%"
594 (test-id test)
595 (test-category test)
597 args)))
598 (pp "Stylesheet" (test-stylesheet-pathname test))
599 (pp "Data" (test-data-pathname test))
600 (pp "Supplemental stylesheet"
601 (test-stylesheet-pathname-2 test))
602 (pp "Supplemental data" (test-data-pathname-2 test))
603 (pp "Expected output (1)" expected-saxon)
604 #+xuriella::xsltproc
605 (pp "Expected output (2)" expected-xsltproc)
606 (pp "Actual output" actual)
607 (terpri)
608 ok))
609 (cond
610 ((equal (test-operation test) "standard")
611 (handler-case
612 (let ((output-method
613 (slurp-output-method (test-stylesheet-pathname test))))
614 (when (find (test-id test)
615 nil ;;'("axes_axes47" "attribset_attribset20")
616 :test #'equal)
617 (error "skipping problematic test"))
618 (doit)
619 (let ((saxon-matches-p
620 (output-equal-p output-method
621 expected-saxon
622 actual))
623 #+xuriella::xsltproc
624 (xsltproc-matches-p
625 (output-equal-p output-method
626 expected-xsltproc
627 actual))
628 (official-matches-p
629 (output-equal-p output-method
630 official
631 actual)))
632 (cond
633 ((or saxon-matches-p
634 #+xuriella::xsltproc xsltproc-matches-p
635 official-matches-p)
636 (report t)
637 #+xuriella::xsltproc
638 (report t ": saxon ~A, xsltproc ~A~:[~; (MISMATCH)~]"
639 saxon-matches-p
640 xsltproc-matches-p
641 (if saxon-matches-p
642 (not xsltproc-matches-p)
643 xsltproc-matches-p)))
645 (report nil ": output doesn't match")))))
646 ((or error parse-number::invalid-number) (c)
647 (report nil ": ~A" c))))
649 (handler-case
650 (doit)
651 (xslt-error (c)
652 (report t ": raised an xslt-error as expected" c))
653 ((or error parse-number::invalid-number) (c)
654 (report nil ": condition of incorrect type: ~%~A" c))
655 (:no-error (result)
656 (cond
657 ((not (and official (probe-file official)))
658 (report nil ": expected error not signalled: " result))
659 ((output-equal-p
660 (slurp-output-method (test-stylesheet-pathname test))
661 official
662 actual)
663 (report t))
665 (report nil ": saxon error not signalled and official output not a match"))))))))))
667 (defun run-xpath-tests ()
668 (run-tests '("XPath-Expression" "XSLT-Data-Model")))
671 ;;;; from cxml-stp-test
673 (defun assert-node= (a b)
674 (unless (node= a b)
675 (error "assertion failed: ~S and ~S are not NODE=" a b)))
677 (defun child-count (node)
678 (stp:count-children-if (constantly t) node))
680 (defun named-node-= (a b)
681 (and (equal (stp:namespace-uri a) (stp:namespace-uri b))
682 ;; (equal (stp:namespace-prefix a) (stp:namespace-prefix b))
683 (equal (stp:local-name a) (stp:local-name b))))
685 (defun parent-node-= (e f)
686 (and (eql (child-count e)
687 (child-count f))
688 (every #'node= (stp:list-children e) (stp:list-children f))))
690 (defmethod node= ((e stp:element) (f stp:element))
691 (and (named-node-= e f)
692 (parent-node-= e f)
693 (null
694 (set-exclusive-or (stp:list-attributes e) (stp:list-attributes f)
695 :test #'node=))
696 (flet ((collect-namespaces (elt)
697 (let ((result ()))
698 (stp:map-extra-namespaces
699 (lambda (k v) (push (cons k v) result))
700 elt)
701 result)))
702 (null
703 (set-exclusive-or (collect-namespaces e) (collect-namespaces f)
704 :test #'equal)))))
706 (defmethod node= ((a stp:node) (b stp:node))
707 nil)
709 (defmethod node= ((e stp:document) (f stp:document))
710 (parent-node-= e f))
712 (defmethod node= ((a stp:attribute) (b stp:attribute))
713 (and (named-node-= a b)
714 (equal (stp:value a) (stp:value b))))
716 (defmethod node= ((a stp:comment) (b stp:comment))
717 (equal (stp:data a) (stp:data b)))
719 (defmethod node= ((a stp:text) (b stp:text))
720 (equal (stp:data a) (stp:data b)))
722 (defmethod node= ((a stp:processing-instruction)
723 (b stp:processing-instruction))
724 (and (equal (stp:data a) (stp:data b))
725 (equal (stp:target a) (stp:target b))))
727 (defmethod node= ((a stp:document-type) (b stp:document-type))
728 (and (equal (stp:root-element-name a) (stp:root-element-name b))
729 (equal (stp:public-id a) (stp:public-id b))
730 (equal (stp:system-id a) (stp:system-id b))
731 (equal (stp:internal-subset a) (stp:internal-subset b))))
733 (xpath::define-xpath-function/eager
734 :print
735 (thing)
736 (if (xpath:node-set-p thing)
737 (loop
738 initially (format t ";;; node set:~%")
739 for i from 0
740 for node in (xpath:all-nodes thing)
742 (format t ";;; ~D: ~A~%" i (type-of node)))
743 (format t ";;; ~A~%" thing))
744 thing)