#!/usr/bin/env nu # The single source of truth for names and flags: drives dispatch, zsh/bash # completion and the self-check. Nushell completion still comes from the # signatures below; the self-check keeps both in step. const command_table = [ { name: "unit", usage: "cargo test --lib --bins", flags: [] } { name: "integration", usage: "cargo test --test '*' [filter] [--nocapture]", flags: ["--nocapture"] } { name: "lint", usage: "fmt, clippy and the openssl check", flags: [] } { name: "vm", usage: "nix build of a NixOS VM test: vm or peers", flags: [] } { name: "all", usage: "lint, unit, integration; stops at the first failure", flags: [] } { name: "ci", usage: "all plus the vm test", flags: [] } { name: "completions", usage: "print a zsh or bash completion script", flags: [] } { name: "self-check", usage: "check that the table, commands and help agree", flags: [] } ] # Baked into the generated shell function so completion works from any directory. const SCRIPT_PATH = path self # Completers cannot update the caller's environment, so the filter list is a file. const FILTER_CACHE = "target/skyg-test-filters.cache" # One entry point for the repository's checks. # # Subcommands: # unit cargo test --lib --bins # integration cargo test --test '*' [filter] [--nocapture] # lint cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo tree -i openssl (empty) # vm nix build of a NixOS VM test: vm (checks) or peers (tests..peers) # all lint, unit, integration; stops at the first failure # ci all plus the vm test # completions print a zsh or bash completion script # self-check fail when the command table, the commands and the help text diverge # # Loaded as a module (`use dev/test.nu *`) this file provides `test` plus one # command per subcommand, so Nushell completes names and flags natively. # # The checks are read-only against the host: no /etc, systemd or Docker changes. # # Script mode (`nu dev/test.nu`) is `--wrapped` so flags reach the parser below. # Nushell would otherwise accept `--nocapture` on every subcommand and reject # the rest before `main` can explain them. export def --wrapped main [...args: string] { let parsed = (parse-script-args $args) match $parsed.cmd { "help" => { print-help } "unit" => { test unit } "integration" => { if ($parsed.positional | is-empty) { test integration --nocapture=$parsed.nocapture } else { test integration $parsed.positional --nocapture=$parsed.nocapture } } "lint" => { test lint } "vm" => { if ($parsed.positional | is-empty) { test vm } else { test vm $parsed.positional } } "all" => { test all } "ci" => { test ci } "completions" => { if ($parsed.positional | is-empty) { test completions } else { test completions $parsed.positional } } "self-check" => { test self-check } _ => { error make { msg: $"subcommand '($parsed.cmd)' has no dispatch arm" } } } } # Run the unit tests: no sockets, no host access. export def "test unit" [] { run-steps (unit-steps) } # Run the integration tests (plain, tls, integration, binary_smoke, peers). export def "test integration" [ filter?: string@"nu-complete test filters" # cargo name filter, e.g. a test name or file --nocapture # do not capture test output ] { run-steps (integration-steps $filter $nocapture) } # Formatting, lints and the dependency check. export def "test lint" [] { run-steps (lint-steps) } # Run a NixOS VM test. Slow: it builds and boots VMs. export def "test vm" [ name?: string@"nu-complete test vm" # vm (checks) or peers (tests..peers) ] { let name = ($name | default "vm") if $name not-in (nu-complete test vm) { error make { msg: $"unknown VM test '($name)'; expected one of: (nu-complete test vm | str join ', ')" } } run-steps (vm-steps $name) } # lint, unit and integration; stops at the first failure. export def "test all" [] { run-steps ((lint-steps) | append (unit-steps) | append (integration-steps null false)) } # `test all` plus the VM test. export def "test ci" [] { run-steps ((lint-steps) | append (unit-steps) | append (integration-steps null false) | append (vm-steps "vm")) } # Print a completion script for a shell that cannot load this module (zsh, bash). export def "test completions" [ shell?: string@"nu-complete test shells" # zsh or bash ] { let shell = ($shell | default "zsh") match $shell { "zsh" => { print (completion-script zsh) } "bash" => { print (completion-script bash) } _ => { error make { msg: $"unknown shell '($shell)'; expected one of: (nu-complete test shells | str join ', ')" } } } } # Fail if the command table, the defined commands or the help text diverge. export def "test self-check" [] { let problems = ( (check-consistency) ++ (check-integration-args) ++ (check-dispatch) ++ (check-filter-cache) ++ (check-openssl-verdict) ++ (check-kvm-step) ++ (check-shell-wrapper) ++ (check-docs) ) if not ($problems | is-empty) { print -e "test self-check failed:" $problems | each {|p| print -e $" - ($p)" } | ignore exit 1 } print "test self-check: ok" } def "nu-complete test vm" [] { ["vm" "peers"] } def "nu-complete test shells" [] { ["zsh" "bash"] } # `cargo test --test '*'` matches integration targets only, same as the integration step. def "nu-complete test filters" [] { let key = (try { source-mtime-key } catch { "unknown" }) try { cached-lines (filter-cache-path) $key {|| list-test-names } } catch { [] } } def filter-cache-path [] { let override = ($env.SKYG_TEST_FILTER_CACHE? | default "") if ($override | is-empty) { $FILTER_CACHE } else { $override } } def source-mtime-key [] { let rows = (ls src/**/*.rs tests/**/*.rs Cargo.toml Cargo.lock) if ($rows | is-empty) { return "none" } $rows | get modified | math max | format date "%s.%f" } # Null means a miss. An empty list is a hit that listed no tests. def read-cached-lines [path: string, key: string] { if not ($path | path exists) { return null } let lines = (open --raw $path | lines | where {|l| not ($l | is-empty) }) if ($lines | is-empty) or (($lines | first) != $key) { return null } $lines | skip 1 } def write-cached-lines [path: string, key: string, names: list] { mkdir ($path | path dirname) ([$key] | append $names | str join (char nl)) | save -f $path } def cached-lines [path: string, key: string, produce: closure] { let hit = (read-cached-lines $path $key) if $hit != null { return $hit } let names = (do $produce) if not ($names | is-empty) { write-cached-lines $path $key $names } $names } def list-test-names [] { # Self-check points this at a counter file to prove Tab does not re-list. let stub = ($env.SKYG_TEST_LIST_STUB? | default "") if not ($stub | is-empty) { let n = (if ($stub | path exists) { open --raw $stub | str trim | into int } else { 0 }) ($n + 1 | into string) | save -f $stub return ["stub-test"] } let listed = (try { run-external "cargo" "test" "--test" "*" "--" "--list" | complete } catch { {stdout: "", stderr: "", exit_code: 1} }) if $listed.exit_code != 0 { return [] } $listed.stdout | lines | where {|l| $l =~ ': (test|benchmark)$' } | each {|l| $l | str replace -r ': (test|benchmark)$' '' } | uniq | sort } def step-record [label: string, command: string, body: closure] { { label: $label, command: $command, body: $body } } def unit-steps [] { [(step-record "unit" "cargo test --lib --bins" {|| run-checked "cargo" ["test" "--lib" "--bins"] })] } def kvm-available [] { # Self-check sets this to prove a missing device fails inside the step. if ($env.SKYG_TEST_ASSUME_NO_KVM? | default "") == "1" { return false } "/dev/kvm" | path exists } def kvm-refusal [] { if (kvm-available) { null } else { "/dev/kvm is missing: NixOS VM tests need hardware virtualisation. Run on a Linux host with KVM, or in CI with KVM exposed; there is no software fallback." } } def vm-steps [name: string] { # The KVM check runs in the step body. Raising it here would abort `test ci` # before lint, unit and integration, and the summary table would not print. let attr = (match $name { "peers" => "tests" _ => "checks" }) let system = $"($nu.os-info.arch)-($nu.os-info.name)" [(step-record $"vm ($name)" $"nix build .#($attr).($system).($name) -L" {|| let why = (kvm-refusal) if $why != null { error make { msg: $why } } print "NixOS VM tests are slow: expect several minutes." run-checked "nix" ["build" $".#($attr).($system).($name)" "-L"] })] } # Libtest flags must follow `--`. A bare `--nocapture` is a cargo flag and cargo rejects it. def integration-cargo-args [filter: any, nocapture: bool] { mut tail = [] if not ($filter | is-empty) { $tail = ($tail | append ($filter | into string)) } if $nocapture { $tail = ($tail | append "--nocapture") } let args = ["test" "--test" "*"] if ($tail | is-empty) { $args } else { $args | append "--" | append $tail } } def integration-steps [filter: any, nocapture: bool] { let args = (integration-cargo-args $filter $nocapture) let label = (if ($filter | is-empty) { "integration" } else { $"integration ($filter)" }) [(step-record $label $"cargo ($args | str join ' ')" {|| run-checked "cargo" $args })] } # Empty stdout is success only when cargo actually ran. A lockfile or registry # error also leaves stdout empty and must fail the step. def openssl-tree-ok [stdout: string, stderr: string, exit_code: int] { let stdout_empty = (($stdout | str trim) | is-empty) let no_match = ($stderr | str contains "did not match any packages") ($exit_code == 0 and $stdout_empty) or $no_match } def lint-steps [] { [ (step-record "fmt" "cargo fmt --check" {|| run-checked "cargo" ["fmt" "--check"] }) (step-record "clippy" "cargo clippy --all-targets -- -D warnings" {|| run-checked "cargo" ["clippy" "--all-targets" "--" "-D" "warnings"] }) (step-record "openssl" "cargo tree -i openssl (must be empty)" {|| let found = (run-external "cargo" "tree" "-i" "openssl" | complete) if not (openssl-tree-ok $found.stdout $found.stderr $found.exit_code) { let detail = (if not (($found.stdout | str trim) | is-empty) { $"openssl is in the dependency tree:\n($found.stdout)" } else { $"cargo tree failed (exit ($found.exit_code)): ($found.stderr | str trim)" }) error make { msg: $detail } } }) ] } # Run each step in order, stop at the first failure, always print the summary # table and exit non-zero if anything failed. def run-steps [steps: list] { mut results = [] for s in $steps { let r = (run-step $s) $results = ($results | append $r) if $r.result != "ok" { break } } let width = ([26 ($results | each {|r| $r.step | str length } | math max)] | math max) print "" print "Summary:" print ((pad "step" $width "left") + (pad "result" 8 "left") + (pad "seconds" 9 "right") + " command") for r in $results { let status = (pad $r.result 8 "left") 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 "" if ($results | any {|r| $r.result != "ok" }) { exit 1 } } def pad [text: string, width: int, alignment: string] { $text | fill -a $alignment -w $width } def run-step [s: record] { print "" print $"(ansi cyan)==> ($s.label)(ansi reset) ($s.command)" let started = (date now) let ok = (try { do $s.body | ignore true } catch {|e| print -e $"(ansi red)($s.label) failed: ($e.msg)(ansi reset)" false }) { step: $s.label command: $s.command result: (if $ok { "ok" } else { "FAILED" }) seconds: ((((date now) - $started) / 1sec) | math round --precision 1) } } # Redirect straight to stdout so long builds and tests show progress; Nushell # raises on a non-zero exit, which the enclosing step records as a failure. def run-checked [cmd: string, args: list] { # Self-check spawns the runner with this set to read the argv without the suite. if ($env.SKYG_TEST_DRY_RUN? | default "") == "1" { print $"DRY-ARGS: ([$cmd] | append $args | str join '|')" return } run-external $cmd ...$args o> /dev/stdout } def help-footer [] { [ "In an interactive bash or zsh, `test` is the shell builtin, so `test unit` exits 0 without running the suite." "Run `devenv shell -- test ` or `nu dev/test.nu `." "An interactive `devenv shell` installs a bash function for known subcommands; `test -f` stays the builtin." "zsh: after compinit, add `source <(nu dev/test.nu completions zsh)` to .zshrc. direnv cannot carry that function." "Nushell: `use dev/test.nu *`." ] | str join "\n" } def print-help [] { print "Run the repository's checks." print "" print "Usage: devenv shell -- test [args]" print " nu dev/test.nu [args]" print "" $command_table | each {|c| {subcommand: $c.name, flags: ($c.flags | str join " "), what: $c.usage} } | table -e | print print "" print (help-footer) } def completion-script [shell: string] { let subcommands = ($command_table | get name | str join " ") let pattern = (($command_table | get name) | append ["--help" "-h"] | str join "|") let flags = ($command_table | get flags | flatten | uniq | str join " ") let replacements = { "__SUBCOMMANDS__": $subcommands "__PATTERN__": $pattern "__FLAGS__": $flags "__VM__": (nu-complete test vm | str join " ") "__SHELLS__": (nu-complete test shells | str join " ") "__SCRIPT__": $SCRIPT_PATH } let template = (match $shell { "zsh" => (zsh-template) _ => (bash-template) }) $replacements | transpose key value | reduce --fold $template {|it, acc| $acc | str replace -a $it.key $it.value } } def zsh-template [] { # A raw string cannot start with `#` in Nushell, so the template starts on the next line. r#' #compdef test # zsh completion for the repository test runner. # `test` is a shell builtin: `test unit` exits 0 and runs nothing. This function # sends known subcommands to the runner and leaves every other call to `builtin test`. # Install after compinit (this hook cannot see zsh from devenv's bash, and direnv # will not carry the function): # source <(nu dev/test.nu completions zsh) _test_runner() { local -a subcommands subcommands=(__SUBCOMMANDS__) if (( CURRENT == 2 )); then _describe 'subcommand' subcommands return fi case "${words[2]}" in integration) compadd -- __FLAGS__ ;; vm) compadd -- __VM__ ;; completions) compadd -- __SHELLS__ ;; esac } test() { if [[ $# -eq 0 ]]; then command nu "__SCRIPT__" return fi case "$1" in __PATTERN__) command nu "__SCRIPT__" "$@" ;; *) builtin test "$@" ;; esac } if (( $+functions[compdef] )); then compdef _test_runner test fi '# | str trim --left } def bash-template [] { r#' # bash completion for the repository test runner. # `test` is a shell builtin: `test unit` exits 0 and runs nothing. This function # sends known subcommands to the runner and leaves every other call to `builtin test`. # source <(nu dev/test.nu completions bash) _test_runner() { local cur sub i cur="${COMP_WORDS[COMP_CWORD]}" sub="" for ((i=1; i] { if ($args | is-empty) or ($args | any {|a| ($a == "--help") or ($a == "-h") }) { return {cmd: "help", positional: null, nocapture: false} } let sub = ($args | first) if $sub not-in ($command_table | get name) { error make { msg: $"unknown subcommand '($sub)'; run 'test --help' for the list" } } let rest = ($args | skip 1) let allowed = ($command_table | where name == $sub | get 0.flags) mut positionals = [] mut nocapture = false for a in $rest { if ($a | str starts-with "-") { if $a not-in $allowed { error make { msg: $"unknown flag '($a)' for 'test ($sub)'" } } if $a == "--nocapture" { $nocapture = true } } else { $positionals = ($positionals | append $a) } } let max_pos = (if $sub in ["integration" "vm" "completions"] { 1 } else { 0 }) if ($positionals | length) > $max_pos { let what = (if $max_pos == 0 { "no arguments" } else { "at most one argument" }) error make { msg: $"test ($sub) takes ($what); got '($positionals | str join ' ')'" } } {cmd: $sub, positional: ($positionals | get 0?), nocapture: $nocapture} } # Compare the table with the commands Nushell actually parsed from this file and # with the help block above; every entry must agree in all three places. def check-consistency [] { let defined = (scope commands | where {|c| $c.name == "test" or ($c.name | str starts-with "test ")} | get name | where {|n| $n != "test" } | each {|n| $n | str substring 5.. }) let table = ($command_table | get name) # The entry point is `test` once the file is used as a module and `main` when # it runs as a script; both modes must agree with the table. let entry = (scope commands | where {|c| $c.name in ["test" "main"]} | get 0?) let usage = (if $entry == null { "" } else { $entry.extra_description | default "" }) mut problems = [] for name in $table { if $name not-in $defined { $problems = ($problems | append $"table lists '($name)' but there is no 'test ($name)' command") } if not ($usage =~ ('(?m)^\s+' + $name + '\s')) { $problems = ($problems | append $"help text does not list '($name)'") } let cmd = (scope commands | where name == $"test ($name)" | get 0?) let flags = (if $cmd == null { [] } else { $cmd.signatures | get any | where {|p| $p.parameter_type in ["switch" "named"]} | each {|p| $"--($p.parameter_name)" } | sort }) let expected = (($command_table | where name == $name | get 0.flags) | sort) if $flags != $expected { $problems = ($problems | append $"flags of 'test ($name)' are ($flags | to json -r), table says ($expected | to json -r)") } } for name in $defined { if $name not-in $table { $problems = ($problems | append $"command 'test ($name)' is not in the command table") } } # The generated shells must at least parse; only checked where the shell exists. for shell in (nu-complete test shells) { if not ((which $shell | is-empty)) { let file = ($nu.temp-dir | path join $"test-completions-($nu.pid).($shell)") completion-script $shell | save -f $file let syntax = (run-external $shell "-n" $file | complete) rm -f $file if $syntax.exit_code != 0 { $problems = ($problems | append $"($shell) completion script does not parse: ($syntax.stderr | str trim)") } } } let footer = (help-footer) if ($footer | str contains "source <(test completions") { $problems = ($problems | append "help tells the shell to complete the builtin via 'test completions'") } if not ($footer | str contains "nu dev/test.nu completions") { $problems = ($problems | append "help does not show 'nu dev/test.nu completions'") } $problems } def check-integration-args [] { mut problems = [] let nocap = (integration-steps null true | first | get command) if $nocap != "cargo test --test * -- --nocapture" { $problems = ($problems | append $"integration --nocapture argv is '($nocap)'") } let both = (integration-steps "peers" true | first | get command) if $both != "cargo test --test * -- peers --nocapture" { $problems = ($problems | append $"integration filter+nocapture argv is '($both)'") } let plain = (integration-steps null false | first | get command) if $plain != "cargo test --test *" { $problems = ($problems | append $"integration argv is '($plain)'") } # The runner must emit that argv, not only build it in memory. let child = (with-env { SKYG_TEST_DRY_RUN: "1" } { run-external "nu" $SCRIPT_PATH "integration" "--nocapture" | complete }) let want = "DRY-ARGS: cargo|test|--test|*|--|--nocapture" if $child.exit_code != 0 or not ($child.stdout | str contains $want) { $problems = ($problems | append $"CLI integration --nocapture exit ($child.exit_code), wanted '($want)': ($child.stdout)\n($child.stderr)") } let filtered = (with-env { SKYG_TEST_DRY_RUN: "1" } { run-external "nu" $SCRIPT_PATH "integration" "peers" "--nocapture" | complete }) let want_both = "DRY-ARGS: cargo|test|--test|*|--|peers|--nocapture" if $filtered.exit_code != 0 or not ($filtered.stdout | str contains $want_both) { $problems = ($problems | append $"CLI integration peers --nocapture exit ($filtered.exit_code), wanted '($want_both)'") } # Cargo itself must accept `--nocapture` with no filter. That is the bug. let listed = (run-external "cargo" "test" "--test" "*" "--" "--nocapture" "--list" | complete) if $listed.exit_code != 0 { $problems = ($problems | append $"cargo rejected --nocapture after --: ($listed.stderr | str trim)") } $problems } def check-dispatch [] { mut problems = [] let cases = [ {args: ["unit" "--nocapture"], needle: "unknown flag"} {args: ["integration" "a" "b"], needle: "at most one"} {args: ["integration" "--bogus"], needle: "unknown flag"} {args: ["lint" "-x"], needle: "unknown flag"} {args: ["vm" "peers" "extra"], needle: "at most one"} {args: ["all" "--nocapture"], needle: "unknown flag"} {args: ["ci" "extra"], needle: "no arguments"} ] for c in $cases { let got = (try { parse-script-args $c.args | ignore; "ok" } catch {|e| $e.msg }) if not ($got | str contains $c.needle) { $problems = ($problems | append $"parse ($c.args | str join ' ') -> '($got)', expected '($c.needle)'") } } let ok = (parse-script-args ["integration" "peers" "--nocapture"]) if $ok.cmd != "integration" or $ok.positional != "peers" or (not $ok.nocapture) { $problems = ($problems | append $"parse integration peers --nocapture -> ($ok | to nuon)") } let bare = (parse-script-args ["integration" "--nocapture"]) if (not $bare.nocapture) or (not ($bare.positional | is-empty)) { $problems = ($problems | append $"parse integration --nocapture -> ($bare | to nuon)") } let cli = (run-external "nu" $SCRIPT_PATH "unit" "--nocapture" | complete) if $cli.exit_code == 0 or not ($cli.stderr | str contains "unknown flag") { $problems = ($problems | append $"CLI 'test unit --nocapture' exit ($cli.exit_code): ($cli.stderr | str trim) ($cli.stdout | str trim)") } let extra = (run-external "nu" $SCRIPT_PATH "integration" "a" "b" | complete) if $extra.exit_code == 0 or not ($extra.stderr | str contains "at most one") { $problems = ($problems | append $"CLI 'test integration a b' exit ($extra.exit_code): ($extra.stderr | str trim)") } $problems } def check-filter-cache [] { mut problems = [] if not ($FILTER_CACHE | str starts-with "target/") { $problems = ($problems | append "filter cache must live under target/") } let dir = ($nu.temp-dir | path join $"filter-cache-($nu.pid)") rm -rf $dir mkdir $dir let counter = ($dir | path join "calls") let cache = ($dir | path join "cache") "0" | save -f $counter let ran = (with-env { SKYG_TEST_LIST_STUB: $counter, SKYG_TEST_FILTER_CACHE: $cache } { let first = (nu-complete test filters) let second = (nu-complete test filters) let n = (open --raw $counter | str trim | into int) let key = (source-mtime-key) let stored = (if ($cache | path exists) { open --raw $cache | lines | first } else { "" }) # A stale key must list again. Rewriting the key is the mtime changing. if ($cache | path exists) { let names = (open --raw $cache | lines | skip 1) (["stale"] | append $names | str join (char nl)) | save -f $cache } let third = (nu-complete test filters) let n2 = (open --raw $counter | str trim | into int) {first: $first, second: $second, third: $third, n: $n, n2: $n2, key: $key, stored: $stored} }) if $ran.n != 1 { $problems = ($problems | append $"filter completer listed ($ran.n) times; a warm cache should list once") } if $ran.first != $ran.second or $ran.first != ["stub-test"] { $problems = ($problems | append $"filter cache returned ($ran.first | to nuon) then ($ran.second | to nuon)") } if $ran.stored != $ran.key { $problems = ($problems | append $"filter cache key is '($ran.stored)', source mtime key is '($ran.key)'") } if $ran.n2 != 2 { $problems = ($problems | append $"stale filter cache listed ($ran.n2) times after a stale key") } rm -rf $dir $problems } def check-openssl-verdict [] { mut problems = [] let cases = [ {out: "", err: "error: package ID specification `openssl` did not match any packages\n", code: 101, ok: true} {out: "", err: "", code: 0, ok: true} {out: "openssl v1.0.0\n", err: "", code: 0, ok: false} {out: "", err: "error: failed to load source for a dependency", code: 101, ok: false} ] for c in $cases { let got = (openssl-tree-ok $c.out $c.err $c.code) if $got != $c.ok { $problems = ($problems | append $"openssl-tree-ok exit ($c.code) = ($got), expected ($c.ok)") } } $problems } def check-kvm-step [] { let built = (with-env { SKYG_TEST_ASSUME_NO_KVM: "1" } { try { let steps = (vm-steps "vm") let msg = (try { do ($steps | first | get body) "no-error" } catch {|e| $e.msg }) {built: true, msg: $msg} } catch {|e| {built: false, msg: $e.msg} } }) if not $built.built { return [$"vm-steps aborted while building the step list: ($built.msg)"] } if not ($built.msg | str contains "/dev/kvm") { return [$"missing kvm should fail the vm step, got: ($built.msg)"] } [] } def check-shell-wrapper [] { mut problems = [] let dir = ($nu.temp-dir | path join $"runner-wrap-($nu.pid)") rm -rf $dir mkdir $dir let fake = ($dir | path join "nu") let nl = (char nl) $"#!/bin/sh($nl)printf '%s\\n' \"\$*\"($nl)" | save -f $fake run-external "chmod" "+x" $fake | complete | ignore for shell in (nu-complete test shells) { if (which $shell | is-empty) { continue } let script = ($dir | path join $"completions.($shell)") completion-script $shell | save -f $script let probe = ($dir | path join $"probe.($shell)") [ $"source '($script)'" "test unit" $"test -f '($script)'" "if [ $? -eq 0 ]; then echo POSIX:0; else echo POSIX:1; fi" ] | str join (char nl) | save -f $probe let out = (with-env { PATH: ([$dir] | append $env.PATH) } { run-external $shell $probe | complete }) if $out.exit_code != 0 { $problems = ($problems | append $"($shell) wrapper exited ($out.exit_code): ($out.stderr | str trim)") continue } if not ($out.stdout | str contains $"($SCRIPT_PATH) unit") { $problems = ($problems | append $"($shell) did not dispatch 'test unit': ($out.stdout)") } if ($out.stdout | str contains $"($SCRIPT_PATH) -f") { $problems = ($problems | append $"($shell) sent POSIX test to the runner: ($out.stdout)") } if not ($out.stdout | str contains "POSIX:0") { $problems = ($problems | append $"($shell) POSIX test -f failed: ($out.stdout) ($out.stderr)") } } rm -rf $dir $problems } def check-docs [] { mut problems = [] for f in ["AGENTS.md" "README.md" "docs/consolidator.md" "devenv.nix"] { let text = (open --raw $f) if ($text | str contains "source <(test completions") { $problems = ($problems | append $"($f) completes the shell builtin via 'test completions'") } } for f in ["AGENTS.md" "README.md" "docs/consolidator.md"] { let text = (open --raw $f) if not ($text | str contains "nu dev/test.nu completions") { $problems = ($problems | append $"($f) does not show 'nu dev/test.nu completions'") } if not ($text | str contains "builtin") { $problems = ($problems | append $"($f) does not mention the test builtin") } } let hook = (open --raw devenv.nix) if not ($hook | str contains ">&2") { $problems = ($problems | append "enterShell banner is not sent to stderr") } if not ($hook | str contains "completions bash") { $problems = ($problems | append "enterShell does not install bash completion") } if ($hook | str contains "completions zsh") { $problems = ($problems | append "enterShell tries to install zsh completion from bash") } if not (($hook | str contains "case $-") and ($hook | str contains "*i*")) { $problems = ($problems | append "enterShell banner is not limited to interactive shells") } $problems }