2024-05-28 16:43:04 +00:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
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-11-03 09:11:28 +00:00
|
|
|
|
mkdir -p err
|
|
|
|
|
cat <<EOF > err/flake.nix
|
|
|
|
|
throw "error"
|
|
|
|
|
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' ]]
|
2023-10-24 20:22:05 +00:00
|
|
|
|
cd ./foo
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=3 nix flake update '')" == $'normal\na\t' ]]
|
|
|
|
|
cd ..
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=5 nix flake update --flake './foo' '')" == $'normal\na\t' ]]
|
2022-07-13 08:29:47 +00:00
|
|
|
|
## 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' ]]
|
2023-08-12 18:51:19 +00:00
|
|
|
|
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=5 nix flake update --flake '~/foo' '')" == $'normal\na\t' ]]
|
2022-07-13 08:25:28 +00:00
|
|
|
|
## Out of order
|
2023-08-12 18:51:19 +00:00
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=3 nix build --override-input '' '' ./foo)" == $'normal\na\t' ]]
|
|
|
|
|
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --override-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' ]]
|
2022-11-03 09:11:28 +00: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' ]]
|