diff options
author | Théophane Hufschmitt <theophane.hufschmitt@tweag.io> | 2022-07-11 15:16:19 +0200 |
---|---|---|
committer | Théophane Hufschmitt <theophane.hufschmitt@tweag.io> | 2022-07-12 09:24:31 +0200 |
commit | 32effccb51783a36ce88607a7a404083e84ab3c0 (patch) | |
tree | 5fecfc7094640e05792ded17ecf479da4c464378 /tests | |
parent | f071eb3702c7aa86fc1885321d73a3707ed702b6 (diff) |
Add some tests for the CLI completion
Diffstat (limited to 'tests')
-rw-r--r-- | tests/completions.sh | 48 | ||||
-rw-r--r-- | tests/local.mk | 1 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/completions.sh b/tests/completions.sh new file mode 100644 index 000000000..4d6beccf8 --- /dev/null +++ b/tests/completions.sh @@ -0,0 +1,48 @@ +source common.sh + +cd "$TEST_ROOT" + +mkdir -p dep && pushd dep +cat <<EOF > flake.nix +{ + outputs = i: { }; +} +EOF +popd +mkdir -p foo && pushd foo +cat <<EOF > flake.nix +{ + inputs.a.url = "path:$(realpath ../dep)"; + + outputs = i: { + sampleOutput = 1; + }; +} +EOF + +popd + +# Test the completion of a subcommand +[[ $(printf "normal\nbuild\t\n") == $(NIX_GET_COMPLETIONS=1 nix buil) ]] +[[ $(printf "normal\nmetadata\t\n") == $(NIX_GET_COMPLETIONS=2 nix flake metad) ]] + +# Filename completion +[[ $(printf "filenames\n./foo\t\n") == $(NIX_GET_COMPLETIONS=2 nix build ./f) ]] +[[ $(printf "filenames\n") == $(NIX_GET_COMPLETIONS=2 nix build ./nonexistent) ]] + +# Input override completion +[[ $(printf "normal\na\t\n") == $(NIX_GET_COMPLETIONS=4 nix build ./foo --override-input '') ]] + +# Cli flag completion +NIX_GET_COMPLETIONS=2 nix build --log-form | grep -- "--log-format" + +# Config option completion +## With `--option` +NIX_GET_COMPLETIONS=3 nix build --option allow-import-from | grep -- "allow-import-from-derivation" +## As a cli flag – not working atm +# NIX_GET_COMPLETIONS=2 nix build --allow-import-from | grep -- "allow-import-from-derivation" + + +# Attr path completions +[[ $(printf "attrs\n./foo#sampleOutput\t\n") == $(NIX_GET_COMPLETIONS=2 nix eval ./foo\#sam) ]] +[[ $(printf "attrs\noutputs\t\n") == $(NIX_GET_COMPLETIONS=4 nix eval --file ./foo/flake.nix outp) ]] diff --git a/tests/local.mk b/tests/local.mk index ae15c70f9..e0579f503 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -102,6 +102,7 @@ nix_tests = \ suggestions.sh \ store-ping.sh \ fetchClosure.sh \ + completion.sh \ impure-derivations.sh ifeq ($(HAVE_LIBCPUID), 1) |