AtlatestRepositorysigil-ui
1
;;; WINDOW FONT C_COMPILER FRESH_OUTPUT — Linux argument-parser controls only.2
(import (sigil shell prelude) (sigil list))3
(requires (tools sigil))4
(define root (realpath (path (script-dir) "../..")))5
(define window (realpath (arg 1)))6
(define font (realpath (arg 2)))7
(define compiler (realpath (arg 3)))8
(define output (arg 4))9
(define cli (or (getenv "SIGIL") (tool-path 'sigil)))10
(unless (and (starts-with? output "/") (not (file-exists? output)))11
(error "Supply a fresh absolute parser-control output directory"))12
(load (path root "test/macos/fixture-arguments.sgl"))13
(ensure-directory output)14
(define run (path output "run with spaces"))15
(define resources (path output "owned resources"))16
(define checks 0)17
(define (check name executable arguments expected)18
(define result ($? ,executable ,@arguments timeout: 15))19
(write-text (path output (str name ".log"))20
(str "Linux argument parser only; native/font/UI operations are not executed.\n"21
(stdout-of result) (stderr-of result) "\n" (format-outcome result) "\n"))22
(unless (equal? expected (exit-status result))23
(error "Argument parser control failed" name (format-outcome result)))24
(set! checks (+ checks 1))25
(println "PASS: ~a" name))27
;;; Compile the real first C main guard, substituting only probe_begin. Refuse28
;;; unfamiliar syntax so a changed entrypoint cannot silently escape coverage.29
(each entry '(("host-aarch64" "test/appkit/host.c")30
("webkit-aarch64" "test/appkit/webkit.c")31
("initialization-aarch64" "test/appkit/initialization.c"))32
(define name (car entry))33
(define source (read-text (path window (cadr entry))))34
(define guard-match35
(regex-search "int main\\(int argc, char \\*\\*argv\\) \\{\\s*(if \\(argc != 2 \\|\\| !probe_begin\\(argv\\[1\\]\\)\\) return 2;)" source))36
(unless guard-match (error "Unrecognized native argument parser" name))37
(define c-file (path output (str name ".c")))38
(define executable (path output name))39
(write-text c-file40
(str "#include <stdbool.h>\n#include <string.h>\n"41
"static bool probe_begin(const char *directory) { return strcmp(directory, "42
(format "~s" run) ") == 0; }\nint main(int argc, char **argv) {\n"43
(match-group guard-match 1) "\nreturn 0;\n}\n"))44
($ ,compiler -std=c11 -Wall -Wextra -Werror ,c-file -o ,executable timeout: 30)45
(check (str name "-exact-argv") executable (fixture-arguments name run resources) 0)46
(check (str name "-missing-run") executable '() 2)47
(check (str name "-old-two-arguments") executable (list run resources) 2))49
;;; Read actual Sigil main forms. Execute only its argument admission prefix,50
;;; with a lexical command-line binding and a side-effect-free begin probe.51
(each entry52
(list (list "appkit-conformance" (path window "test/appkit/conformance/src/conformance/main.sgl"))53
(list "font-aarch64" (path font "test/coretext-host/src/sigil/font/tests/coretext.sgl"))54
(list "ui-drawing-aarch64" (path root "test/macos-drawing/src/drawing/main.sgl")))55
(define name (car entry))56
(define library (call-with-input-file (cadr entry) read))57
(define body (find (lambda (form) (and (pair? form) (eq? (car form) 'begin))) (cddr library)))58
(unless body (error "Missing fixture library body" name))59
(define main-form60
(find (lambda (form) (and (pair? form) (eq? (car form) 'define)61
(equal? (cadr form) '(main)))) (cdr body)))62
(unless main-form (error "Missing fixture main" name))63
(define admission64
(if (equal? name "appkit-conformance")65
(list (caddr main-form))66
(list (caddr main-form) (cadddr main-form))))67
(unless (if (equal? name "appkit-conformance")68
(and (eq? (caar admission) 'let) (= (length (car admission)) 3)69
(eq? (car (caddr (car admission))) 'unless))70
(and (equal? (car admission) '(define args (cdr (command-line))))71
(eq? (car (cadr admission)) 'unless)))72
(error "Unrecognized Sigil argument admission prefix" name))73
(define parser (path output (str name ".sgl")))74
(write-text parser75
(str "(import (sigil shell prelude))\n(define argument-probe-began #f)\n"76
"(define (parser-begin directory)\n (set! argument-probe-began #t)\n (equal? directory "77
(format "~s" run) "))\n"78
"(let ((command-line (lambda () (cons \"fixture\" (script-args)))))\n"79
" (let ((probe-begin! parser-begin) (%fixture-begin! parser-begin))\n"80
(string-join (map (lambda (form) (format "~s" form)) admission) "\n")81
"\n (unless argument-probe-began (error \"Parser did not call begin\"))))\n"))82
(define arguments (fixture-arguments name run resources))83
(check (str name "-exact-argv") cli (cons parser arguments) 0)84
(check (str name "-missing-run") cli (list parser) 2)85
(unless (equal? name "appkit-conformance")86
(check (str name "-missing-resources") cli (list parser run) 2)87
(check (str name "-extra-argument") cli (append (list parser) arguments '("extra")) 2)))88
(println "PASS: ~a actual-parser controls; all six fixtures use the launcher's shared argv builder" checks)