AtlatestRepositorysigil-fontconfig

sigil-fontconfig / tree / testtest-00-isolation.sgl

1;;; Run this file alone in a fresh native process before either legacy suite.
2(import (sigil test) (sigil fontconfig) (sigil ffi) (sigil fs) (sigil string)
3 (sigil process) (sigil path))
4
5(define (register-isolation!)
6 (define inventory
7 (or (getenv "SIGIL_FONTCONFIG_TEST_DIRECTORY") (error "Select the owned font inventory")))
8 (test "fresh isolated queries never initialize the process default config"
9 (define work (or (make-temp-directory) (error "Cannot create the sentinel fixture")))
10 (define sentinel-cache (path-join work "default-cache"))
11 (define sentinel-file (path-join work "sentinel-default-config.conf"))
12 (define (xml text)
13 (string-replace (string-replace (string-replace text "&" "&amp;") "<" "&lt;") ">" "&gt;"))
14 (ensure-directory sentinel-cache)
15 (write-file-string sentinel-file
16 (string-append "<fontconfig><dir>" (xml inventory) "</dir><cachedir>"
17 (xml sentinel-cache) "</cachedir></fontconfig>"))
18 (define previous
19 (map (lambda (name) (cons name (getenv name)))
20 '("FONTCONFIG_FILE" "FONTCONFIG_PATH" "XDG_CACHE_HOME")))
21 (assert-equal '() (directory-list sentinel-cache))
22 (dynamic-wind
23 (lambda ()
24 (setenv! "FONTCONFIG_FILE" sentinel-file)
25 (setenv! "FONTCONFIG_PATH" (path-dirname sentinel-file))
26 (setenv! "XDG_CACHE_HOME" sentinel-cache))
27 (lambda ()
28 ;; FcGetVersion reports the loaded library without touching FcConfig.
29 (let* ((library (c-library "libfontconfig"))
30 (version (c-function library "FcGetVersion" '() ffi/int)))
31 (display "ISOLATION_FONTCONFIG_VERSION=") (display (version)) (newline))
32 (let ((context
33 (make-fc-context files:
34 (list (path-join inventory "JetBrainsMono-Regular.ttf")
35 (path-join inventory "JetBrainsMono-Bold.ttf")))))
36 (dynamic-wind (lambda () #f)
37 (lambda ()
38 (assert-equal "Regular" (fc-font-style
39 (fc-context-match context (fc-pattern family: "JetBrains Mono"))))
40 (assert-equal "Bold" (fc-font-style
41 (fc-context-match context (fc-pattern family: "JetBrains Mono" style: "Bold" size: 16))))
42 (assert-true (pair? (fc-context-sort context (fc-pattern family: "JetBrains Mono"))))
43 (assert-equal 2 (length (fc-context-list context))))
44 (lambda () (fc-context-close! context))))
45 (assert-equal '() (directory-list sentinel-cache))
46 ;; This must initialize the sentinel default now. If another test already
47 ;; initialized it, the new cache stays empty and this test must fail.
48 (display "ISOLATION_DEFAULT_CONTROL_BEGIN\n")
49 (let* ((library (c-library "libfontconfig"))
50 (current (c-function library "FcConfigGetCurrent" '() ffi/pointer)))
51 (assert-true (pointer? (current))))
52 (assert-true (pair? (directory-list sentinel-cache))))
53 (lambda ()
54 (for-each (lambda (entry) (setenv! (car entry) (cdr entry))) previous)
55 (let remove ((file work))
56 (if (and (directory? file) (not (symlink? file)))
57 (begin
58 (for-each (lambda (name) (remove (path-join file name))) (directory-list file))
59 (delete-directory file))
60 (delete-file file)))))))
62(if (equal? (getenv "SIGIL_FONTCONFIG_ISOLATION_FIRST") "1")
63 (register-isolation!)
64 (display "SKIP: fresh Fontconfig isolation requires scripts/ci-test.sgl\n"))