Merge pull request #1906 from dtzWill/fix/nix-search
nix search: tests and fix #1893 and part of #1892
This commit is contained in:
commit
56f2ed0081
4 changed files with 71 additions and 2 deletions
|
@ -78,6 +78,11 @@ struct CmdSearch : SourceExprCommand, MixJSON
|
||||||
{
|
{
|
||||||
settings.readOnlyMode = true;
|
settings.readOnlyMode = true;
|
||||||
|
|
||||||
|
// Empty search string should match all packages
|
||||||
|
// Use "^" here instead of ".*" due to differences in resulting highlighting
|
||||||
|
// (see #1893 -- libc++ claims empty search string is not in POSIX grammar)
|
||||||
|
if (re.empty()) re = "^";
|
||||||
|
|
||||||
std::regex regex(re, std::regex::extended | std::regex::icase);
|
std::regex regex(re, std::regex::extended | std::regex::icase);
|
||||||
|
|
||||||
auto state = getEvalState();
|
auto state = getEvalState();
|
||||||
|
@ -234,7 +239,7 @@ struct CmdSearch : SourceExprCommand, MixJSON
|
||||||
throw Error("error writing to %s", tmpFile);
|
throw Error("error writing to %s", tmpFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)
|
if (writeCache && rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)
|
||||||
throw SysError("cannot rename '%s' to '%s'", tmpFile, jsonCacheFileName);
|
throw SysError("cannot rename '%s' to '%s'", tmpFile, jsonCacheFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ nix_tests = \
|
||||||
brotli.sh \
|
brotli.sh \
|
||||||
pure-eval.sh \
|
pure-eval.sh \
|
||||||
check.sh \
|
check.sh \
|
||||||
plugins.sh
|
plugins.sh \
|
||||||
|
search.sh
|
||||||
# parallel.sh
|
# parallel.sh
|
||||||
|
|
||||||
install-tests += $(foreach x, $(nix_tests), tests/$(x))
|
install-tests += $(foreach x, $(nix_tests), tests/$(x))
|
||||||
|
|
25
tests/search.nix
Normal file
25
tests/search.nix
Normal file
|
@ -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";
|
||||||
|
};
|
||||||
|
}
|
38
tests/search.sh
Normal file
38
tests/search.sh
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
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
|
||||||
|
nix search|grep -q foo
|
||||||
|
nix search|grep -q bar
|
||||||
|
nix search|grep -q hello
|
Loading…
Reference in a new issue