openvswitch: generalize builder
[NixPkgs.git] / lib / tests / sources.sh
bloba7f490a79d74464aeea4fcba5b03465e0b0445e6
1 #!/usr/bin/env bash
2 set -euo pipefail
3 shopt -s inherit_errexit
5 # Use
6 # || die
7 die() {
8 echo >&2 "test case failed: " "$@"
9 exit 1
12 if test -n "${TEST_LIB:-}"; then
13 NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")"
14 else
15 NIX_PATH=nixpkgs="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.."; pwd)"
17 export NIX_PATH
19 work="$(mktemp -d)"
20 clean_up() {
21 rm -rf "$work"
23 trap clean_up EXIT
24 cd "$work"
26 touch {README.md,module.o,foo.bar}
28 # nix-instantiate doesn't write out the source, only computing the hash, so
29 # this uses the experimental nix command instead.
31 dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${
32 cleanSource ./.
33 }")')"
34 (cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF
36 ./foo.bar
37 ./README.md
38 EOF
39 ) || die "cleanSource 1"
42 dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${
43 cleanSourceWith { src = '"$work"'; filter = path: type: ! hasSuffix ".bar" path; }
44 }")')"
45 (cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF
47 ./module.o
48 ./README.md
49 EOF
50 ) || die "cleanSourceWith 1"
52 dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${
53 cleanSourceWith { src = cleanSource '"$work"'; filter = path: type: ! hasSuffix ".bar" path; }
54 }")')"
55 (cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF
57 ./README.md
58 EOF
59 ) || die "cleanSourceWith + cleanSource"
61 echo >&2 tests ok