T: failing checks raise instead of exiting, so module mode keeps the session
run-steps and self-check ended with exit 1. With use dev/dev-test.nu * in a Nushell config, exit ends the caller's session and cannot be caught, so any red dev-test unit|all|ci closed the terminal right after the summary. run-steps and self-check now raise a catchable error; only the script-mode entry point (main) exits, after printing the reason. check-module-mode guards that: it rejects exit outside main, rejects (exit ...) interpolated into a message (a subexpression that ends the process; the cargo-tree message had one), catches a real failing step in module mode and requires script mode to still exit non-zero.
This commit is contained in:
1 parent
b476ac2b0c
commit
b2a4059080
1 file changed
+55
-4
+55
-4
@@ -50,6 +50,18 @@ const FILTER_CACHE = "target/skyg-test-filters.cache"
|
|||||||
# Nushell would otherwise accept `--nocapture` on every subcommand and reject
|
# Nushell would otherwise accept `--nocapture` on every subcommand and reject
|
||||||
# the rest before `main` can explain them.
|
# the rest before `main` can explain them.
|
||||||
export def --wrapped main [...args: string] {
|
export def --wrapped main [...args: string] {
|
||||||
|
# Only script mode reaches this entry point: `use ... *` binds the file stem to
|
||||||
|
# a wrapper that calls the subcommands directly. A non-zero status is still
|
||||||
|
# wanted from `nu dev/dev-test.nu <sub>`, and `exit` is acceptable here.
|
||||||
|
try {
|
||||||
|
dispatch-script-args $args
|
||||||
|
} catch {|e|
|
||||||
|
print -e $"($RUNNER): ($e.msg)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def dispatch-script-args [args: list<string>] {
|
||||||
let parsed = (parse-script-args $args)
|
let parsed = (parse-script-args $args)
|
||||||
match $parsed.cmd {
|
match $parsed.cmd {
|
||||||
"help" => { print-help }
|
"help" => { print-help }
|
||||||
@@ -143,6 +155,7 @@ export def "dev-test self-check" [] {
|
|||||||
++ (check-filter-cache)
|
++ (check-filter-cache)
|
||||||
++ (check-openssl-verdict)
|
++ (check-openssl-verdict)
|
||||||
++ (check-kvm-step)
|
++ (check-kvm-step)
|
||||||
|
++ (check-module-mode)
|
||||||
++ (check-shell-completion)
|
++ (check-shell-completion)
|
||||||
++ (check-nu-completions)
|
++ (check-nu-completions)
|
||||||
++ (check-docs)
|
++ (check-docs)
|
||||||
@@ -150,7 +163,8 @@ export def "dev-test self-check" [] {
|
|||||||
if not ($problems | is-empty) {
|
if not ($problems | is-empty) {
|
||||||
print -e "dev-test self-check failed:"
|
print -e "dev-test self-check failed:"
|
||||||
$problems | each {|p| print -e $" - ($p)" } | ignore
|
$problems | each {|p| print -e $" - ($p)" } | ignore
|
||||||
exit 1
|
# Catchable, so a module-mode caller survives; script mode still exits 1.
|
||||||
|
error make { msg: "dev-test self-check failed; see the problems above" }
|
||||||
}
|
}
|
||||||
print "dev-test self-check: ok"
|
print "dev-test self-check: ok"
|
||||||
}
|
}
|
||||||
@@ -332,7 +346,7 @@ def lint-steps [] {
|
|||||||
let detail = (if not (($found.stdout | str trim) | is-empty) {
|
let detail = (if not (($found.stdout | str trim) | is-empty) {
|
||||||
$"openssl is in the dependency tree:\n($found.stdout)"
|
$"openssl is in the dependency tree:\n($found.stdout)"
|
||||||
} else {
|
} else {
|
||||||
$"cargo tree failed (exit ($found.exit_code)): ($found.stderr | str trim)"
|
$"cargo tree failed with status ($found.exit_code): ($found.stderr | str trim)"
|
||||||
})
|
})
|
||||||
error make { msg: $detail }
|
error make { msg: $detail }
|
||||||
}
|
}
|
||||||
@@ -358,8 +372,11 @@ def run-steps [steps: list] {
|
|||||||
print ((pad $r.step $width "left") + (if $r.result == "ok" { $"(ansi green)($status)(ansi reset)" } else { $"(ansi red)($status)(ansi reset)" }) + (pad $"(($r.seconds))s" 9 "right") + $" ($r.command)")
|
print ((pad $r.step $width "left") + (if $r.result == "ok" { $"(ansi green)($status)(ansi reset)" } else { $"(ansi red)($status)(ansi reset)" }) + (pad $"(($r.seconds))s" 9 "right") + $" ($r.command)")
|
||||||
}
|
}
|
||||||
print ""
|
print ""
|
||||||
if ($results | any {|r| $r.result != "ok" }) {
|
let failed = ($results | where result != "ok" | get step)
|
||||||
exit 1
|
if not ($failed | is-empty) {
|
||||||
|
# A catchable error, not `exit`: with `use dev/dev-test.nu *` in a Nushell
|
||||||
|
# config, `exit` ends the caller's session and cannot be caught.
|
||||||
|
error make { msg: $"($failed | str join ', ') failed; see the summary above" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -696,6 +713,40 @@ def check-filter-cache [] {
|
|||||||
$problems
|
$problems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# `exit` in a module ends the caller's Nushell session and cannot be caught, so
|
||||||
|
# a failing check must raise; only the script-mode entry point may exit.
|
||||||
|
def check-module-mode [] {
|
||||||
|
mut problems = []
|
||||||
|
let lines = (open --raw $SCRIPT_PATH | lines)
|
||||||
|
let entry = ($lines | enumerate | where {|r| $r.item =~ '^export def --wrapped main'} | get 0?.index)
|
||||||
|
let next = ($lines | enumerate | where {|r| $entry != null and $r.index > $entry and ($r.item =~ '^export def ')} | get 0?.index)
|
||||||
|
let exits = ($lines | enumerate | where {|r| $r.item =~ '^\s*exit\b'} | get index)
|
||||||
|
let allowed = ($exits | where {|i| $entry != null and $i > $entry and ($next == null or $i < $next)})
|
||||||
|
for i in ($exits | where {|i| $i not-in $allowed}) {
|
||||||
|
$problems = ($problems | append $"line ($i + 1) calls exit outside the script-mode entry point: ($lines | get $i | str trim)")
|
||||||
|
}
|
||||||
|
# `(exit ...)` inside a double-quoted string is a subexpression that ends the
|
||||||
|
# process instead of building the message.
|
||||||
|
for r in ($lines | enumerate | where {|r| $r.item =~ '\$".*\(\s*exit\b'}) {
|
||||||
|
$problems = ($problems | append $"line ($r.index + 1) interpolates a call to exit: ($r.item | str trim)")
|
||||||
|
}
|
||||||
|
# The failure path itself: catch it in module mode and keep going.
|
||||||
|
let probe = (with-env { SKYG_TEST_ASSUME_NO_KVM: "1" } {
|
||||||
|
run-external "nu" "--no-config-file" "-c" $"use ($SCRIPT_PATH) *; try { ($RUNNER) vm } catch { print 'caught' }; print 'after'" | complete
|
||||||
|
})
|
||||||
|
if $probe.exit_code != 0 or not ($probe.stdout | str contains "caught") or not ($probe.stdout | str contains "after") {
|
||||||
|
$problems = ($problems | append $"module mode: a failing step was not catchable, exit code ($probe.exit_code); wanted 'caught' and 'after' in: ($probe.stdout | str trim) ($probe.stderr | str trim)")
|
||||||
|
}
|
||||||
|
# Script mode still has to fail.
|
||||||
|
let script = (with-env { SKYG_TEST_ASSUME_NO_KVM: "1" } {
|
||||||
|
run-external "nu" "--no-config-file" $SCRIPT_PATH "vm" | complete
|
||||||
|
})
|
||||||
|
if $script.exit_code == 0 or not ($script.stderr | str contains "/dev/kvm") {
|
||||||
|
$problems = ($problems | append $"script mode: a failing step exited ($script.exit_code), expected non-zero with the /dev/kvm reason: ($script.stderr | str trim)")
|
||||||
|
}
|
||||||
|
$problems
|
||||||
|
}
|
||||||
|
|
||||||
def check-openssl-verdict [] {
|
def check-openssl-verdict [] {
|
||||||
mut problems = []
|
mut problems = []
|
||||||
let cases = [
|
let cases = [
|
||||||
|
|||||||
Reference in new issue
Block a user