(defpackage #:topic-maps.include.tests (:use #:cl #:topic-maps.tmdm) (:import-from #:topic-maps.ctm.tests #:check #:cxtm #:binary-file) (:import-from #:topic-maps.variant.tests #:condition-from) (:import-from #:topic-maps.mergemap.tests #:ascii #:resources #:original-resources #:local #:si #:valid #:observe #:call-with-import-observer) (:export #:run-tests #:include-checks #:write-include-report)) (in-package #:topic-maps.include.tests) (defparameter *doc* "https://example.invalid/maps/main.ctm") (defparameter *child* "https://example.invalid/maps/child.ctm") (defparameter *originals* '("include" "include-prefix" "include-prefix2" "include-template" "include-template-wildcard" "include-tm-reifier" "include-topicref" "include-wildcard" "include-wildcard2")) (defvar *last-checks* nil) (defvar *observations* nil) (defvar *rejections* nil) (defun include-checks () *last-checks*) (defun read-map (text &rest keys) (apply #'topic-maps.ctm:deserialize-string text :document-iri *doc* :source-name "memory:main" keys)) (defun with-child (child parent &rest keys) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii child) "memory:child"))) (declare (ignore calls)) (apply #'read-map parent :resource-resolver resolver keys))) (defun ids= (topic expected) (and topic (equal (sort (item-identifiers topic) #'string<) (sort (copy-list expected) #'string<)))) (defun rejected (label text class code &rest keys) (let ((c (condition-from (lambda () (apply #'read-map text keys))))) (check (concatenate 'string "include:" label ":specific-condition") (and (eq class (type-of c)) (eq code (topic-maps.ctm:error-code c)))) (check (concatenate 'string "include:" label ":source-position") (and (integerp (topic-maps.ctm:error-position c)) (>= (topic-maps.ctm:error-position c) 0))) c)) (defun alias-tests () (let* ((map (with-child "topic ; =; occ: \"child.ctm#payload\"^^." "before. %include topic - \"After\".")) (owner (local map (concatenate 'string *doc* "#topic"))) (occ (first (topic-occurrences owner)))) (check "alias:local-Topic-two-IIs-and-caller-reference-EQ" (and (ids= owner (list (concatenate 'string *doc* "#topic") (concatenate 'string *child* "#topic"))) (eq owner (si map "urn:subject")) (= 1 (length (topic-names owner))) (valid map))) (check "alias:SI-SL-Occurrence-value-and-datatype-unchanged" (and (equal '("urn:subject") (topic-subject-identifiers owner)) (equal '("urn:located") (topic-subject-locators owner)) (string= "child.ctm#payload" (occurrence-value occ)) (string= "urn:datatype" (occurrence-datatype occ)) (eq owner (occurrence-parent occ)) (ids= (occurrence-type occ) (list (concatenate 'string *doc* "#occ") (concatenate 'string *child* "#occ")))))) (let ((map (with-child "^. ^. ^." "%include "))) (check "alias:literal-prefix-no-fragment-boundary-assumption" (ids= (local map "https://example.invalid/maps/ish#x") (list (concatenate 'string *child* "ish#x") "https://example.invalid/maps/ish#x"))) (check "alias:empty-suffix-resolves-to-parent-Document-IRI" (ids= (local map *doc*) (list *doc* *child*))) (check "alias:existing-percent-encoded-locator-is-not-decoded-again" (ids= (local map (concatenate 'string *doc* "#x%25")) (list (concatenate 'string *doc* "#x%25") (concatenate 'string *child* "#x%25"))))) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii "t.") "source:key-not-an-IRI-base"))) (let* ((map (read-map "%prefix r <./> %include r:child.ctm" :resource-resolver resolver)) (request (topic-maps.test-foundation::json-object-members (first (funcall calls))))) (check "resolver:purpose-Include-notation-NIL-resolved-IRI-and-source-key" (and (ids= (local map (concatenate 'string *doc* "#t")) (list (concatenate 'string *child* "#t") (concatenate 'string *doc* "#t"))) (= 1 (length (funcall calls))) (equal request (topic-maps.test-foundation::json-object-members (topic-maps.test-foundation::fields "resourceIRI" *child* "purpose" "INCLUDE" "fromDocumentIRI" *doc* "notation" nil "sourceKey" "source:key-not-an-IRI-base"))))))) (let ((doc "https://example.invalid/maps/xy") (child "https://example.invalid/maps/x")) (multiple-value-bind (resolver calls) (resources (list (list child (ascii "t.") "snapshot:child"))) (declare (ignore calls)) (let ((map (topic-maps.ctm:deserialize-string "%include " :document-iri doc :resource-resolver resolver))) (check "alias:single-snapshot-pass-even-when-new-alias-matches-child-prefix" (ids= (local map (concatenate 'string doc "#t")) (list (concatenate 'string child "#t") (concatenate 'string doc "#t"))))))) (let ((seen nil)) (call-with-import-observer (lambda (saved target source) (setf seen (and (local target (concatenate 'string *doc* "#before")) (null (local target (concatenate 'string *doc* "#after"))))) (funcall saved target source)) (lambda () (with-child "t." "before. %include after."))) (check "include:immediate-processing-before-caller-continuation" seen))) (defun wildcard-tests () (multiple-value-bind (map counter) (with-child "?x. ?x. ?." "?x. %include ?x. ?. %include ?." :wildcard-iri "urn:root-wild" :wildcard-counter 7) (check "wildcard:counter-passed-returned-and-parent-cache-preserved" (and (= counter 14) (= 7 (length (topic-map-topics map))) (valid map))) (dolist (id (list "urn:root-wild#$__8.x" (concatenate 'string *doc* "#$__9.x") (concatenate 'string *doc* "#$__10") "urn:root-wild#$__11" (concatenate 'string *doc* "#$__12.x") (concatenate 'string *doc* "#$__13") "urn:root-wild#$__14")) (check (concatenate 'string "wildcard:exact-distinct-identity:" id) (ids= (local map id) (list id))))) (let ((child "def f($x) $x occ: \"V\". ?body - \"B\". ?body. end")) (multiple-value-bind (map counter) (with-child child "%include f(?argument) f(?argument) f([-\"Embedded\"])" :wildcard-counter 10) (let ((argument (local map (concatenate 'string *doc* "#$__11.argument"))) (embedded (local map (concatenate 'string *doc* "#$__14")))) (check "wildcard:Template-local-names-and-once-evaluated-arguments" (and (= counter 15) (local map (concatenate 'string *doc* "#$__12.body")) (local map (concatenate 'string *doc* "#$__13.body")) (local map (concatenate 'string *doc* "#$__15.body")) (= 1 (length (topic-occurrences argument))) (eq argument (occurrence-parent (first (topic-occurrences argument)))) (string= "Embedded" (topic-name-value (first (topic-names embedded)))) (eq embedded (occurrence-parent (first (topic-occurrences embedded)))) (valid map))))))) (defun template-tests () (let* ((child (format nil "%prefix p ~%def f($x)~% $x p:type: \"V\".~%end~%f(child)")) (parent (format nil "%prefix p ~%%include ~%f(owner)"))) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii child) "definition:child"))) (declare (ignore calls)) (multiple-value-bind (map counter parser) (topic-maps.ctm::deserialize-context parent :document-iri *doc* :source-name "invocation:main" :resource-resolver resolver) (let* ((definition (gethash '("f" 1) (topic-maps.ctm::parser-templates parser))) (body (first (topic-maps.ctm::template-definition-body definition))) (token (first (topic-maps.ctm::ctm-statement-tokens body))) (owner (local map (concatenate 'string *doc* "#owner")))) (check "template:source-text-Document-IRI-and-original-token-range-preserved" (and (= counter 0) (string= child (topic-maps.ctm::template-definition-source-text definition)) (string= "definition:child" (topic-maps.ctm::template-definition-source-name definition)) (string= *child* (topic-maps.ctm::template-definition-document-iri definition)) (= (search "def f" child) (topic-maps.ctm::template-definition-position definition)) (= (search "$x p:type" child) (topic-maps.ctm::token-position token)))) (check "template:caller-Prefix-bindings-and-Document-IRI-not-definition-closure" (and owner (eq (si map "urn:caller:type") (occurrence-type (first (topic-occurrences owner)))) (si map "urn:child:type") (local map (concatenate 'string *doc* "#child")) (not (local map (concatenate 'string *child* "#owner"))) (valid map))))))) (let* ((child "def outer($x) inner($x) end") (parent (format nil "%include ~%def inner($t)~% $t - \"N\".~%end~%outer(owner)")) (map (with-child child parent))) (check "template:forward-lookup-at-Invocation-and-nested-imported-execution" (string= "N" (topic-name-value (first (topic-names (local map (concatenate 'string *doc* "#owner")))))))) (let ((map (with-child "def f() end def f($x) $x. end" "%include f() f(owner) f."))) (check "template:overloads-and-independent-Topic-namespace" (and (= 2 (length (topic-map-topics map))) (valid map)))) (let* ((child (format nil "~%def f($x)~% $x missing:type: \"V\".~%end")) (parent (format nil "%include ~%f(owner)"))) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii child) "definition:child"))) (declare (ignore calls)) (let* ((c (rejected "template:body-error-source" parent 'topic-maps.ctm:undefined-prefix :undefined-prefix :resource-resolver resolver)) (frame (first (topic-maps.ctm:error-context c)))) (check "template:body-error-original-source-position-and-Invocation-frame" (and (string= "definition:child" (topic-maps.ctm:error-source c)) (= (search "missing:type" child) (topic-maps.ctm:error-position c)) (= 3 (topic-maps.ctm:error-line c)) (string= "definition:child" (getf frame :definition-source)) (string= *child* (getf frame :definition-document-iri)) (string= "memory:main" (getf frame :invocation-source)) (string= *doc* (getf frame :invocation-document-iri)) (= (search "f(owner)" parent) (getf frame :invocation-position))))))) (let* ((child (format nil "~%def outer($x)~% inner($x)~%end")) (parent (format nil "%include ~%def inner($t)~% $t - \"N\".~%end~%outer(42)"))) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii child) "definition:outer"))) (declare (ignore calls)) (let* ((c (rejected "template:nested-body-error" parent 'topic-maps.ctm:invalid-template-argument :invalid-template-argument :resource-resolver resolver)) (frames (topic-maps.ctm:error-context c))) (check "template:nested-source-chain-and-restored-parent-definition-source" (and (= 2 (length frames)) (string= "memory:main" (topic-maps.ctm:error-source c)) (= (search "$t -" parent) (topic-maps.ctm:error-position c)) (string= "memory:main" (getf (first frames) :definition-source)) (string= "definition:outer" (getf (first frames) :invocation-source)) (= (search "inner($x)" child) (getf (first frames) :invocation-position)) (string= "definition:outer" (getf (second frames) :definition-source)) (= (search "outer(42)" parent) (getf (second frames) :invocation-position))))))) (let* ((grand "https://example.invalid/maps/grand.ctm") (text "%include f(owner)")) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii "%include ") "source:middle") (list grand (ascii "def f($x) $x type: \"V\". end") "source:grand"))) (multiple-value-bind (map counter parser) (topic-maps.ctm::deserialize-context text :document-iri *doc* :source-name "source:root" :resource-resolver resolver) (let* ((definition (gethash '("f" 1) (topic-maps.ctm::parser-templates parser))) (owner (local map (concatenate 'string *doc* "#owner")))) (check "template:nested-transport-preserves-original-source-and-caller-identity" (and (= counter 0) (= 2 (length (funcall calls))) (string= grand (topic-maps.ctm::template-definition-document-iri definition)) (string= "source:grand" (topic-maps.ctm::template-definition-source-name definition)) (ids= (occurrence-type (first (topic-occurrences owner))) (list (concatenate 'string *doc* "#type"))) (valid map))))))) (check "API:public-deserialization-still-returns-exactly-two-values" (= 2 (length (multiple-value-list (read-map "def unused() t. end")))))) (defun model-tests () (let* ((body "owner ; - type: \"N\" @theme ~ (\"V\" @extra ~); type: \"O\" @theme ~. assoc(role: owner ~) @theme ~") (child (concatenate 'string "~ child-map " body)) (old-topic nil) (old-name nil) (old-variant nil) (old-occ nil) (old-a nil) (old-r nil)) (let ((map (call-with-import-observer (lambda (saved target source) (setf old-topic (si target "urn:owner") old-name (first (topic-names old-topic)) old-variant (first (topic-name-variants old-name)) old-occ (first (topic-occurrences old-topic)) old-a (first (topic-map-associations target)) old-r (first (association-roles old-a))) (add-item-identifier source "urn:source-map-only") (loop for item in (rest (topic-maps.import.tests::handles source)) for i from 1 when (topic-maps.tmdm::reifiable-p item) do (add-item-identifier item (format nil "urn:metadata:~D" i))) (let* ((held (topic-maps.import.tests::handles source)) (state (topic-maps.import.tests::state source held))) (multiple-value-bind (result resolve) (funcall saved target source) (check "model:source-preserving-real-import-and-root-Identifiers-excluded" (and (equal state (topic-maps.import.tests::state source held)) (null (item-identifiers result)) (every (lambda (item) (subsetp (item-identifiers item) (item-identifiers (funcall resolve item)) :test #'string=)) (rest held)))) (values result resolve)))) (lambda () (with-child child (format nil "~A %include " body)))))) (let* ((owner (si map "urn:owner")) (name (first (topic-names owner))) (variant (first (topic-name-variants name))) (occ (first (topic-occurrences owner))) (a (first (topic-map-associations map))) (r (first (association-roles a)))) (check "model:alias-driven-merge-retains-all-six-canonical-handles" (and (not (eq old-topic owner)) (eq owner (canonical-topic old-topic)) (eq name (canonical-topic-name old-name)) (eq variant (canonical-variant old-variant)) (eq occ (canonical-occurrence old-occ)) (eq a (canonical-association old-a)) (eq r (canonical-association-role old-r)))) (check "model:Parent-Type-Scope-Player-and-Reifier-references-EQ" (and (= 1 (length (topic-names owner))) (= 1 (length (topic-occurrences owner))) (= 1 (length (topic-map-associations map))) (eq owner (topic-name-parent name)) (eq name (variant-parent variant)) (eq owner (occurrence-parent occ)) (eq (local map (concatenate 'string *doc* "#type")) (topic-name-type name)) (eq (topic-name-type name) (occurrence-type occ)) (eq (local map (concatenate 'string *doc* "#theme")) (first (topic-name-scope name))) (eq owner (association-role-player r)) (eq a (association-role-parent r)) (every (lambda (item) (eq item (topic-reified (item-reifier item)))) (list name variant occ a r)) (null (topic-reified (local map (concatenate 'string *doc* "#child-map")))) (valid map)))) (let* ((held (topic-maps.import.tests::handles map)) (state (topic-maps.import.tests::state map held))) (check "model:CXTM-deterministic-and-mutation-free-for-retained-handles" (and (string= (cxtm map) (cxtm map)) (equal state (topic-maps.import.tests::state map held)))))))) (defun atomic-tests () (dolist (collision '(nil t)) (let* ((text (if collision "def f() before. end %include " "%include ")) (parser (topic-maps.ctm::make-parser (topic-maps.ctm::make-lexer text) *doc* "urn:w" 9)) (map (topic-maps.ctm:deserialize-string "a ; ^." :document-iri *doc*)) (child (if collision "def f() x. end ?." "def added() x. end ?. b ; ^."))) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii child) "atomic:child"))) (declare (ignore calls)) (setf (topic-maps.ctm::parser-resource-resolver parser) resolver) (let ((topic-maps.ctm::*source-name* "memory:main") (topic-maps.ctm::*source-text* text)) (when collision (topic-maps.ctm::read-template-definition parser)) (let* ((held (topic-maps.import.tests::handles map)) (before (topic-maps.import.tests::state map held)) (registry (hash-table-count (topic-maps.ctm::parser-templates parser))) (c (condition-from (lambda () (topic-maps.ctm::read-directive parser map))))) (check (format nil "atomic:~A:Map-Counter-and-Template-registry-unchanged" collision) (and (eq (if collision :duplicate-template :core-subject-conflict) (topic-maps.ctm:error-code c)) (equal before (topic-maps.import.tests::state map held)) (= 9 (topic-maps.ctm::parser-wildcard-counter parser)) (= registry (hash-table-count (topic-maps.ctm::parser-templates parser))))))))))) (defun diagnostic-tests () (rejected "diagnostic:missing-resource" "%include" 'topic-maps.ctm:ctm-rejection :expected-include-resource) (rejected "diagnostic:no-implicit-access" "%include " 'topic-maps.ctm:ctm-unsupported :resource-resolver-required) (rejected "diagnostic:resolver-declined" "%include " 'topic-maps.ctm:ctm-resource-error :resource-unavailable :resource-resolver (lambda (&rest args) (declare (ignore args)) nil)) (rejected "diagnostic:resolver-error" "%include " 'topic-maps.ctm:ctm-resource-error :resource-resolver-failure :resource-resolver (lambda (&rest args) (declare (ignore args)) (error "denied"))) (dolist (bad '("text" #(256))) (rejected (format nil "diagnostic:invalid-bytes:~S" bad) "%include " 'topic-maps.ctm:ctm-resource-error :invalid-resource-result :resource-resolver (lambda (&rest args) (declare (ignore args)) bad))) (dolist (fixture '((#(255) :invalid-utf8) (#(97) :missing-period))) (let ((c (rejected (format nil "diagnostic:child:~S" (second fixture)) "%include " 'topic-maps.ctm:ctm-rejection (second fixture) :resource-resolver (lambda (&rest args) (declare (ignore args)) (values (first fixture) "bad:child"))))) (check (format nil "diagnostic:child:~S:correct-source" (second fixture)) (string= "bad:child" (topic-maps.ctm:error-source c))))) (multiple-value-bind (resolver calls) (resources (list (list *child* (ascii "%include ") "cycle:child"))) (let ((c (rejected "diagnostic:active-cycle" "%include " 'topic-maps.ctm:ctm-unsupported :cyclic-include :resource-resolver resolver))) (check "diagnostic:cycle-context-and-no-second-fetch" (and (= 1 (length (funcall calls))) (= 2 (length (topic-maps.ctm:error-context c))))))) (multiple-value-bind (resolver calls) (resources nil) (rejected "diagnostic:depth-limit" "%include " 'topic-maps.ctm:ctm-unsupported :resource-depth-limit :resource-resolver resolver :max-resource-depth 0) (check "diagnostic:depth-limit-no-fetch" (null (funcall calls)))) (let* ((bytes (concatenate '(vector (unsigned-byte 8)) #(239 187 191) (ascii "t - \"") #(195 169) (ascii "\"."))) (before (copy-seq bytes))) (multiple-value-bind (resolver calls) (resources (list (list *child* bytes "BOM:child"))) (declare (ignore calls)) (let ((map (read-map "%include " :resource-resolver resolver))) (check "include:strict-UTF8-BOM-and-Unicode-without-byte-mutation" (and (equalp before bytes) (string= "é" (topic-name-value (first (topic-names (local map (concatenate 'string *doc* "#t")))))))))))) (defun call-with-context-observer (observer thunk) (let ((saved (symbol-function 'topic-maps.ctm::deserialize-context))) (unwind-protect (progn (setf (symbol-function 'topic-maps.ctm::deserialize-context) (lambda (text &rest keys) (multiple-value-bind (map counter parser) (apply saved text keys) (funcall observer keys map counter parser) (values map counter parser)))) (funcall thunk)) (setf (symbol-function 'topic-maps.ctm::deserialize-context) saved)))) (defun call-with-alias-observer (observer thunk) (let ((saved (symbol-function 'topic-maps.ctm::add-include-aliases))) (unwind-protect (progn (setf (symbol-function 'topic-maps.ctm::add-include-aliases) (lambda (map child parent position) (let ((before (observe map))) (funcall saved map child parent position) (funcall observer child parent before (observe map)) map))) (funcall thunk)) (setf (symbol-function 'topic-maps.ctm::add-include-aliases) saved)))) (defun discrepancy (file) (cond ((string= file "include-template") "Known normative discrepancy: CTM 3.14 / 3.15 / 3.16.2; declaration creates no Topics, imported body executes in caller context, no later definition-source alias rule. Baseline adds include-template.sub#occtype.") ((string= file "include-wildcard2") "Known normative discrepancy: CTM 3.16.2; immediate-parent Document IRI initializes child Wildcard IRI and each Include level retains original identifiers. Baseline omits include-wildcard2.sub#$__1.foo."))) (defun original-cases () (setf *observations* nil *rejections* nil) (dolist (file *originals*) (let* ((id (format nil "ctm/in/~A.ctm" file)) (case (first (topic-maps.test-foundation:select-cases topic-maps.ctm.tests::*cxtm-corpus* :id id))) (doc (topic-maps.test-foundation:test-case-document-iri case)) (environments nil) (transfers nil)) (multiple-value-bind (resolver calls) (original-resources) (multiple-value-bind (map counter) (call-with-context-observer (lambda (keys map counter parser) (push (topic-maps.test-foundation::fields "documentIRI" (getf keys :document-iri) "wildcardIRI" (getf keys :wildcard-iri (getf keys :document-iri)) "initialCounter" (getf keys :wildcard-counter 0) "finalCounter" counter "templateCount" (hash-table-count (topic-maps.ctm::parser-templates parser)) "model" (observe map)) environments)) (lambda () (call-with-alias-observer (lambda (child parent before after) (push (topic-maps.test-foundation::fields "childDocumentIRI" child "parentDocumentIRI" parent "before" before "after" after) transfers)) (lambda () (topic-maps.ctm:deserialize-file (topic-maps.test-foundation:test-case-source-pathname case) :document-iri doc :source-name id :resource-resolver resolver))))) (let* ((held (topic-maps.import.tests::handles map)) (state (topic-maps.import.tests::state map held)) (actual (topic-maps.cxtm:canonicalize-octets map :base-locator doc)) (expected (binary-file (topic-maps.test-foundation:test-case-expected-baseline case))) (match (equalp actual expected))) (check (concatenate 'string id ":model-and-references") (valid map)) (check (concatenate 'string id ":actual-original-comparison") (eq match (null (discrepancy file)))) (check (concatenate 'string id ":deterministic-and-pure") (and (equalp actual (topic-maps.cxtm:canonicalize-octets map :base-locator doc)) (equal state (topic-maps.import.tests::state map held)))) (when (string= file "include-template") (let* ((owner (local map (concatenate 'string doc "#topic"))) (occ (first (topic-occurrences owner)))) (check "original:template-no-eager-Topic-or-future-definition-alias" (and (= 2 (length (topic-map-topics map))) (= counter 0) (eq owner (occurrence-parent occ)) (ids= (occurrence-type occ) (list (concatenate 'string doc "#occtype"))) (string= "Test" (occurrence-value occ)) (string= (string-datatype) (occurrence-datatype occ)))))) (when (string= file "include-wildcard2") (let* ((b (topic-maps.ctm::resolve-iri "include-wildcard2.sub" doc 0)) (owner (local map (concatenate 'string doc "#$__1.foo")))); original B II must remain (check "original:nested-Wildcard-counter-and-both-retained-identifiers" (and (= counter 3) (= 4 (length (topic-map-topics map))) (ids= owner (list (concatenate 'string doc "#$__1.foo") (concatenate 'string b "#$__1.foo"))) (string= "Sub Sub" (topic-name-value (first (topic-names owner)))) (local map (concatenate 'string doc "#$__2.foo")) (local map (concatenate 'string doc "#$__3.foo")))))) (topic-maps.test-foundation:record-result case (if match :cxtm-match :cxtm-mismatch) :diagnostics (when (not match) (list (discrepancy file) (format nil "First different byte ~D; actual ~D bytes, expected ~D bytes." (mismatch actual expected) (length actual) (length expected))))) (setf (topic-maps.test-foundation:test-case-clauses case) '("CTM 3.2" "CTM 3.3.6" "CTM 3.3.8" "CTM 3.14" "CTM 3.15" "CTM 3.16.2" "TMDM 5-6" "CXTM 3.13" "CXTM 3.18")) (setf topic-maps.ctm.tests::*cxtm-results* (append topic-maps.ctm.tests::*cxtm-results* (list (list :id id :base doc :actual (cxtm map doc) :expected (uiop:read-file-string (topic-maps.test-foundation:test-case-expected-baseline case)) :match match :bytes (length actual))))) (push (topic-maps.test-foundation::fields "id" id "documentIRI" doc "ctmSource" (uiop:read-file-string (topic-maps.test-foundation:test-case-source-pathname case)) "requests" (topic-maps.test-foundation::json-array (funcall calls)) "counter" counter "model" (observe map) "environments" (topic-maps.test-foundation::json-array (reverse environments)) "aliasTransfers" (topic-maps.test-foundation::json-array (reverse transfers)) "byteCount" (length actual) "expectedByteCount" (length expected) "baselineMatch" (if match :true :false) "discrepancy" (discrepancy file)) *observations*) (format t "~&INCLUDE-CXTM ~A: ~A (~D/~D bytes)~%" id (if match :PASS :FAIL) (length actual) (length expected))))))) (dolist (fixture '(("include-prefix" topic-maps.ctm:undefined-prefix :undefined-prefix "ctm/invalid/include-prefix.ctm") ("include-prefix2" topic-maps.ctm:undefined-prefix :undefined-prefix "ctm/invalid/include-prefix2.sub") ("include-xtm" topic-maps.ctm:ctm-rejection :invalid-iri "ctm/invalid/include-xtm.sub"))) (destructuring-bind (file class code source) fixture (let* ((id (format nil "ctm/invalid/~A.ctm" file)) (case (first (topic-maps.test-foundation:select-cases topic-maps.ctm.tests::*cxtm-corpus* :id id)))) (multiple-value-bind (resolver calls) (original-resources) (let ((c (condition-from (lambda () (topic-maps.ctm:deserialize-file (topic-maps.test-foundation:test-case-source-pathname case) :document-iri (topic-maps.test-foundation:test-case-document-iri case) :source-name id :resource-resolver resolver))))) (check (concatenate 'string id ":intended-rejection-source-and-request") (and (eq class (type-of c)) (eq code (topic-maps.ctm:error-code c)) (string= source (topic-maps.ctm:error-source c)) (= 1 (length (funcall calls))))) (topic-maps.test-foundation:record-result case :ctm-rejection :diagnostics (list (princ-to-string c))) (setf (topic-maps.test-foundation:test-case-clauses case) '("CTM 3.16.2" "CTM 3.3.4")) (push (topic-maps.test-foundation::fields "id" id "class" (symbol-name class) "code" (symbol-name code) "source" (topic-maps.ctm:error-source c) "position" (topic-maps.ctm:error-position c) "line" (topic-maps.ctm:error-line c) "column" (topic-maps.ctm:error-column c) "requests" (topic-maps.test-foundation::json-array (funcall calls))) *rejections*) (format t "~&INCLUDE-REJECTION ~A: PASS (~A)~%" id code)))))) (setf *observations* (nreverse *observations*) *rejections* (nreverse *rejections*))) (defun run-tests () (topic-maps.mergemap.tests:run-tests) (let ((topic-maps.ctm.tests::*checks* nil)) (alias-tests) (wildcard-tests) (template-tests) (model-tests) (atomic-tests) (diagnostic-tests) (original-cases) (check "include:twelve-contracts-only-ten-PASS-two-actual-FAIL" (equal '(:pass 204 :fail 4 :unsupported 0 :not-run 65) (getf (topic-maps.test-foundation:summarize-corpus topic-maps.ctm.tests::*cxtm-corpus*) :statuses))) (setf *last-checks* (nreverse topic-maps.ctm.tests::*checks*)) (format t "~&INCLUDE-PASS: ~D checks; seven byte-exact originals, three rejections, two explicit baseline FAILs.~%" (length *last-checks*)) t)) (defun write-include-report (path) (with-open-file (out path :direction :output :if-exists :supersede :if-does-not-exist :create) (topic-maps.test-foundation::emit-json-value (topic-maps.test-foundation::fields "kind" "ctm-include-execution-evidence" "passed" (length *last-checks*) "failed" 0 "checks" (topic-maps.test-foundation::json-array *last-checks*) "cases" (topic-maps.test-foundation::json-array *observations*) "rejections" (topic-maps.test-foundation::json-array *rejections*)) out) (terpri out)))