about summary refs log tree commit diff
path: root/pkgs/build-support/trivial-builders/test.sh
blob: 3e21b0008155dc6cade991d876f69e8da966dff9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash

# -------------------------------------------------------------------------- #
#
#                         trivial-builders test
#
# -------------------------------------------------------------------------- #
#
#  This file can be run independently (quick):
#
#      $ pkgs/build-support/trivial-builders/test.sh
#
#  or in the build sandbox with a ~20s VM overhead
#
#      $ nix-build -A tests.trivial-builders
#
# -------------------------------------------------------------------------- #

# strict bash
set -euo pipefail

# debug
# set -x
# PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'

cd "$(dirname ${BASH_SOURCE[0]})"  # nixpkgs root

testDirectReferences() {
  expr="$1"
  diff -U3 \
    <(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeDirectReferencesToFile ($expr)")) \
    <(nix-store -q --references $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort)
}

testDirectReferences 'hello'
testDirectReferences 'figlet'
testDirectReferences 'writeText "hi" "hello"'
testDirectReferences 'writeText "hi" "hello ${hello}"'
testDirectReferences 'writeText "hi" "hello ${hello} ${figlet}"'



testClosure() {
  expr="$1"
  diff -U3 \
    <(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeReferencesToFile ($expr)")) \
    <(nix-store -q --requisites $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort)
}

testClosure 'hello'
testClosure 'figlet'
testClosure 'writeText "hi" "hello"'
testClosure 'writeText "hi" "hello ${hello}"'
testClosure 'writeText "hi" "hello ${hello} ${figlet}"'


echo 'OK!'