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