-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some tests for the CLI completion #6784
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32effcc
Add some tests for the CLI completion
thufschmitt 260fb83
Fix the name of the completions test
thufschmitt 07e14d3
Harden the comparisons in the completion test
thufschmitt 21c443d
Test the tilde expansion for the flake completion
thufschmitt d34a333
Fix the “out of order” completion test
thufschmitt b052e7e
Add some more completion tests
thufschmitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
source common.sh | ||
|
||
cd "$TEST_ROOT" | ||
|
||
mkdir -p dep | ||
cat <<EOF > dep/flake.nix | ||
{ | ||
outputs = i: { }; | ||
} | ||
EOF | ||
mkdir -p foo | ||
cat <<EOF > foo/flake.nix | ||
{ | ||
inputs.a.url = "path:$(realpath dep)"; | ||
|
||
outputs = i: { | ||
sampleOutput = 1; | ||
}; | ||
} | ||
EOF | ||
mkdir -p bar | ||
cat <<EOF > bar/flake.nix | ||
{ | ||
inputs.b.url = "path:$(realpath dep)"; | ||
|
||
outputs = i: { | ||
sampleOutput = 1; | ||
}; | ||
} | ||
EOF | ||
|
||
# Test the completion of a subcommand | ||
[[ "$(NIX_GET_COMPLETIONS=1 nix buil)" == $'normal\nbuild\t' ]] | ||
[[ "$(NIX_GET_COMPLETIONS=2 nix flake metad)" == $'normal\nmetadata\t' ]] | ||
|
||
# Filename completion | ||
[[ "$(NIX_GET_COMPLETIONS=2 nix build ./f)" == $'filenames\n./foo\t' ]] | ||
[[ "$(NIX_GET_COMPLETIONS=2 nix build ./nonexistent)" == $'filenames' ]] | ||
|
||
# Input override completion | ||
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --override-input '')" == $'normal\na\t' ]] | ||
[[ "$(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' ]] | ||
## With tilde expansion | ||
[[ "$(HOME=$PWD NIX_GET_COMPLETIONS=4 nix build '~/foo' --override-input '')" == $'normal\na\t' ]] | ||
## Out of order | ||
[[ "$(NIX_GET_COMPLETIONS=3 nix build --update-input '' ./foo)" == $'normal\na\t' ]] | ||
[[ "$(NIX_GET_COMPLETIONS=4 nix build ./foo --update-input '' ./bar)" == $'normal\na\t\nb\t' ]] | ||
|
||
# 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 | ||
[[ "$(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' ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grep -q
maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like having the
grep
output for this kind of things since it's hidden by default but it gives a direct feedback as to whether the grep call found something or not when debugging (as it can be a bit tricky to understand which command exactly failed in the middle of a complex pipeline). Not that I have a very strong opinion about it thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither.