AtlatestRepositorysigil-ui

sigil-ui / tree / scriptstest-window-services.sgl

1#!/usr/bin/env sigil
2;;; Host request state controls; no display, clipboard, drawing, or toolchain dependency.
3(import (sigil shell prelude))
4(define root (realpath (path (script-dir) "..")))
5(define work (or (getenv "SIGIL_UI_TEST_ROOT") (path root "build/window-services")))
6(define compiler (or (getenv "CC") "cc"))
7(ensure-directory work)
8(define binary (path work "window-services"))
9($ ,compiler -std=c11 -Wall -Wextra -Werror
10 ,(str "-I" (path root "native")) ,(path root "test/window-services.c")
11 -o ,binary timeout: 60)
12($ ,binary timeout: 10)
14;;; These controls must reject granting a mismatching reply and renewing a
15;;; pending request's deadline on every configure.
16(define header (read-text (path root "native/window-services.h")))
17(define fixture (read-text (path root "test/window-services.c")))
18(each mutation
19 '(("wrong-state-grant" "if (actual == request->requested)" "if ((void)actual, 1)")
20 ("renew-configure-deadline" "int previous = request->status;"
21 "request->deadline += SUI_FULLSCREEN_TIMEOUT_MS;\n int previous = request->status;"))
22 (let* ((name (car mutation)) (anchor (cadr mutation))
23 (directory (path work name)) (mutant (path directory "check")))
24 (unless (= (string-count header anchor) 1) (error "Request-state mutation anchor changed" name))
25 (ensure-directory directory)
26 (write-text (path directory "window-services.h") (string-replace header anchor (caddr mutation)))
27 (write-text (path directory "fixture.c") fixture)
28 ($ ,compiler -std=c11 -Wall -Wextra -Werror
29 ,(str "-I" directory) ,(path directory "fixture.c") -o ,mutant timeout: 60)
30 (let ((result ($? ,mutant out: ,(path directory "log") err: 'merge timeout: 10)))
31 (unless (and (not (ok? result)) (contains? (stdout-of result) "Assertion"))
32 (error "Request-state mutant was not rejected" name (format-outcome result)))
33 (println "PASS: rejected ~a" name))))