From 8282c60d742dc6725723370249a341a944575d6c Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sun, 25 Feb 2018 16:33:17 -0600 Subject: [PATCH] tests: test nix search behavior --- tests/local.mk | 3 ++- tests/search.nix | 25 +++++++++++++++++++++++++ tests/search.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/search.nix create mode 100644 tests/search.sh diff --git a/tests/local.mk b/tests/local.mk index ec7ebfb0..9df0adf1 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -24,7 +24,8 @@ nix_tests = \ brotli.sh \ pure-eval.sh \ check.sh \ - plugins.sh + plugins.sh \ + search.sh # parallel.sh install-tests += $(foreach x, $(nix_tests), tests/$(x)) diff --git a/tests/search.nix b/tests/search.nix new file mode 100644 index 00000000..fea6e7a7 --- /dev/null +++ b/tests/search.nix @@ -0,0 +1,25 @@ +with import ./config.nix; + +{ + hello = mkDerivation rec { + name = "hello-${version}"; + version = "0.1"; + buildCommand = "touch $out"; + meta.description = "Empty file"; + }; + foo = mkDerivation rec { + name = "foo-5"; + buildCommand = '' + mkdir -p $out + echo ${name} > $out/${name} + ''; + }; + bar = mkDerivation rec { + name = "bar-3"; + buildCommand = '' + echo "Does not build successfully" + exit 1 + ''; + meta.description = "broken bar"; + }; +} diff --git a/tests/search.sh b/tests/search.sh new file mode 100644 index 00000000..53a69a0b --- /dev/null +++ b/tests/search.sh @@ -0,0 +1,42 @@ +source common.sh + +clearStore +clearCache + +# No packages +(( $(NIX_PATH= nix search -u|wc -l) == 0 )) + +# Haven't updated cache, still nothing +(( $(nix search -f search.nix hello|wc -l) == 0 )) +(( $(nix search -f search.nix |wc -l) == 0 )) + +# Update cache, search should work +(( $(nix search -f search.nix -u hello|wc -l) > 0 )) + +# Use cache +(( $(nix search -f search.nix foo|wc -l) > 0 )) +(( $(nix search foo|wc -l) > 0 )) + +# Test --no-cache works +# No results from cache +(( $(nix search --no-cache foo |wc -l) == 0 )) +# Does find results from file pointed at +(( $(nix search -f search.nix --no-cache foo |wc -l) > 0 )) + +# Check descriptions are searched +(( $(nix search broken | wc -l) > 0 )) + +# Check search that matches nothing +(( $(nix search nosuchpackageexists | wc -l) == 0 )) + + +## Search expressions + +# Check that empty search string matches all +EMPTY=$(nix search) +BOL=$(nix search "^") +ALL=$(nix search ".*") + +diff <(printf "%s" $EMPTY) <(printf "%s" $BOL) +# "ALL" highlights differently, not sure preferred behavior +# diff <(printf "%s" $EMPTY) <(printf "%s" $ALL)