Skip to content

Commit

Permalink
Merge pull request NixOS#10799 from hercules-ci/safer-tab-completion
Browse files Browse the repository at this point in the history
Add repl completion test

(cherry picked from commit 1e2b267)

Change-Id: Ic3de39e71960a05a8676190b1ec9a7f0bb6057f5
Signed-off-by: Jörg Thalheim <[email protected]>
  • Loading branch information
roberth authored and Mic92 committed Jun 16, 2024
1 parent 4734ce7 commit b588a76
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@
}
);

# Completion tests for the Nix REPL.
repl-completion = forAllSystems (
system: nixpkgsFor.${system}.native.callPackage ./tests/repl-completion.nix { }
);

# Perl bindings for various platforms.
perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nix.passthru.perl-bindings);

Expand Down Expand Up @@ -330,6 +335,7 @@
rl-next = self.hydraJobs.rl-next.${system}.user;
# Will be empty attr set on i686-linux, and filtered out by forAvailableSystems.
pre-commit = self.hydraJobs.pre-commit.${system};
repl-completion = self.hydraJobs.repl-completion.${system};
}
// (lib.optionalAttrs (builtins.elem system linux64BitSystems)) {
dockerImage = self.hydraJobs.dockerImage.${system};
Expand Down
40 changes: 40 additions & 0 deletions tests/repl-completion.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ runCommand, nix, expect }:

# We only use expect when necessary, e.g. for testing tab completion in nix repl.
# See also tests/functional/repl.sh

runCommand "repl-completion" {
nativeBuildInputs = [
expect
nix
];
expectScript = ''
# Regression https://github.com/NixOS/nix/pull/10778
spawn nix repl --offline --extra-experimental-features nix-command
expect "nix-repl>"
send "foo = import ./does-not-exist.nix\n"
expect "nix-repl>"
send "foo.\t"
expect {
"nix-repl>" {
puts "Got another prompt. Good."
}
eof {
puts "Got EOF. Bad."
exit 1
}
}
exit 0
'';
passAsFile = [ "expectScript" ];
}
''
export NIX_STORE=$TMPDIR/store
export NIX_STATE_DIR=$TMPDIR/state
export HOME=$TMPDIR/home
mkdir $HOME
nix-store --init
expect $expectScriptPath
touch $out
''

0 comments on commit b588a76

Please sign in to comment.