3 # Tests lib/sources.nix
5 # [nixpkgs]$ lib/tests/sources.sh
7 # [nixpkgs]$ nix-build lib/tests/release.nix
10 shopt -s inherit_errexit
15 echo >&2 "test case failed: " "$@"
19 if test -n "${TEST_LIB:-}"; then
20 NIX_PATH
=nixpkgs
="$(dirname "$TEST_LIB")"
22 NIX_PATH
=nixpkgs
="$(cd "$
(dirname "${BASH_SOURCE[0]}")/..
/..
"; pwd)"
33 # Crudely unquotes a JSON string by just taking everything between the first and the second quote.
34 # We're only using this for resulting /nix/store paths, which can't contain " anyways,
35 # nor can they contain any other characters that would need to be escaped specially in JSON
36 # This way we don't need to add a dependency on e.g. jq
41 touch {README.md
,module.o
,foo.bar
}
43 dir
="$(nix-instantiate --eval --strict --read-write-mode --json --expr '(with import <nixpkgs/lib>; "$
{
45 }")' | crudeUnquoteJSON)"
46 (cd "$dir"; find) |
sort -f |
diff -U10 - <(cat <<EOF
51 ) || die
"cleanSource 1"
54 dir
="$(nix-instantiate --eval --strict --read-write-mode --json --expr '(with import <nixpkgs/lib>; "$
{
55 cleanSourceWith
{ src
= '"$work"'; filter
= path
: type: ! hasSuffix
".bar" path
; }
56 }")' | crudeUnquoteJSON)"
57 (cd "$dir"; find) |
sort -f |
diff -U10 - <(cat <<EOF
62 ) || die
"cleanSourceWith 1"
64 dir
="$(nix-instantiate --eval --strict --read-write-mode --json --expr '(with import <nixpkgs/lib>; "$
{
65 cleanSourceWith
{ src
= cleanSource
'"$work"'; filter
= path
: type: ! hasSuffix
".bar" path
; }
66 }")' | crudeUnquoteJSON)"
67 (cd "$dir"; find) |
sort -f |
diff -U10 - <(cat <<EOF
71 ) || die
"cleanSourceWith + cleanSource"