-
Notifications
You must be signed in to change notification settings - Fork 2
/
Runfile
138 lines (116 loc) · 5.81 KB
/
Runfile
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
.SHELL = bash
##
# Runs benchmarks.
# OPTION NIX --nix Use a Nix-built test executable instead of compiling with cabal in the user's shell.
benchmarks:
set -eo pipefail
if [ -n "$NIX" ]; then
nix run ".#x86_64-unknown-linux-musl:codd:bench:codd-bench"
else
cabal run -O2 codd-bench
fi
##
# Runs all tests that CI runs, exactly like CI runs them.
ci-tests:
set -eo pipefail
echo "Testing install script posix compatibility"
shellcheck --shell=sh nix/install-codd.sh
echo "Running tests that don't depend on a database"
run test-no-db --nix
# Postgres-version dependent tests for each possible version next
# We test the last version with the vanilla nixpkgs-built derivation,
# not the IOHK one. We assume differences in the codebase regarding different
# postgres versions aren't enough to make it worth testing every version here too.
echo "Running all tests on Postgres 16 with nixpkgs's cabal2nix derivation of codd"
nix-build ./nix/install-codd-nixpkgs.nix --no-link -A coddWithCheck
run test-with-db --nix --pg 15
run test-with-db --nix --pg 14
run test-with-db --nix --pg 13
run test-with-db --nix --pg 12
echo "Running system-resources test"
run test-system-resources --nix
##
# Formats all Haskell files with fourmolu.
format-hs:
set -eo pipefail
readarray -d '' FILES < <(git ls-files -z '*.hs')
for f in "${FILES[@]}"; do
if [ "$f" = "src/Codd/Internal.hs" ]; then
echo "Skipping \"$f\" because of some fourmolu bug"
else
echo "Formatting $f..."
fourmolu --mode inplace "$f"
fi
done
##
# Runs a test without starting a postgresql DB for it. If no extra arguments are passed, special cases to running
# all tests that don't require a database.
# OPTION NIX --nix Use a Nix-built test executable instead of compiling with cabal in the user's shell.
# OPTION NONIXBUILD --nonixbuild Assume the test executable has already been build with Nix. Option used mostly internally.
# OPTION STRACE --strace Wrap test execution with strace. Useful for a very specific test or for debugging.
test-no-db:
set -eo pipefail
TARGS=( "$@" ) && [ -z "$1" ] && TARGS=(--skip /DbDependentSpecs/ --skip /SystemResourcesSpecs/)
STRACECMD=() && [ -n "$STRACE" ] && STRACECMD=(strace -f -e openat,open,close -o /tmp/strace-codd-system-resources-test.log)
if [ -n "$NIX" ]; then
# This Run command is used insire pure Nix shells where `nix` is not available. That's why
# this option is useful.
if [ -z "$NONIXBUILD" ]; then
nix build ".#x86_64-unknown-linux-musl:codd:test:codd-test" -o local/codd-test
fi
"${STRACECMD[@]}" ./local/codd-test/bin/codd-test "${TARGS[@]}"
else
cabal build -O0 codd-test
"${STRACECMD[@]}" `cabal list-bin -O0 codd-test` "${TARGS[@]}"
fi
##
# Runs a test in an environment where there is a postgresql DB listening. If no extra arguments are passed, special cases to running
# all tests that _do_ require a database.
# OPTION PG --pg <pg> The version of the postgresql instance to start or 'all'. Defaults to 16 if unspecified.
# OPTION NIX --nix Use a Nix-built test executable in a pure Nix shell instead of compiling with cabal in the user's shell.
test-with-db:
set -eo pipefail
[ -z "$PG" ] && PG=(16)
[ "${PG[0]}" = "all" ] && PG=(12 13 14 15 16)
NIXA=() && [ -n "$NIX" ] && NIXA=(--nix)
NIXDEVARGS=() && [ -n "$NIX" ] && NIXDEVARGS=(-i)
TARGS=(--match /DbDependentSpecs/) && [ -n "$1" ] && TARGS=("$@")
# Build the test executable only once with Nix
if [ -n "$NIX" ]; then
nix build ".#x86_64-unknown-linux-musl:codd:test:codd-test" -o local/codd-test
fi
for pg in "${PG[@]}"; do
echo "Running tests on Postgres $pg"
nix develop ".#testShells.x86_64-linux.pg${pg}" "${NIXDEVARGS[@]}" -c run test-with-db-internal "${NIXA[@]}" -- "${TARGS[@]}"
done
##
# Do not use this. Use the `test-with-db` command instead.
# OPTION NIX --nix Use a Nix-built test executable instead of compiling with cabal in the user's shell.
# OPTION STRACE --strace Wrap test execution with strace. Useful for a very specific test or for debugging.
test-with-db-internal:
set -eo pipefail
trap "echo Stopping postgres && pg_ctl stop" EXIT
NIXA=() && [ -n "$NIX" ] && NIXA=(--nix)
STRACEA=() && [ -n "$STRACE" ] && STRACEA=(--strace)
TARGS=(--skip /DbDependentSpecs/ --skip /SystemResourcesSpecs/) && [ -n "$1" ] && TARGS=("$@")
run test-no-db "${NIXA[@]}" "${STRACEA[@]}" --nonixbuild -- "${TARGS[@]}"
##
# Test that codd does not open more than one migration file or on-disk representation file simultaneously, so that it won't fail in shells or OS's with tight open file limits.
# OPTION NIX --nix Use a Nix-built test executable instead of compiling with cabal in the user's shell.
test-system-resources:
set -eo pipefail
if ! command -v strace &> /dev/null
then
echo strace could not be found. You need strace installed for this test.
exit 1
fi
rm -f /tmp/strace-codd-system-resources-test.log
trap "rm -f /tmp/strace-codd-system-resources-test.log" ERR EXIT
if [ -n "$NIX" ]; then
nix build ".#x86_64-unknown-linux-musl:codd:test:codd-test" -o local/codd-test
nix develop ".#testShells.x86_64-linux.pg16" -i -c run test-with-db-internal --strace --nix -- --match "/SystemResourcesSpecs/RUNNING"
nix develop ".#testShells.x86_64-linux.pg16" -i -c run test-with-db-internal --nix -- --match "/SystemResourcesSpecs/CHECKING"
else
nix develop ".#testShells.x86_64-linux.pg16" -c run test-with-db-internal --strace -- --match "/SystemResourcesSpecs/RUNNING"
nix develop ".#testShells.x86_64-linux.pg16" -c run test-with-db-internal -- --match "/SystemResourcesSpecs/CHECKING"
fi