-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·125 lines (104 loc) · 3.96 KB
/
run
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
#!/bin/sh
# ==============================================================================
# Setup of environment
# Temp files
config="$(mktemp)" # configuration
order="$(mktemp)" # order
compilation="$(mktemp)" # output of compilation
# Saving the configuration from stdin
cat > "$config"
# Directories containing the test files and the judge repository
resources="$(jq -r '.resources' < "$config")"
judge="$(jq -r '.judge' < "$config")"
workdir="$(jq -r '.workdir' < "$config")"
builddir="$(mktemp -d -p /dev/shm)"
trap "rm -rf '$config' '$order' '$compilation' '$execution' '$builddir'" EXIT
# Searching the environment
pkgdb="$(find "$HOME/.local/state/cabal/store" -name package.db -print -quit)"
# ==============================================================================
# Helper functions for JSON generation
dodona() { "$judge/dodona" "$@"; }
append_message() {
dodona append-message -f "$1" -p "$2" -d "$3"
}
# ==============================================================================
# Compiling and running tests.
# Let's get started
dodona start-judgement
# Compiling the judge code
cd "$judge"
if ! ghc -outputdir "$builddir" -package-db "$pkgdb" lib/*.hs > "$compilation" 2>&1; then
dodona append-message -f code -p staff -d "$(cat "$compilation")"
dodona close-judgement -A -e 'internal error' -h 'Compilatie judge mislukt'
exit 0
fi
# Create the Input.hs module, containing the submitted code
echo 'module Input where' > lib/Input.hs
cat "$(jq -r '.source' < "$config")" >> lib/Input.hs
cp "$(jq -r '.helper' < "$config")" . 2>/dev/null
# Lint the user code.
runghc -package-db --ghc-arg="$pkgdb" src/JSONLinter.hs lib/Input.hs
# Compiling the user code.
dodona start-tab -h -t 'compilatie'
dodona start-context -f code -d "ghc Input.hs"
if ! ghc -outputdir "$builddir" -package-db "$pkgdb" lib/*.hs > "$compilation" 2>&1; then
dodona append-message -f code -d "$(cat "$compilation")"
dodona close-context -A
dodona close-tab
dodona close-judgement -A -e 'compilation error' -h 'Compilatie mislukt'
exit 0
fi
dodona close-context
dodona close-tab
# Copy over non-testfiles
find "$resources" \
-name '*.hs' \
-not -name '*_test.hs' \
-not -name 'typecheck.hs' \
-exec cp \{\} lib \;
if [ -f "$resources/typecheck.hs" ]; then
dodona start-tab -h -t 'Typecheck'
echo 'module Typecheck where' > lib/Typecheck.hs
cat "$resources/typecheck.hs" >> lib/Typecheck.hs
if ! ghc -i"$builddir" -outputdir "$builddir" -package-db "$pkgdb" lib/*.hs > "$compilation" 2>&1; then
dodona start-context -f plain -d 'Compilatie'
dodona append-message -f code -d "$(cat "$compilation")"
dodona close-context -A
dodona close-tab
dodona close-judgement -A -e 'compilation error' -h 'Interface niet voldaan'
exit 0
fi
dodona close-tab
fi
# Compiling and running each test file.
if [ -f "$resources/ordered_tests" ]
then sed "s|^|$resources/|" < "$resources/ordered_tests" > "$order"
else echo "$resources"/*_test.hs > "$order"
fi
for testfile in $(cat "$order"); do
[ -f "$testfile" ] || continue
testbase="$(basename "$testfile")"
testname="${testbase%_test.hs}"
tabtitle="$(echo "$testname" | tr '_' ' ')"
# Compiling the test
dodona start-tab -p staff -h -t "$tabtitle"
cp "$testfile" src/Test.hs
if ! ghc -i"$builddir" -outputdir "$builddir" -package-db "$pkgdb" -c src/Test.hs > "$compilation" 2>&1; then
dodona start-context -f plain -d 'Compilatie'
dodona append-message -f code -d "$(cat "$compilation")"
dodona close-context -A
dodona close-tab
dodona close-judgement -A -e 'internal error' -h 'Testcompilatie gefaald'
exit 0
fi
dodona close-tab
# Running the test
dodona start-tab -t "$tabtitle"
set -e
cd "$workdir"
runghc -w -package-db --ghc-arg="$pkgdb" -i"$builddir":"$judge"/lib "$judge"/src/Test.hs
cd "$judge"
set +e
dodona close-tab
done
dodona close-judgement