2021-02-06 02:15:33 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
2021-11-25 23:53:57 +03:00
|
|
|
shopt -s inherit_errexit
|
2021-02-06 02:15:33 +03:00
|
|
|
|
|
|
|
# Use
|
|
|
|
# || die
|
|
|
|
die() {
|
|
|
|
echo >&2 "test case failed: " "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if test -n "${TEST_LIB:-}"; then
|
2021-11-25 23:30:10 +03:00
|
|
|
NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")"
|
2021-02-06 02:15:33 +03:00
|
|
|
else
|
2021-11-25 23:36:42 +03:00
|
|
|
NIX_PATH=nixpkgs="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.."; pwd)"
|
2021-02-06 02:15:33 +03:00
|
|
|
fi
|
2021-11-25 23:30:10 +03:00
|
|
|
export NIX_PATH
|
2021-02-06 02:15:33 +03:00
|
|
|
|
|
|
|
work="$(mktemp -d)"
|
|
|
|
clean_up() {
|
|
|
|
rm -rf "$work"
|
|
|
|
}
|
|
|
|
trap clean_up EXIT
|
2021-11-25 23:36:42 +03:00
|
|
|
cd "$work"
|
2021-02-06 02:15:33 +03:00
|
|
|
|
|
|
|
touch {README.md,module.o,foo.bar}
|
|
|
|
|
|
|
|
# nix-instantiate doesn't write out the source, only computing the hash, so
|
|
|
|
# this uses the experimental nix command instead.
|
|
|
|
|
2021-11-04 02:19:30 +03:00
|
|
|
dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${
|
2021-02-06 02:15:33 +03:00
|
|
|
cleanSource ./.
|
|
|
|
}")')"
|
2021-11-25 23:36:42 +03:00
|
|
|
(cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF
|
2021-02-06 02:15:33 +03:00
|
|
|
.
|
|
|
|
./foo.bar
|
|
|
|
./README.md
|
|
|
|
EOF
|
|
|
|
) || die "cleanSource 1"
|
|
|
|
|
|
|
|
|
2021-11-04 02:19:30 +03:00
|
|
|
dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${
|
2021-02-06 02:15:33 +03:00
|
|
|
cleanSourceWith { src = '"$work"'; filter = path: type: ! hasSuffix ".bar" path; }
|
|
|
|
}")')"
|
2021-11-25 23:36:42 +03:00
|
|
|
(cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF
|
2021-02-06 02:15:33 +03:00
|
|
|
.
|
|
|
|
./module.o
|
|
|
|
./README.md
|
|
|
|
EOF
|
|
|
|
) || die "cleanSourceWith 1"
|
|
|
|
|
2021-11-04 02:19:30 +03:00
|
|
|
dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${
|
2021-02-06 02:15:33 +03:00
|
|
|
cleanSourceWith { src = cleanSource '"$work"'; filter = path: type: ! hasSuffix ".bar" path; }
|
|
|
|
}")')"
|
2021-11-25 23:36:42 +03:00
|
|
|
(cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF
|
2021-02-06 02:15:33 +03:00
|
|
|
.
|
|
|
|
./README.md
|
|
|
|
EOF
|
|
|
|
) || die "cleanSourceWith + cleanSource"
|
|
|
|
|
|
|
|
echo >&2 tests ok
|