AtlatestRepositorysigil-doc

sigil-doc / tree / testbuild-d6-pressure.sgl

1(import (sigil core) (sigil fs) (sigil shell) (sigil doc) (sigil doc examples)
2 (sigil doc verify) (sigil doc presentation) (sigil doc publication)
3 (sigil doc print) (sigil doc render typst))
4
5(define args (script-args))
6(unless (= (length args) 1)
7 (error "usage: build-d6-pressure.sgl OUTPUT.typ"))
8
9(load "test/fixtures/d3-examples.sgd")
10(define loaded-document (eval 'document))
11(define examples (document-examples loaded-document))
12(define projects (document-project-checks loaded-document))
13(define external-cache (getenv "D6_VERIFY_CACHE"))
14(define cache-dir (or external-cache (make-temp-directory)))
15(define sigil-bin (or (getenv "SIGIL_D1_COMPILER")
16 "../task-sigil-language-readers/build/dev/bin/sigil"))
17(define (example-presentation spec)
18 (let ((result (verify-example loaded-document examples spec "test/fixtures"
19 sigil-bin cache-dir #f)))
20 (make-verified-presentation spec result (verify-result-effective-source result))))
21(define (project-presentation spec)
22 (let ((result (verify-project-check loaded-document spec "test/fixtures"
23 sigil-bin cache-dir #t)))
24 (make-verified-presentation spec result (verify-result-effective-source result))))
25(define presentations
26 (append
27 (map example-presentation
28 (filter (lambda (spec) (member (example-id spec) '("stdout" "expected-error"))) examples))
29 (map project-presentation projects)))
30(define shown-example
31 (car (filter (lambda (spec) (string=? (example-id spec) "stdout")) examples)))
32(define shown-error
33 (car (filter (lambda (spec) (string=? (example-id spec) "expected-error")) examples)))
34(define shown-project (car projects))
35(define pressure-document
36 (make-document 'chapter "Verified print results" '("D6 gate")
37 (list shown-example shown-error shown-project) (document-location loaded-document)))
38(define print-value
39 (make-print-publication "sigil-doc Print Pressure" #f '("D6 gate")
40 (list (make-publication-document "pressure" pressure-document)) presentations))
42;; A presentation is permanently bound to the exact verified specification,
43;; not merely to a target id. All three stale same-id variants must fail
44;; before Typst source emission.
45(define (must-reject label spec presentation)
46 (unless
47 (guard (_ (else #t))
48 (make-print-publication label #f '()
49 (list (make-publication-document "stale"
50 (make-document 'chapter label '() (list spec) (node-location spec))))
51 (list presentation))
52 #f)
53 (error (string-append "D6 stale specification accepted: " label))))
54(define stdout-presentation
55 (car (filter (lambda (p) (string=? (verified-presentation-id p) "stdout")) presentations)))
56(define project-presentation-value
57 (car (filter (lambda (p) (string=? (verified-presentation-id p) "d3-project")) presentations)))
58(unless (verified-presentation-matches-spec? stdout-presentation shown-example)
59 (error "D6 current presentation no longer matches its specification"))
60(must-reject "changed source"
61 (make-example "stdout" 'inline "(display \"changed\\n\")" "sigil" #f 'bytecode
62 'stdout "hello\n" "" 30 'source+expected (example-location shown-example))
63 stdout-presentation)
64(must-reject "changed expectation"
65 (make-example "stdout" 'inline "(display \"hello\\n\")" "sigil" #f 'bytecode
66 'stdout "changed\n" "" 30 'source+expected (example-location shown-example))
67 stdout-presentation)
68(must-reject "changed project"
69 (make-project-check "d3-project" (project-check-root shown-project)
70 (project-check-files shown-project) (project-check-config shown-project)
71 (project-check-target shown-project) "changed\n" (project-check-timeout shown-project)
72 (project-check-location shown-project))
73 project-presentation-value)
74(write-file-string (car args) (print-publication->typst print-value))
75(unless external-cache (delete-directory cache-dir))