-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathtest-example
executable file
·94 lines (82 loc) · 2.83 KB
/
test-example
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
#!/bin/sh
if [ $# -eq 0 ]; then
echo "usage: $0 /path/to/exercise/example"
exit 1
fi
exampledir=$(cd "$1" && pwd)
examplename=$(basename "$exampledir")
if [ "$examplename" = "exemplar" ]; then
exercisedir=$(cd "$exampledir/../.." && pwd)
else
exercisedir=$(cd "$exampledir/../../.." && pwd)
fi
exercisename=$(basename "$exercisedir")
xhaskell=$(cd "$(dirname "$0")/.." && pwd)
# We would ideally use a tmpdir here,
# but stack will invalidate its cache if the path changes,
# so the best alternative seems to be to put it in xhaskell.
buildfolder="${xhaskell}/build/${exercisename}/${examplename}"
mkdir -p "${buildfolder}"
cleanup() {
rm -r "${xhaskell}/build"
}
trap cleanup EXIT INT TERM
cp -R -L \
${exercisedir}/stack.yaml \
${exercisedir}/test \
${exampledir}/* \
"${buildfolder}"
if [ -d ${exercisedir}/bench ]; then
cp -R -L ${exercisedir}/bench "${buildfolder}"
fi
cd $buildfolder
if [ -n "$GITHUB_ACTIONS" ]; then
cachedir="$HOME"
else
cachedir="$xhaskell"
fi
examplecache="${cachedir}/.foldercache/${exercisename}/${examplename}/.stack-work"
mkdir -p "$examplecache"
ln -f -s "$examplecache"
exampletype=$(echo "$examplename" | cut -d- -f1)
runstack () {
# SET_RESOLVER passed by GitHub Actions - sets --resolver if not current.
stack "$@" ${SET_RESOLVER} `# Select the correct resolver. `\
--install-ghc `# Download GHC if not in cache.`\
--no-terminal `# Terminal detection is broken.`\
--pedantic `# Enable -Wall and -Werror. `\
# --bench `# Build benchmarks, but `\
# --no-run-benchmarks `# do not run them. `
#
# We are temporarily disabling the benchmarks
# to speed up CI and try to stay below
# the 50 minutes limit.
}
if [ "$exampletype" = "success" -o "$exampletype" = "exemplar" ]; then
echo "testing ${exampledir} - should succeed"
# Implicit exit value: this is last thing in this path,
# so the script's exit value = stack's exit value.
# If statements are reordered, please preserve this property.
runstack "test"
elif [ "$exampletype" = "fail" ]; then
echo "testing ${exampledir} - should build, but fail tests"
if ! runstack "build"; then
echo "${exampledir} build failed unexpectedly"
exit 1
fi
if runstack "test"; then
echo "${exampledir} test succeeded unexpectedly"
exit 1
fi
elif [ "$exampletype" = "error" ]; then
echo "testing ${exampledir} - should fail to build"
if runstack "test" "--no-run-tests"; then
echo "${exampledir} build succeeded unexpectedly"
exit 1
else
rm -rf "${examplecache}"
fi
else
echo "unknown example type: ${exampledir}"
exit 1
fi