-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
executable file
·150 lines (131 loc) · 3.88 KB
/
test
File metadata and controls
executable file
·150 lines (131 loc) · 3.88 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
#!/bin/bash
CPTOOL_DIR=`dirname $0`
source "$CPTOOL_DIR/util"
print_usage() {
echo "Test"
echo " test competitive programming solution. The program will compiled first if not yet compiled. The program will run"
echo " with provided testcases. The program will be killed if still running after some period of time, you can change"
echo " this behaviour using --timeout option."
echo ""
echo "Usage: cptool test [OPTION]... [LANGUAGE] SOLUTION TESTCASE_PREFIX"
echo ""
echo "Available commands:"
echo " -h --help Show this help screen."
echo " --version Show version."
echo " --hide-time Hide time indicator"
echo " -t, --timeout TIME Kill program if still running after TIME"
echo " TIME is a floating point number with an optional suffix:"
echo " 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days"
echo " The default value of this option is 10s"
echo " -s, --show-stdout Show program stdout in cli"
echo " -d, --show-diff Show program diff when test failed"
echo ""
}
test_solution() {
local language="$1"
local solution="$2"
local testcase_prefix="$3"
for testcase_in in "$testcase_prefix"*
do
if [[ ! "$testcase_in" == *.in ]]; then
continue
fi
local testcase=`basename "$testcase_in" .in`
local testcase_out="$testcase.out"
show_info running testcase "$testcase"
local output_file=`get_solution_test_path "$language" "$solution" "$testcase"`
local params="-t $TIMEOUT"
if [ $HIDE_TIME = true ]; then
local params=$params --hide-time
fi
mkdir -p `dirname "$output_file"`
$(. "$CPTOOL_DIR/run" $params "$language" "$solution" < "$testcase_in" > "$output_file" 2> /dev/null)
local status=$?
if [ ! $status -eq 0 ]; then
show_warning "program exited with return code $status"
fi
if [ -f "$testcase_out" ]; then
local diff_text
diff_text=`diff "$output_file" "$testcase_out"`
if [ $? -eq 0 ]; then
show_success test passed
else
show_error test failed
fi
if [ $SHOW_STDOUT = true ]; then
echo ""
echo "program stdout:"
cat "$output_file"
fi
if [ $SHOW_DIFF = true ]; then
echo ""
echo "output diffs:"
echo $diff_text
fi
else
show_warning skip comparing output file, "$testcase_out" doesn\'t exists
fi
echo ""
done
}
DEFAULT_LANGUAGE="cpp"
SHOW_STDOUT=false
SHOW_DIFF=false
HIDE_TIME=false
TIMEOUT=10s
LANGUAGE=""
SOLUTION=""
TESTCASE_PREFIX=""
parsing_options=true
parsing_timeout=false
if [ $# -eq 0 ]; then
print_usage
exit 0
fi
for arg in "$@"
do
if [ $parsing_options = true ]; then
if [ $parsing_timeout = true ]; then
parsing_timeout=false
TIMEOUT=$arg
elif [ $arg = "-h" ] || [ $arg = "--help" ]; then
print_usage
exit $?
elif [ $arg = "--version" ]; then
print_version
exit $?
elif [ $arg = "--hide-time" ]; then
HIDE_TIME=true
elif [ $arg = "-s" ] || [ $arg = "--show-stdout" ]; then
SHOW_STDOUT=true
elif [ $arg = "-d" ] || [ $arg = "--show-diff " ]; then
SHOW_DIFF=true
elif [ $arg = "-t" ] || [ $arg = "--timeout" ]; then
parsing_timeout=true
else
parsing_options=false
LANGUAGE="$arg"
fi
elif [ -z "$SOLUTION" ]; then
SOLUTION="$arg"
elif [ -z "$TESTCASE_PREFIX" ]; then
TESTCASE_PREFIX="$arg"
else
print_usage
exit 1
fi
done
if [ -z "$LANGUAGE" ]; then
show_error "please specify solution name."
print_usage
exit 1
elif [ -z "$SOLUTION" ]; then
show_error "please specify solution name."
print_usage
exit 1
elif [ -z "$TESTCASE_PREFIX" ]; then
TESTCASE_PREFIX="$SOLUTION"
SOLUTION="$LANGUAGE"
LANGUAGE="$DEFAULT_LANGUAGE"
fi
test_solution "$LANGUAGE" "$SOLUTION" "$TESTCASE_PREFIX"