T: rename runner to dev-test
This commit is contained in:
1 parent
6dade6239d
commit
b476ac2b0c
6 files changed
+331
-219
No files matched your search
+270
-165
@@ -14,8 +14,16 @@ 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.
|
||||
# Baked into dry-run spawns. Docs and help use the repo-relative path.
|
||||
const SCRIPT_PATH = path self
|
||||
const SCRIPT_REL = "dev/dev-test.nu"
|
||||
|
||||
# File stem. Nushell binds `main` to this name on `use`, so every subcommand
|
||||
# is `dev-test <sub>` or tab completion of `dev-test` does not list them.
|
||||
const RUNNER = "dev-test"
|
||||
|
||||
# Same name in both generated scripts, so the self-check can call it.
|
||||
const COMP_FN = "_dev_test"
|
||||
|
||||
# Completers cannot update the caller's environment, so the filter list is a file.
|
||||
const FILTER_CACHE = "target/skyg-test-filters.cache"
|
||||
@@ -32,101 +40,102 @@ const FILTER_CACHE = "target/skyg-test-filters.cache"
|
||||
# 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.
|
||||
# Loaded as a module (`use dev/dev-test.nu *`) the file stem is `dev-test`, so
|
||||
# the subcommands have to be named `dev-test <sub>` or Nushell will not
|
||||
# complete them.
|
||||
#
|
||||
# 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.
|
||||
# Script mode (`nu dev/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 }
|
||||
"unit" => { dev-test unit }
|
||||
"integration" => {
|
||||
if ($parsed.positional | is-empty) {
|
||||
test integration --nocapture=$parsed.nocapture
|
||||
dev-test integration --nocapture=$parsed.nocapture
|
||||
} else {
|
||||
test integration $parsed.positional --nocapture=$parsed.nocapture
|
||||
dev-test integration $parsed.positional --nocapture=$parsed.nocapture
|
||||
}
|
||||
}
|
||||
"lint" => { test lint }
|
||||
"lint" => { dev-test lint }
|
||||
"vm" => {
|
||||
if ($parsed.positional | is-empty) {
|
||||
test vm
|
||||
dev-test vm
|
||||
} else {
|
||||
test vm $parsed.positional
|
||||
dev-test vm $parsed.positional
|
||||
}
|
||||
}
|
||||
"all" => { test all }
|
||||
"ci" => { test ci }
|
||||
"all" => { dev-test all }
|
||||
"ci" => { dev-test ci }
|
||||
"completions" => {
|
||||
if ($parsed.positional | is-empty) {
|
||||
test completions
|
||||
dev-test completions
|
||||
} else {
|
||||
test completions $parsed.positional
|
||||
dev-test completions $parsed.positional
|
||||
}
|
||||
}
|
||||
"self-check" => { test self-check }
|
||||
"self-check" => { dev-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" [] {
|
||||
export def "dev-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
|
||||
export def "dev-test integration" [
|
||||
filter?: string@"nu-complete dev-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" [] {
|
||||
export def "dev-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.<system>.peers)
|
||||
export def "dev-test vm" [
|
||||
name?: string@"nu-complete dev-test vm" # vm (checks) or peers (tests.<system>.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 ', ')" }
|
||||
if $name not-in (nu-complete dev-test vm) {
|
||||
error make { msg: $"unknown VM test '($name)'; expected one of: (nu-complete dev-test vm | str join ', ')" }
|
||||
}
|
||||
run-steps (vm-steps $name)
|
||||
}
|
||||
|
||||
# lint, unit and integration; stops at the first failure.
|
||||
export def "test all" [] {
|
||||
export def "dev-test all" [] {
|
||||
run-steps ((lint-steps) | append (unit-steps) | append (integration-steps null false))
|
||||
}
|
||||
|
||||
# `test all` plus the VM test.
|
||||
export def "test ci" [] {
|
||||
# `dev-test all` plus the VM test.
|
||||
export def "dev-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
|
||||
export def "dev-test completions" [
|
||||
shell?: string@"nu-complete dev-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 ', ')" } }
|
||||
_ => { error make { msg: $"unknown shell '($shell)'; expected one of: (nu-complete dev-test shells | str join ', ')" } }
|
||||
}
|
||||
}
|
||||
|
||||
# Fail if the command table, the defined commands or the help text diverge.
|
||||
export def "test self-check" [] {
|
||||
export def "dev-test self-check" [] {
|
||||
let problems = (
|
||||
(check-consistency)
|
||||
++ (check-integration-args)
|
||||
@@ -134,27 +143,28 @@ export def "test self-check" [] {
|
||||
++ (check-filter-cache)
|
||||
++ (check-openssl-verdict)
|
||||
++ (check-kvm-step)
|
||||
++ (check-shell-wrapper)
|
||||
++ (check-shell-completion)
|
||||
++ (check-nu-completions)
|
||||
++ (check-docs)
|
||||
)
|
||||
if not ($problems | is-empty) {
|
||||
print -e "test self-check failed:"
|
||||
print -e "dev-test self-check failed:"
|
||||
$problems | each {|p| print -e $" - ($p)" } | ignore
|
||||
exit 1
|
||||
}
|
||||
print "test self-check: ok"
|
||||
print "dev-test self-check: ok"
|
||||
}
|
||||
|
||||
def "nu-complete test vm" [] {
|
||||
def "nu-complete dev-test vm" [] {
|
||||
["vm" "peers"]
|
||||
}
|
||||
|
||||
def "nu-complete test shells" [] {
|
||||
def "nu-complete dev-test shells" [] {
|
||||
["zsh" "bash"]
|
||||
}
|
||||
|
||||
# `cargo test --test '*'` matches integration targets only, same as the integration step.
|
||||
def "nu-complete test filters" [] {
|
||||
def "nu-complete dev-test filters" [] {
|
||||
let key = (try { source-mtime-key } catch { "unknown" })
|
||||
try {
|
||||
cached-lines (filter-cache-path) $key {|| list-test-names }
|
||||
@@ -260,7 +270,7 @@ def kvm-refusal [] {
|
||||
}
|
||||
|
||||
def vm-steps [name: string] {
|
||||
# The KVM check runs in the step body. Raising it here would abort `test ci`
|
||||
# The KVM check runs in the step body. Raising it here would abort `dev-test ci`
|
||||
# before lint, unit and integration, and the summary table would not print.
|
||||
let attr = (match $name {
|
||||
"peers" => "tests"
|
||||
@@ -389,19 +399,19 @@ def run-checked [cmd: string, args: list<string>] {
|
||||
|
||||
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 *`."
|
||||
$"Run `devenv shell -- ($RUNNER) <subcommand>` or `nu ($SCRIPT_REL) <subcommand>`."
|
||||
"An interactive `devenv shell` installs bash completion for this command."
|
||||
# Single quotes: `(...)` inside a double-quoted string runs the command.
|
||||
('zsh: after compinit, add `source <(nu ' + $SCRIPT_REL + ' completions zsh)` to .zshrc. direnv will not source it.')
|
||||
$"Nushell: `use ($SCRIPT_REL) *`."
|
||||
] | str join "\n"
|
||||
}
|
||||
|
||||
def print-help [] {
|
||||
print "Run the repository's checks."
|
||||
print ""
|
||||
print "Usage: devenv shell -- test <subcommand> [args]"
|
||||
print " nu dev/test.nu <subcommand> [args]"
|
||||
print $"Usage: devenv shell -- ($RUNNER) <subcommand> [args]"
|
||||
print $" nu ($SCRIPT_REL) <subcommand> [args]"
|
||||
print ""
|
||||
$command_table | each {|c| {subcommand: $c.name, flags: ($c.flags | str join " "), what: $c.usage} } | table -e | print
|
||||
print ""
|
||||
@@ -410,15 +420,14 @@ def print-help [] {
|
||||
|
||||
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
|
||||
"__VM__": (nu-complete dev-test vm | str join " ")
|
||||
"__SHELLS__": (nu-complete dev-test shells | str join " ")
|
||||
"__FN__": $COMP_FN
|
||||
"__RUNNER__": $RUNNER
|
||||
}
|
||||
let template = (match $shell {
|
||||
"zsh" => (zsh-template)
|
||||
@@ -428,20 +437,21 @@ def completion-script [shell: string] {
|
||||
}
|
||||
|
||||
def zsh-template [] {
|
||||
# `_describe` emits nothing unless a completion widget is already active, so
|
||||
# the candidate list was empty. `compadd` writes the words itself.
|
||||
# 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() {
|
||||
#compdef __RUNNER__
|
||||
# zsh completion for the dev-test runner. The command is an external program,
|
||||
# so this file only registers completion; it does not define a dev-test function.
|
||||
# Install after compinit (devenv's hook runs in bash, and direnv will not source
|
||||
# it for you):
|
||||
# source <(nu dev/dev-test.nu completions zsh)
|
||||
__FN__() {
|
||||
local -a subcommands
|
||||
subcommands=(__SUBCOMMANDS__)
|
||||
if (( CURRENT == 2 )); then
|
||||
_describe 'subcommand' subcommands
|
||||
compadd -- "${subcommands[@]}"
|
||||
return
|
||||
fi
|
||||
case "${words[2]}" in
|
||||
@@ -450,33 +460,18 @@ _test_runner() {
|
||||
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
|
||||
compdef __FN__ __RUNNER__
|
||||
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() {
|
||||
# bash completion for the dev-test runner. The command is an external program,
|
||||
# so this file only registers completion; it does not define a dev-test function.
|
||||
# source <(nu dev/dev-test.nu completions bash)
|
||||
__FN__() {
|
||||
local cur sub i
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
sub=""
|
||||
@@ -498,33 +493,19 @@ _test_runner() {
|
||||
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
|
||||
complete -F __FN__ __RUNNER__
|
||||
'# | 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.
|
||||
# `dev-test unit --nocapture` and `dev-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" }
|
||||
error make { msg: $"unknown subcommand '($sub)'; run '($RUNNER) --help' for the list" }
|
||||
}
|
||||
let rest = ($args | skip 1)
|
||||
let allowed = ($command_table | where name == $sub | get 0.flags)
|
||||
@@ -533,7 +514,7 @@ def parse-script-args [args: list<string>] {
|
||||
for a in $rest {
|
||||
if ($a | str starts-with "-") {
|
||||
if $a not-in $allowed {
|
||||
error make { msg: $"unknown flag '($a)' for 'test ($sub)'" }
|
||||
error make { msg: $"unknown flag '($a)' for '($RUNNER) ($sub)'" }
|
||||
}
|
||||
if $a == "--nocapture" {
|
||||
$nocapture = true
|
||||
@@ -545,7 +526,7 @@ def parse-script-args [args: list<string>] {
|
||||
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 ' ')'" }
|
||||
error make { msg: $"($RUNNER) ($sub) takes ($what); got '($positionals | str join ' ')'" }
|
||||
}
|
||||
{cmd: $sub, positional: ($positionals | get 0?), nocapture: $nocapture}
|
||||
}
|
||||
@@ -553,51 +534,49 @@ def parse-script-args [args: list<string>] {
|
||||
# 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 prefix = $"($RUNNER) "
|
||||
let defined = (
|
||||
scope commands
|
||||
| where {|c| $c.name == $RUNNER or ($c.name | str starts-with $prefix)}
|
||||
| get name
|
||||
| where {|n| $n != $RUNNER}
|
||||
| each {|n| $n | str substring ($prefix | str length).. }
|
||||
)
|
||||
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?)
|
||||
# The entry point is `dev-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 [$RUNNER "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")
|
||||
$problems = ($problems | append $"table lists '($name)' but there is no '($RUNNER) ($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 cmd = (scope commands | where name == $"($RUNNER) ($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)")
|
||||
$problems = ($problems | append $"flags of '($RUNNER) ($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)")
|
||||
}
|
||||
$problems = ($problems | append $"command '($RUNNER) ($name)' is not in the command table")
|
||||
}
|
||||
}
|
||||
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 ($footer | str contains "shell builtin") or ($footer | str contains "builtin test") {
|
||||
$problems = ($problems | append "help still warns about the test builtin")
|
||||
}
|
||||
if not ($footer | str contains "nu dev/test.nu completions") {
|
||||
$problems = ($problems | append "help does not show 'nu dev/test.nu completions'")
|
||||
if not ($footer | str contains $"nu ($SCRIPT_REL) completions") {
|
||||
$problems = ($problems | append $"help does not show 'nu ($SCRIPT_REL) completions'")
|
||||
}
|
||||
# `(...)` in a double-quoted string runs the command; that would inline the script.
|
||||
if ($footer | str contains "#compdef") or ($footer | str contains "complete -F") {
|
||||
$problems = ($problems | append "help footer embeds a completion script; quote the <(...) example literally")
|
||||
}
|
||||
$problems
|
||||
}
|
||||
@@ -666,11 +645,11 @@ def check-dispatch [] {
|
||||
}
|
||||
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)")
|
||||
$problems = ($problems | append $"CLI '($RUNNER) 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 = ($problems | append $"CLI '($RUNNER) integration a b' exit ($extra.exit_code): ($extra.stderr | str trim)")
|
||||
}
|
||||
$problems
|
||||
}
|
||||
@@ -687,8 +666,8 @@ def check-filter-cache [] {
|
||||
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 first = (nu-complete dev-test filters)
|
||||
let second = (nu-complete dev-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 { "" })
|
||||
@@ -697,7 +676,7 @@ def check-filter-cache [] {
|
||||
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 third = (nu-complete dev-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}
|
||||
})
|
||||
@@ -756,78 +735,204 @@ def check-kvm-step [] {
|
||||
[]
|
||||
}
|
||||
|
||||
def check-shell-wrapper [] {
|
||||
# Words after a `TAG:` line, dropping the `--` that ends compadd's options.
|
||||
def tagged-words [text: string, tag: string] {
|
||||
let line = ($text | lines | where {|l| $l | str starts-with $"($tag):"} | get 0?)
|
||||
if $line == null {
|
||||
return []
|
||||
}
|
||||
$line
|
||||
| str substring ($"($tag):" | str length)..
|
||||
| split row " "
|
||||
| where {|w| not ($w | is-empty) and $w != "--" }
|
||||
}
|
||||
|
||||
def check-shell-completion [] {
|
||||
mut problems = []
|
||||
let dir = ($nu.temp-dir | path join $"runner-wrap-($nu.pid)")
|
||||
let dir = ($nu.temp-dir | path join $"runner-complete-($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) {
|
||||
let subcommands = ($command_table | get name)
|
||||
for shell in (nu-complete dev-test shells) {
|
||||
let script = (completion-script $shell)
|
||||
let file = ($dir | path join $"completions.($shell)")
|
||||
$script | save -f $file
|
||||
if ($script | str contains "builtin") {
|
||||
$problems = ($problems | append $"($shell) completion still mentions the test builtin")
|
||||
}
|
||||
let wrappers = ($script | lines | where {|l| $l =~ '^(test|dev-test)\(\)' })
|
||||
if not ($wrappers | is-empty) {
|
||||
$problems = ($problems | append $"($shell) completion defines a command function")
|
||||
}
|
||||
if not ($script | str contains $COMP_FN) or not ($script | str contains $RUNNER) {
|
||||
$problems = ($problems | append $"($shell) completion does not register ($COMP_FN) for ($RUNNER)")
|
||||
}
|
||||
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)")
|
||||
let syntax_args = (if $shell == "zsh" { ["-f" "-n" $file] } else { ["--noprofile" "--norc" "-n" $file] })
|
||||
let syntax = (run-external $shell ...$syntax_args | complete)
|
||||
if $syntax.exit_code != 0 {
|
||||
$problems = ($problems | append $"($shell) completion script does not parse: ($syntax.stderr | str trim)")
|
||||
continue
|
||||
}
|
||||
if not ($out.stdout | str contains $"($SCRIPT_PATH) unit") {
|
||||
$problems = ($problems | append $"($shell) did not dispatch 'test unit': ($out.stdout)")
|
||||
let probe = ($dir | path join $"probe.($shell)")
|
||||
let body = (if $shell == "zsh" {
|
||||
[
|
||||
$"source '($file)'"
|
||||
"typeset -a got"
|
||||
'compadd() { got+=("$*"); }'
|
||||
("words=(" + $RUNNER + " '')")
|
||||
"CURRENT=2"
|
||||
$COMP_FN
|
||||
'print -r -- "SUB:${got[*]}"'
|
||||
"got=()"
|
||||
("words=(" + $RUNNER + " vm '')")
|
||||
"CURRENT=3"
|
||||
$COMP_FN
|
||||
'print -r -- "VM:${got[*]}"'
|
||||
"got=()"
|
||||
("words=(" + $RUNNER + " integration '')")
|
||||
"CURRENT=3"
|
||||
$"($COMP_FN)"
|
||||
'print -r -- "FLAG:${got[*]}"'
|
||||
"funcs="
|
||||
'(( $+functions[dev-test] )) && funcs="${funcs}dev-test"'
|
||||
'(( $+functions[test] )) && funcs="${funcs} test"'
|
||||
'print -r -- "FUNCS:${funcs}"'
|
||||
]
|
||||
} else {
|
||||
[
|
||||
$"source '($file)'"
|
||||
("COMP_WORDS=(" + $RUNNER + " '')")
|
||||
"COMP_CWORD=1"
|
||||
$COMP_FN
|
||||
'printf "SUB:%s\n" "${COMPREPLY[*]}"'
|
||||
("COMP_WORDS=(" + $RUNNER + " vm '')")
|
||||
"COMP_CWORD=2"
|
||||
$COMP_FN
|
||||
'printf "VM:%s\n" "${COMPREPLY[*]}"'
|
||||
("COMP_WORDS=(" + $RUNNER + " integration '')")
|
||||
"COMP_CWORD=2"
|
||||
$COMP_FN
|
||||
'printf "FLAG:%s\n" "${COMPREPLY[*]}"'
|
||||
"funcs="
|
||||
'declare -F dev-test >/dev/null && funcs="${funcs}dev-test"'
|
||||
'declare -F test >/dev/null && funcs="${funcs} test"'
|
||||
'printf "FUNCS:%s\n" "$funcs"'
|
||||
]
|
||||
})
|
||||
$body | str join (char nl) | save -f $probe
|
||||
let args = (if $shell == "zsh" { ["-f" $probe] } else { ["--noprofile" "--norc" $probe] })
|
||||
let out = (run-external $shell ...$args | complete)
|
||||
if $out.exit_code != 0 {
|
||||
$problems = ($problems | append $"($shell) completion probe exited ($out.exit_code): ($out.stderr | str trim) ($out.stdout | str trim)")
|
||||
continue
|
||||
}
|
||||
if ($out.stdout | str contains $"($SCRIPT_PATH) -f") {
|
||||
$problems = ($problems | append $"($shell) sent POSIX test to the runner: ($out.stdout)")
|
||||
let sub_words = (tagged-words $out.stdout "SUB")
|
||||
if ($sub_words | is-empty) {
|
||||
$problems = ($problems | append $"($shell) completion output is empty: ($out.stdout | str trim)")
|
||||
}
|
||||
if not ($out.stdout | str contains "POSIX:0") {
|
||||
$problems = ($problems | append $"($shell) POSIX test -f failed: ($out.stdout) ($out.stderr)")
|
||||
for name in $subcommands {
|
||||
if $name not-in $sub_words {
|
||||
$problems = ($problems | append $"($shell) completion missing '($name)': ($sub_words | str join ' ')")
|
||||
}
|
||||
}
|
||||
let vm_words = (tagged-words $out.stdout "VM")
|
||||
if ("vm" not-in $vm_words) or ("peers" not-in $vm_words) {
|
||||
$problems = ($problems | append $"($shell) vm completion is ($vm_words | str join ' ')")
|
||||
}
|
||||
let flag_words = (tagged-words $out.stdout "FLAG")
|
||||
if "--nocapture" not-in $flag_words {
|
||||
$problems = ($problems | append $"($shell) integration completion is ($flag_words | str join ' ')")
|
||||
}
|
||||
let funcs = (tagged-words $out.stdout "FUNCS")
|
||||
if not ($funcs | is-empty) {
|
||||
$problems = ($problems | append $"($shell) defined a command function: ($funcs | str join ' ')")
|
||||
}
|
||||
}
|
||||
rm -rf $dir
|
||||
$problems
|
||||
}
|
||||
|
||||
# Cursor sits just after `marker` in the raw file, before any trailing newline.
|
||||
def complete-at [body: string, marker: string] {
|
||||
let file = ($nu.temp-dir | path join $"dev-test-ide-($nu.pid)-($marker | str replace ' ' '_').nu")
|
||||
$body | save -f $file
|
||||
let raw = (open --raw $file)
|
||||
let idx = ($raw | str index-of $marker)
|
||||
let pos = (if $idx == null or $idx < 0 { -1 } else { $idx + ($marker | str length) })
|
||||
let got = (if $pos < 0 {
|
||||
{stdout: "", stderr: "marker not found", exit_code: 1}
|
||||
} else {
|
||||
run-external "nu" "--no-config-file" "--ide-complete" ($pos | into string) $file | complete
|
||||
})
|
||||
rm -f $file
|
||||
let comps = (if $got.exit_code != 0 {
|
||||
[]
|
||||
} else {
|
||||
try { $got.stdout | from json | get completions } catch { [] }
|
||||
})
|
||||
{pos: $pos, comps: $comps, stdout: $got.stdout, stderr: $got.stderr, exit_code: $got.exit_code}
|
||||
}
|
||||
|
||||
def check-nu-completions [] {
|
||||
mut problems = []
|
||||
let sub = (complete-at $"use ($SCRIPT_PATH) *\n($RUNNER) " $"($RUNNER) ")
|
||||
let want = ($command_table | get name | each {|n| $"($RUNNER) ($n)" })
|
||||
let missing = ($want | where {|n| $n not-in $sub.comps })
|
||||
if ($sub.comps | is-empty) or ("alias" in $sub.comps) or (not ($missing | is-empty)) or (($sub.comps | length) != ($want | length)) {
|
||||
$problems = ($problems | append $"nushell completion output is empty or wrong at ($sub.pos): ($sub.comps | to json -r) ($sub.stderr | str trim)")
|
||||
}
|
||||
let vm = (complete-at $"use ($SCRIPT_PATH) *\n($RUNNER) vm " $"($RUNNER) vm ")
|
||||
if ($vm.comps | is-empty) or ("vm" not-in $vm.comps) or ("peers" not-in $vm.comps) or ("alias" in $vm.comps) {
|
||||
$problems = ($problems | append $"nushell vm completion is empty or wrong: ($vm.comps | to json -r)")
|
||||
}
|
||||
$problems
|
||||
}
|
||||
|
||||
def check-docs [] {
|
||||
mut problems = []
|
||||
let rel = $"nu ($SCRIPT_REL) completions"
|
||||
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'")
|
||||
if ($text | str contains "dev/test.nu") {
|
||||
$problems = ($problems | append $"($f) still names dev/test.nu")
|
||||
}
|
||||
if ($text | str contains "shell builtin") or ($text | str contains "builtin test") {
|
||||
$problems = ($problems | append $"($f) still documents the test builtin workaround")
|
||||
}
|
||||
if ($text | str contains "devenv shell -- test") {
|
||||
$problems = ($problems | append $"($f) still invokes 'devenv shell -- test'")
|
||||
}
|
||||
}
|
||||
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 $rel) {
|
||||
$problems = ($problems | append $"($f) does not show '($rel)'")
|
||||
}
|
||||
if not ($text | str contains "builtin") {
|
||||
$problems = ($problems | append $"($f) does not mention the test builtin")
|
||||
if not ($text | str contains $"devenv shell -- ($RUNNER)") {
|
||||
$problems = ($problems | append $"($f) does not show 'devenv shell -- ($RUNNER)'")
|
||||
}
|
||||
}
|
||||
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 'scripts."dev-test"') {
|
||||
$problems = ($problems | append "devenv.nix does not define scripts.\"dev-test\"")
|
||||
}
|
||||
if not ($hook | str contains "completions bash") {
|
||||
if ($hook | str contains "scripts.test") {
|
||||
$problems = ($problems | append "devenv.nix still defines scripts.test")
|
||||
}
|
||||
if not ($hook | str contains $"($SCRIPT_REL) 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 = ($problems | append "enterShell completion is not limited to interactive shells")
|
||||
}
|
||||
if ($hook | str contains 'echo "') {
|
||||
$problems = ($problems | append "enterShell prints; non-interactive stdout must stay the command's own output")
|
||||
}
|
||||
$problems
|
||||
}
|
||||
Reference in new issue
Block a user