forked from nix-community/crate2nix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.sh
executable file
·144 lines (131 loc) · 4.2 KB
/
run_tests.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
#
# Regenerates build files and runs tests on them.
# Please use this to validate your pull requests!
#
set -Eeuo pipefail
top="$(dirname "$0")"
top="$(cd "$top"; pwd)"
if [ -z "${IN_CRATE2NIX_SHELL:-}" ] || [ "${IN_NIX_SHELL:-}" = "impure" ]; then
export CACHIX
CACHIX="$(which cachix 2>/dev/null || echo "")"
echo -e "\e[1m=== Entering $top/shell.nix\e[0m" >&2
exec nix-shell --keep CACHIX --pure "$top/shell.nix" --run "$(printf "%q " "$0" "$@")"
fi
echo -e "\e[1m=== Parsing opts for $top/run_tests.sh\e[0m" >&2
options=$(getopt -o '' --long offline,build-test-nixpkgs:,no-cargo-build -- "$@") || {
echo "" >&2
echo "Available options:" >&2
echo " --offline Enable offline friendly operations with out substituters" >&2
echo " --build-test-nixpkgs Path to nixpkgs used for the build tests." >&2
echo " --no-cargo-build Skip local cargo build." >&2
exit 1
}
eval set -- "$options"
NIX_OPTIONS=( --option log-lines 100 --show-trace )
REGENERATE_OPTIONS=()
NIX_TESTS_OPTIONS=( --out-link ./target/nix-result )
NO_CARGO_BUILD=""
while true; do
case "$1" in
--no-cargo-build)
REGENERATE_OPTIONS+=( --no-cargo-build )
NO_CARGO_BUILD="1"
;;
--offline)
NIX_OPTIONS+=( --option substitute false )
REGENERATE_OPTIONS+=( --offline )
CACHIX=""
;;
--build-test-nixpkgs)
shift
NIX_TESTS_OPTIONS+=( --arg buildTestNixpkgs "$1" )
;;
--)
shift
break
;;
esac
shift
done
# Add other files when we adopt nixpkgs-fmt for them.
cd "$top"
echo -e "\e[1m=== Reformatting nix code\e[0m" >&2
./nixpkgs-fmt.sh \
./{,nix/}{,*/}*.nix \
./crate2nix/templates/nix/crate2nix/{*.nix,tests/*.nix} \
./sample_projects/*/[[:lower:]]*.nix
cd "$top"/crate2nix
echo "=== Reformatting rust code" >&2
../cargo.sh fmt
cd "$top"
echo -e "\e[1m=== Running nix unit tests\e[0m" >&2
./nix-test.sh ./crate2nix/templates/nix/crate2nix/tests/default.nix || {
echo "" >&2
echo "==================" >&2
echo "$top/nix-test.sh $top/crate2nix/templates/nix/crate2nix/tests/default.nix: FAILED" >&2
exit 1
}
cd "$top"/crate2nix
echo -e "\e[1m=== Running cargo clippy\e[0m" >&2
if [ -z "${NO_CARGO_BUILD}" ]; then
../cargo.sh clippy || {
echo "==================" >&2
echo "$top/cargo.sh clippy: FAILED" >&2
exit 2
}
else
echo "Skipping because of --no-cargo-build"
fi
../regenerate_cargo_nix.sh "${REGENERATE_OPTIONS[@]}" || {
echo "==================" >&2
echo "$top/regenerate_cargo_nix.sh ${REGENERATE_OPTIONS[*]}: FAILED" >&2
exit 3
}
echo -e "\e[1m=== Running cargo test\e[0m" >&2
if [ -z "${NO_CARGO_BUILD}" ]; then
../cargo.sh test || {
echo "==================" >&2
echo "$top/cargo.sh test: FAILED" >&2
exit 4
}
else
echo "Skipping because of --no-cargo-build"
fi
cd "$top"
echo -e "\e[1m=== Building ./tests.nix (= Running Integration Tests)\e[0m" >&2
rm -rf target/nix-result*
nix build -L "${NIX_OPTIONS[@]}" "${NIX_TESTS_OPTIONS[@]}" -f ./tests.nix || {
echo "==================" >&2
echo "cd $top" >&2
echo "nix build -L \\" >&2
echo " ${NIX_OPTIONS[*]} ${NIX_TESTS_OPTIONS[*]} \\" >&2
echo " -f ./tests.nix"
echo "=> FAILED" >&2
exit 5
}
echo -e "\e[1m=== Checking for uncomitted changes\e[0m" >&2
if test -n "$(git status --porcelain)"; then
echo ""
git --no-pager diff HEAD
echo ""
git --no-pager diff --stat HEAD
echo ""
git status --porcelain
echo ""
echo "!!! repository has uncomitted changes" >&2
echo "Otherwise, things look good :)"
exit 6
fi
# Crude hack: check if we have the right to push to the cache
cd "$top"
if test -n "${CACHIX:-}" && test -r ~/.config/cachix/cachix.dhall &&\
grep -q '"eigenvalue"' ~/.config/cachix/cachix.dhall; then
echo -e "\e[1m=== Pushing artifacts to eigenvalue.cachix.org \e[0m" >&2
# we filter for "rust_" to exclude some things that are in the
# nixos cache anyways
nix-store -q -R --include-outputs "$(nix-store -q -d target/nix-result* | grep -v crates.io)" |\
grep -e "-rust_" |\
$CACHIX push eigenvalue
fi
echo -e "\e[1m=== SUCCESS (run_tests.sh) \e[0m" >&2