From 4b15ca2ffb710d96eb34ac47683abdd85d236f92 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 4 Mar 2024 16:07:03 +0100 Subject: [PATCH 1/3] add tests for showing help --- package.nix | 2 + tests/functional/help.sh | 79 +++++++++++++++++++++++++++++++++++++++ tests/functional/local.mk | 3 +- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tests/functional/help.sh diff --git a/package.nix b/package.nix index 20796a386..a90973b4c 100644 --- a/package.nix +++ b/package.nix @@ -24,6 +24,7 @@ , libgit2 , libseccomp , libsodium +, man , lowdown , mdbook , mdbook-linkcheck @@ -213,6 +214,7 @@ in { git mercurial openssh + man # for testing `nix-* --help` ] ++ lib.optionals (doInstallCheck || enableManual) [ jq # Also for custom mdBook preprocessor. ] ++ lib.optional stdenv.hostPlatform.isLinux util-linux diff --git a/tests/functional/help.sh b/tests/functional/help.sh new file mode 100644 index 000000000..74531c5d0 --- /dev/null +++ b/tests/functional/help.sh @@ -0,0 +1,79 @@ +source common.sh + +clearStore + +# test help output + +nix-build --help +nix-shell --help + +nix-env --help +nix-env --install --help +nix-env --upgrade --help +nix-env --uninstall --help +nix-env --set --help +nix-env --set-flag --help +nix-env --query --help +nix-env --switch-profile --help +nix-env --list-generations --help +nix-env --delete-generations --help +nix-env --switch-generation --help +nix-env --rollback --help + +nix-store --help +nix-store --realise --help +nix-store --serve --help +nix-store --gc --help +nix-store --delete --help +nix-store --query --help +nix-store --add --help +nix-store --add-fixed --help +nix-store --verify --help +nix-store --verify-path --help +nix-store --repair-path --help +nix-store --dump --help +nix-store --restore --help +nix-store --export --help +nix-store --import --help +nix-store --optimise --help +nix-store --read-log --help +nix-store --dump-db --help +nix-store --load-db --help +nix-store --print-env --help +nix-store --generate-binary-cache-key --help + +nix-channel --help +nix-collect-garbage --help +nix-copy-closure --help +nix-daemon --help +nix-hash --help +nix-instantiate --help +nix-prefetch-url --help + +function subcommands() { + jq -r ' +def recurse($prefix): + if .commands then + .commands | to_entries[] | .key as $k | + ($prefix + " " + $k) as $newPrefix | + if .value | has("commands") then + (.value | recurse($newPrefix)) + else + $newPrefix + end + else + $prefix + end; + +.args.commands | to_entries[] | .key as $cmd | + if .value | has("commands") then + (.value | recurse($cmd)) + else + $cmd + end +' +} + +nix __dump-cli | subcommands | while IFS= read -r cmd; do + nix $cmd --help +done diff --git a/tests/functional/local.mk b/tests/functional/local.mk index 18eb887cd..e36323a45 100644 --- a/tests/functional/local.mk +++ b/tests/functional/local.mk @@ -129,7 +129,8 @@ nix_tests = \ read-only-store.sh \ nested-sandboxing.sh \ impure-env.sh \ - debugger.sh + debugger.sh \ + help.sh ifeq ($(HAVE_LIBCPUID), 1) nix_tests += compute-levels.sh From 8a6ef3bae525e04b4cf5f460edf5a8e49cf8928f Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 4 Mar 2024 19:25:28 +0100 Subject: [PATCH 2/3] less scary jq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Théophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com> --- tests/functional/help.sh | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/functional/help.sh b/tests/functional/help.sh index 74531c5d0..868f5d2e9 100644 --- a/tests/functional/help.sh +++ b/tests/functional/help.sh @@ -53,24 +53,14 @@ nix-prefetch-url --help function subcommands() { jq -r ' def recurse($prefix): - if .commands then - .commands | to_entries[] | .key as $k | - ($prefix + " " + $k) as $newPrefix | - if .value | has("commands") then - (.value | recurse($newPrefix)) + to_entries[] | + ($prefix + [.key]) as $newPrefix | + (if .value | has("commands") then + ($newPrefix, (.value.commands | recurse($newPrefix))) else $newPrefix - end - else - $prefix - end; - -.args.commands | to_entries[] | .key as $cmd | - if .value | has("commands") then - (.value | recurse($cmd)) - else - $cmd - end + end); +.args.commands | recurse([]) | join(" ") ' } From 8d23847571c2921558cbcc7593de19e7a2edd944 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Mon, 4 Mar 2024 19:25:44 +0100 Subject: [PATCH 3/3] fix indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Théophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com> --- tests/functional/local.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/local.mk b/tests/functional/local.mk index e36323a45..8bb8e3600 100644 --- a/tests/functional/local.mk +++ b/tests/functional/local.mk @@ -130,7 +130,7 @@ nix_tests = \ nested-sandboxing.sh \ impure-env.sh \ debugger.sh \ - help.sh + help.sh ifeq ($(HAVE_LIBCPUID), 1) nix_tests += compute-levels.sh