at 23.05-pre 1.3 kB view raw
1#!/usr/bin/env bash 2set -euo pipefail 3shopt -s inherit_errexit 4 5# Use 6# || die 7die() { 8 echo >&2 "test case failed: " "$@" 9 exit 1 10} 11 12if test -n "${TEST_LIB:-}"; then 13 NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")" 14else 15 NIX_PATH=nixpkgs="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.."; pwd)" 16fi 17export NIX_PATH 18 19work="$(mktemp -d)" 20clean_up() { 21 rm -rf "$work" 22} 23trap clean_up EXIT 24cd "$work" 25 26touch {README.md,module.o,foo.bar} 27 28# nix-instantiate doesn't write out the source, only computing the hash, so 29# this uses the experimental nix command instead. 30 31dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${ 32 cleanSource ./. 33}")')" 34(cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF 35. 36./foo.bar 37./README.md 38EOF 39) || die "cleanSource 1" 40 41 42dir="$(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 46. 47./module.o 48./README.md 49EOF 50) || die "cleanSourceWith 1" 51 52dir="$(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 56. 57./README.md 58EOF 59) || die "cleanSourceWith + cleanSource" 60 61echo >&2 tests ok