T: review round 1 fix runner argv, filter cache, and the test builtin
This commit is contained in:
1 parent
40cf1073f4
commit
6dade6239d
6 files changed
+562
-93
No files matched your search
+513
-64
@@ -5,7 +5,7 @@
|
||||
# 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 --tests [filter] [--nocapture]", flags: ["--nocapture"] }
|
||||
{ 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: [] }
|
||||
@@ -14,11 +14,17 @@ const command_table = [
|
||||
{ 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 --tests [filter] [--nocapture]
|
||||
# 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.<system>.peers)
|
||||
# all lint, unit, integration; stops at the first failure
|
||||
@@ -30,30 +36,41 @@ const command_table = [
|
||||
# command per subcommand, so Nushell completes names and flags natively.
|
||||
#
|
||||
# The checks are read-only against the host: no /etc, systemd or Docker changes.
|
||||
export def main [
|
||||
...args: string # subcommand and its arguments, as in `test integration peers`
|
||||
--nocapture # forward to `test integration`
|
||||
] {
|
||||
if ($args | is-empty) {
|
||||
print-help
|
||||
return
|
||||
}
|
||||
let sub = ($args | first)
|
||||
let rest = ($args | skip 1)
|
||||
let positional = ($rest | where {|a| not ($a | str starts-with "-") })
|
||||
if $sub not-in ($command_table | get name) {
|
||||
error make { msg: $"unknown subcommand '($sub)'; run 'test --help' for the list" }
|
||||
}
|
||||
match $sub {
|
||||
#
|
||||
# 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" => { test integration ($positional | get 0?) --nocapture=$nocapture }
|
||||
"integration" => {
|
||||
if ($parsed.positional | is-empty) {
|
||||
test integration --nocapture=$parsed.nocapture
|
||||
} else {
|
||||
test integration $parsed.positional --nocapture=$parsed.nocapture
|
||||
}
|
||||
}
|
||||
"lint" => { test lint }
|
||||
"vm" => { test vm ($positional | get 0?) }
|
||||
"vm" => {
|
||||
if ($parsed.positional | is-empty) {
|
||||
test vm
|
||||
} else {
|
||||
test vm $parsed.positional
|
||||
}
|
||||
}
|
||||
"all" => { test all }
|
||||
"ci" => { test ci }
|
||||
"completions" => { test completions ($positional | get 0?) }
|
||||
"completions" => {
|
||||
if ($parsed.positional | is-empty) {
|
||||
test completions
|
||||
} else {
|
||||
test completions $parsed.positional
|
||||
}
|
||||
}
|
||||
"self-check" => { test self-check }
|
||||
_ => { error make { msg: $"subcommand '($sub)' has no dispatch arm" } }
|
||||
_ => { error make { msg: $"subcommand '($parsed.cmd)' has no dispatch arm" } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,13 +127,22 @@ export def "test completions" [
|
||||
|
||||
# Fail if the command table, the defined commands or the help text diverge.
|
||||
export def "test self-check" [] {
|
||||
let problems = (check-consistency)
|
||||
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: command table, commands and help agree"
|
||||
print "test self-check: ok"
|
||||
}
|
||||
|
||||
def "nu-complete test vm" [] {
|
||||
@@ -127,26 +153,86 @@ def "nu-complete test shells" [] {
|
||||
["zsh" "bash"]
|
||||
}
|
||||
|
||||
# Test names come from cargo; the first Tab compiles in debug mode and is slow,
|
||||
# so the list is kept for the rest of the session.
|
||||
# `cargo test --test '*'` matches integration targets only, same as the integration step.
|
||||
def "nu-complete test filters" [] {
|
||||
if ($env.SKYG_TEST_FILTERS? | is-not-empty) {
|
||||
return $env.SKYG_TEST_FILTERS
|
||||
let key = (try { source-mtime-key } catch { "unknown" })
|
||||
try {
|
||||
cached-lines (filter-cache-path) $key {|| list-test-names }
|
||||
} catch {
|
||||
[]
|
||||
}
|
||||
let listed = (do -i { run-external "cargo" "test" "--tests" "--" "--list" | complete })
|
||||
let names = ($listed
|
||||
| default {stdout: ""}
|
||||
| get stdout
|
||||
| lines
|
||||
| where {|l| $l =~ ': (test|benchmark)$'}
|
||||
| each {|l| $l | str replace -r ': (test|benchmark)$' '' | str replace -r '^.*: ' '' }
|
||||
| uniq)
|
||||
}
|
||||
|
||||
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<string>] {
|
||||
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) {
|
||||
$env.SKYG_TEST_FILTERS = $names
|
||||
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 }
|
||||
}
|
||||
@@ -157,35 +243,71 @@ def unit-steps [] {
|
||||
})]
|
||||
}
|
||||
|
||||
def require-kvm [] {
|
||||
if not ("/dev/kvm" | path exists) {
|
||||
error make {
|
||||
msg: "/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 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] {
|
||||
require-kvm
|
||||
# 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 filter_args = (if ($filter | is-empty) { [] } else { ["--", $filter] })
|
||||
let capture_args = (if $nocapture { ["--nocapture"] } else { [] })
|
||||
let args = (["test" "--tests"] | append $filter_args | append $capture_args)
|
||||
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" {||
|
||||
@@ -194,12 +316,15 @@ def lint-steps [] {
|
||||
(step-record "clippy" "cargo clippy --all-targets -- -D warnings" {||
|
||||
run-checked "cargo" ["clippy" "--all-targets" "--" "-D" "warnings"]
|
||||
})
|
||||
# An empty tree is the only acceptable answer; cargo itself exits non-zero
|
||||
# when nothing matches, so the exit code is not the signal here.
|
||||
(step-record "openssl" "cargo tree -i openssl (must be empty)" {||
|
||||
let found = (run-external "cargo" "tree" "-i" "openssl" | complete)
|
||||
if not (($found.stdout | str trim) | is-empty) {
|
||||
error make { msg: $"openssl is in the dependency tree:\n($found.stdout)" }
|
||||
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 }
|
||||
}
|
||||
})
|
||||
]
|
||||
@@ -254,28 +379,46 @@ def run-step [s: record] {
|
||||
# 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<string>] {
|
||||
# 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 <subcommand>` or `nu dev/test.nu <subcommand>`."
|
||||
"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: test <subcommand> [args]"
|
||||
print "Usage: devenv shell -- test <subcommand> [args]"
|
||||
print " nu dev/test.nu <subcommand> [args]"
|
||||
print ""
|
||||
$command_table | each {|c| {subcommand: $c.name, flags: ($c.flags | str join " "), what: $c.usage} } | table -e | print
|
||||
print ""
|
||||
print "In Nushell: use dev/test.nu * (then `test integration peers`). In zsh/bash: source <(test completions zsh|bash)."
|
||||
print "Underlying commands: test --help, or `test <subcommand> --help`."
|
||||
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)
|
||||
@@ -288,31 +431,51 @@ def zsh-template [] {
|
||||
# A raw string cannot start with `#` in Nushell, so the template starts on the next line.
|
||||
r#'
|
||||
#compdef test
|
||||
# Completion for the repository test runner: source <(test completions zsh)
|
||||
# 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
|
||||
if [[ "${words[2]}" == -* ]]; then
|
||||
compadd -- __FLAGS__
|
||||
else
|
||||
_describe 'subcommand' subcommands
|
||||
fi
|
||||
_describe 'subcommand' subcommands
|
||||
return
|
||||
fi
|
||||
case "${words[2]}" in
|
||||
vm) compadd -- __VM__ __FLAGS__ ;;
|
||||
integration) compadd -- __FLAGS__ ;;
|
||||
vm) compadd -- __VM__ ;;
|
||||
completions) compadd -- __SHELLS__ ;;
|
||||
*) compadd -- __FLAGS__ ;;
|
||||
esac
|
||||
}
|
||||
compdef _test_runner test
|
||||
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: source <(test completions bash)
|
||||
# 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]}"
|
||||
@@ -328,16 +491,65 @@ _test_runner() {
|
||||
return 0
|
||||
fi
|
||||
case "$sub" in
|
||||
vm) COMPREPLY=( $(compgen -W "__VM__ __FLAGS__" -- "$cur") ) ;;
|
||||
integration) COMPREPLY=( $(compgen -W "__FLAGS__" -- "$cur") ) ;;
|
||||
vm) COMPREPLY=( $(compgen -W "__VM__" -- "$cur") ) ;;
|
||||
completions) COMPREPLY=( $(compgen -W "__SHELLS__" -- "$cur") ) ;;
|
||||
*) COMPREPLY=( $(compgen -W "__FLAGS__" -- "$cur") ) ;;
|
||||
*) COMPREPLY=() ;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
test() {
|
||||
if [ $# -eq 0 ]; then
|
||||
command nu "__SCRIPT__"
|
||||
return
|
||||
fi
|
||||
case "$1" in
|
||||
__PATTERN__)
|
||||
command nu "__SCRIPT__" "$@"
|
||||
;;
|
||||
*)
|
||||
builtin test "$@"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
complete -F _test_runner test
|
||||
'# | str trim --left
|
||||
}
|
||||
|
||||
# Script-mode argv is one list. Swallowing a flag or a spare word made
|
||||
# `test unit --nocapture` and `test integration a b` look successful.
|
||||
def parse-script-args [args: list<string>] {
|
||||
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 [] {
|
||||
@@ -380,5 +592,242 @@ def check-consistency [] {
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user