-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtmc_module.sh
executable file
·149 lines (124 loc) · 3.63 KB
/
tmc_module.sh
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
#!/bin/bash
usage="$(basename "$0") [-t] [-u] [-p='part1'] -- Program to run tests and/or update the TMC Module for exercises
Script goes through only following exercise structure:
osa1/01_hymio
osa1/02_ei_hymio
...
osa3/01_input_file
osa3/18_last_exercise
Where:
-t Runs tests for exercises
-u Updates TMC Module from tmc-python-tester repository
-p='part1' Applies only to given folder"
# Manually ignored folders if needed
ignored_dirs=("tmc-python-tester" ".vscode" "osax")
ignored_subdirs=("")
TEST=false
UPDATE=false
PART=""
for i in "$@"; do
case $i in
-t|--test)
TEST=true
shift
;;
-u|--update)
UPDATE=true
shift
;;
-p=*|--part=*)
PART="${i#*=}"
shift
;;
*)
echo "$usage" >&2
exit 1
;;
esac
done
if [[ "$UPDATE" = true ]]; then
git clone https://github.com/testmycode/tmc-python-tester.git
fi
for dir in *; do
# Only process directories
if [ ! -d "${dir}" ]; then
continue
fi
# Skip ignored directories
skip_dir=false
for ignored_dir in "${ignored_dirs[@]}"
do
if [[ $ignored_dir =~ $dir ]]; then
skip_dir=true
break
fi
done
if $skip_dir; then
continue
fi
# Filter by part argument, if given
if [[ "$PART" != "" && "$PART" != "$dir" ]]; then
continue
fi
# Go to part/osa folder
cd "${dir}" || exit
for subdir in *; do
# Only process directories
if [ ! -d "${subdir}" ]; then
continue
fi
# Skip ignored subdirectories
skip_subdir=false
for ignored_subdir in "${ignored_subdirs[@]}"
do
if [[ $ignored_subdir =~ $subdir ]]; then
skip_subdir=true
fi
done
if $skip_subdir; then
continue
fi
# Go to exercise folder under part
cd "${subdir}" || exit
if find . | grep -q ".tmcignore"; then
echo "Skipped update for ${dir}/${subdir} due to .tmcignore file."
# Leave exercise folder
cd ..
continue
fi
if [[ "$UPDATE" = true ]]; then
echo "Updating TMC Module for ${dir}/${subdir}."
rm -rf tmc/
cp -r ../../tmc-python-tester/tmc/ tmc/
fi
if [[ "$TEST" = true ]]; then
output=$( (python -m tmc) 2>&1 )
skipped=false
while [[ "$output" =~ "FAIL" || "$output" =~ "ERROR" ]]; do
python -m tmc
echo ""
echo "Some test failed after update for ${dir}/${subdir}, please fix failed tests."
read -n 1 -r -p "Press (s) to skip or any key to continue... " key
if [[ "$key" == "s" || "$key" == "S" ]]; then
skipped=true
git restore "tmc/."
echo ""
break
fi
output=$( (python -m tmc) 2>&1 )
done
if [[ "$skipped" = false ]]; then
echo "All tests passed for ${dir}/${subdir}."
fi
fi
# Go away from exercise folder
cd ..
done
# Away from part/osa folder
cd ..
done
if [[ "$UPDATE" = true ]]; then
echo "Removing cloned tmc-python-tester repo."
rm -rf tmc-python-tester
fi
echo "Make sure to run \`git add **/tmc/**\` to add the updated \`tmc\` module files without any files generated by the exercise tests."