2022-07-11 16:16:19 +03:00
|
|
|
|
source common.sh
|
|
|
|
|
|
|
|
|
|
cd "$TEST_ROOT"
|
|
|
|
|
|
2022-07-13 11:29:47 +03:00
|
|
|
|
mkdir -p dep
|
|
|
|
|
cat <<EOF > dep/flake.nix
|
2022-07-11 16:16:19 +03:00
|
|
|
|
{
|
|
|
|
|
outputs = i: { };
|
|
|
|
|
}
|
|
|
|
|
EOF
|
2022-07-13 11:29:47 +03:00
|
|
|
|
mkdir -p foo
|
|
|
|
|
cat <<EOF > foo/flake.nix
|
2022-07-11 16:16:19 +03:00
|
|
|
|
{
|
2022-07-13 11:29:47 +03:00
|
|
|
|
inputs.a.url = "path:$(realpath dep)";
|
2022-07-11 16:16:19 +03:00
|
|
|
|
|
|
|
|
|
outputs = i: {
|
|
|
|
|
sampleOutput = 1;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
EOF
|
2022-07-13 11:29:47 +03:00
|
|
|
|
mkdir -p bar
|
|
|
|
|
cat <<EOF > bar/flake.nix
|
|
|
|
|
{
|
|
|
|
|
inputs.b.url = "path:$(realpath dep)";
|
2022-07-11 16:16:19 +03:00
|
|
|
|
|
2022-07-13 11:29:47 +03:00
|
|
|
|
outputs = i: {
|
|
|
|
|
sampleOutput = 1;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
EOF
|
2022-11-03 11:11:28 +02:00
|
|
|
|
mkdir -p err
|
|
|
|
|
cat <<EOF > err/flake.nix
|
|
|
|
|
throw "error"
|
|
|
|
|
EOF
|
2022-07-11 16:16:19 +03:00
|
|
|
|
|
|
|
|
|
# Test the completion of a subcommand
|
2022-07-12 10:19:15 +03:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=1 nix buil)" == $'normal\nbuild\t' ]]
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=2 nix flake metad)" == $'normal\nmetadata\t' ]]
|
2022-07-11 16:16:19 +03:00
|
|
|
|
|
|
|
|
|
# Filename completion
|
2022-07-12 10:19:15 +03:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=2 nix build ./f)" == $'filenames\n./foo\t' ]]
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=2 nix build ./nonexistent)" == $'filenames' ]]
|
2022-07-11 16:16:19 +03:00
|
|
|
|
|
|
|
|
|
# Input override completion
|
2022-07-12 10:19:15 +03:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --override-input '')" == $'normal\na\t' ]]
|
2022-07-13 11:29:47 +03:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=5 nix flake show ./foo --override-input '')" == $'normal\na\t' ]]
|
|
|
|
|
## With multiple input flakes
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=5 nix build ./foo ./bar --override-input '')" == $'normal\na\t\nb\t' ]]
|
2022-07-12 10:37:57 +03:00
|
|
|
|
## With tilde expansion
|
|
|
|
|
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=4 nix build '~/foo' --override-input '')" == $'normal\na\t' ]]
|
2023-04-03 06:37:55 +03:00
|
|
|
|
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=5 nix flake show '~/foo' --update-input '')" == $'normal\na\t' ]]
|
|
|
|
|
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=4 nix run '~/foo' --update-input '')" == $'normal\na\t' ]]
|
2022-07-13 11:25:28 +03:00
|
|
|
|
## Out of order
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=3 nix build --update-input '' ./foo)" == $'normal\na\t' ]]
|
2022-07-13 11:29:47 +03:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --update-input '' ./bar)" == $'normal\na\t\nb\t' ]]
|
2022-07-11 16:16:19 +03:00
|
|
|
|
|
|
|
|
|
# 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
|
2022-07-12 10:19:15 +03:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=2 nix eval ./foo\#sam)" == $'attrs\n./foo#sampleOutput\t' ]]
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=4 nix eval --file ./foo/flake.nix outp)" == $'attrs\noutputs\t' ]]
|
2022-11-03 11:11:28 +02:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=4 nix eval --file ./err/flake.nix outp 2>&1)" == $'attrs' ]]
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=2 nix eval ./err\# 2>&1)" == $'attrs' ]]
|