-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexecute.bash
More file actions
executable file
·170 lines (158 loc) · 4.54 KB
/
Copy pathexecute.bash
File metadata and controls
executable file
·170 lines (158 loc) · 4.54 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
set -e
if test -n "$ZSH_VERSION"; then
PROFILE_SHELL=zsh
elif test -n "$BASH_VERSION"; then
PROFILE_SHELL=bash
elif test -n "$KSH_VERSION"; then
PROFILE_SHELL=ksh
elif test -n "$FCEDIT"; then
PROFILE_SHELL=ksh
elif test -n "$PS3"; then
PROFILE_SHELL=unknown
else
PROFILE_SHELL=sh
fi
if [ $PROFILE_SHELL != "bash" ]
then
echo "The following shell seems to be used ... "$PROFILE_SHELL
echo "However, it is best tested with bash shells! I wish you the best of luck :)"
else
echo "Great, you are using bash which is well-tested!"
fi
if [ -z $1 ]
then
function color {
"$@" 2> >(sed $'s,.*,\e[31m&\e[m,' 1>&2)
}
else
if [ $1 = "PDB" ]
then
function color {
"$@" 2> >(sed $'s,.*,\e[31m&\e[m,' 1>&2)
}
m4 --synclines -DLOCAL -DPDB Solution.py.m4 | tail -n +2 | ./sync_lines_after_m4.py > Solution.py
chmod +x Solution.py
color ./Solution.py < sample.txt
exit 0
else
color()(set -o pipefail; "$@" 2>/dev/null)
TEST="True"
fi
fi
if [[ -f Solution.py.m4 && -f ../template_problem_folder/Solution.py.m4 && ! -z $(diff Solution.py.m4 ../template_problem_folder/Solution.py.m4) ]]
then
echo "#####################################################################"
echo "Using Python solution..."
echo "#####################################################################"
if [ $TEST ]
then
exec="Solution_upload.py"
else
exec="Solution.py"
fi
m4 --synclines -DLOCAL Solution.py.m4 | tail -n +2 | ./sync_lines_after_m4.py > Solution.py
m4 --synclines Solution.py.m4 | tail -n +2 | ./sync_lines_after_m4.py > Solution_upload.py
chmod +x Solution.py
chmod +x Solution_upload.py
if [ -f local_testing_tool.py ]
then
i=0
ia_status=0
while [ $ia_status == 0 ]
do
set +e
time color ./interactive_runner.py python3 local_testing_tool.py $i -- ./$exec
ia_status=$?
set -e
i=$[i+1]
done
if [ $ia_status != 126 ]
then
exit $ia_status
fi
else
for sfile in sample*.txt
do
echo
echo
echo
echo
echo $sfile
rfile=$(sed 's/sample/result/' <(echo $sfile))
if [ -f $rfile ] && [ -n "$(cat $rfile)" ]
then
diffresult="$(echo "$(diff -Z <(time color ./$exec < $sfile) $rfile)")"
if [ -z "$diffresult" ]
then
:
else
echo "Did not produce the expected result! See diff for details:"
echo "$diffresult"
exit 1
fi
else
time color ./$exec < $sfile
fi
done
fi
fi
if [[ -f Main.cpp && -f ../template_problem_folder/Main.cpp && ! -z $(diff Main.cpp ../template_problem_folder/Main.cpp) ]]
then
echo "#####################################################################"
echo "Using C++ solution..."
echo "#####################################################################"
if [ $TEST ]
then
exec="Solution_upload"
g++-7 Main.cpp -std=c++14 -pthread -O3 -o Solution_upload
else
exec="Solution"
g++-7 Main.cpp -std=c++14 -pthread -O3 -o Solution -DLOCAL
fi
if [ -f local_testing_tool.py ]
then
i=0
ia_status=0
while [ $ia_status == 0 ]
do
set +e
time color ./interactive_runner.py python3 local_testing_tool.py $i -- ./$exec
ia_status=$?
set -e
i=$[i+1]
done
if [ $ia_status != 126 ]
then
exit $ia_status
fi
else
for sfile in sample*.txt
do
echo
echo
echo
echo
echo $sfile
rfile=$(sed 's/sample/result/' <(echo $sfile))
if [ -f $rfile ] && [ -n "$(cat $rfile)" ]
then
diffresult="$(echo "$(diff -Z <(time color ./$exec < $sfile) $rfile)")"
if [ -z "$diffresult" ]
then
:
else
echo "Did not produce the expected result! See diff for details:"
echo "$diffresult"
exit 1
fi
else
time color ./$exec < $sfile
fi
done
fi
fi
if [ ! $TEST ]
then
./execute.bash TEST
fi