AtlatestRepositorysigil
sigil / tree / test / integrationtest-native-uncaught-error.sgl
1
#!/usr/bin/env sigil2
;;; Demonstration port of test-native-uncaught-error.sh.3
;;; This is a library test, not a release gate. The Bash sibling remains4
;;; authoritative until a release containing (sigil shell) has shipped.6
(import (sigil fs)7
(sigil path)8
(sigil process)9
(sigil shell)10
(sigil shell checks)11
(sigil string))13
(requires (tools file))15
(define repo-root16
(realpath (path-dirname (path-dirname (script-dir)))))17
(define sigil-bin18
(or (getenv "SIGIL") (path-join repo-root "build/dev/bin/sigil")))19
(define app-dir20
(path-join (script-dir) "apps/native-uncaught-probe"))21
(define bin22
(path-join app-dir "build/release/bin/native-uncaught-probe"))23
(define with-zig (path-join repo-root "scripts/with-zig"))24
(define probe-outcome #f)25
(define probe-output "")27
(define (delete-tree path)28
(when (file-exists? path)29
(if (directory? path)30
(begin31
(for-each32
(lambda (entry) (delete-tree (path-join path entry)))33
(directory-list path))34
(delete-directory path))35
(delete-file path))))37
(check "SGLSH-S19-native-probe-builds"38
(unless (and (file? sigil-bin) (command-exists? sigil-bin))39
(error (format "sigil binary is missing or not executable: ~a" sigil-bin)))40
(delete-tree (path-join app-dir "build"))41
(if (and (file? with-zig) (command-exists? with-zig))42
($ ,with-zig ,sigil-bin build --config release cwd: ,app-dir)43
($ ,sigil-bin build --config release cwd: ,app-dir))44
(unless (and (file? bin) (command-exists? bin))45
(error (format "native binary was not produced: ~a" bin))))47
(check "SGLSH-S19-native-probe-is-ELF"48
(unless (string-contains? (out file ,bin) "ELF")49
(error (format "native probe is not an ELF binary: ~a" bin))))51
(check "SGLSH-S19-native-uncaught-error-is-a-considered-failure"52
(set! probe-outcome ($? ,bin err: 'merge timeout: 30))53
(set! probe-output (stdout-of probe-outcome))54
(display probe-output)55
(unless (failed? probe-outcome)56
(error (format "probe did not exit with a considered failure: ~a"57
(format-outcome probe-outcome)))))59
(check "SGLSH-S19-native-code-before-raise-ran"60
(unless (string-contains? probe-output "before-raise")61
(error "code before the raise did not run")))63
(check "SGLSH-S19-native-error-surfaced"64
(unless (string-contains? probe-output "uncaught-boom")65
(error "uncaught exception was swallowed")))67
(check "SGLSH-S19-native-code-after-raise-did-not-run"68
(when (string-contains? probe-output "REACHED-END")69
(error "execution continued past the uncaught raise")))71
(run-checks!)