Skip to content

Commit

Permalink
Add some tests for the CLI completion
Browse files Browse the repository at this point in the history
  • Loading branch information
thufschmitt committed Jul 11, 2022
1 parent df6fe6b commit c89fca8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/completions.sh
Original file line number Diff line number Diff line change
@@ -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) ]]
1 change: 1 addition & 0 deletions tests/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ nix_tests = \
suggestions.sh \
store-ping.sh \
fetchClosure.sh \
completion.sh \
impure-derivations.sh

ifeq ($(HAVE_LIBCPUID), 1)
Expand Down

0 comments on commit c89fca8

Please sign in to comment.