-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_tests
executable file
·116 lines (97 loc) · 3.34 KB
/
sync_tests
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
#!/bin/bash
declare -A mappings
mappings=(
[parsetest]='syntax'
[sematest]='semantic'
)
declare -A suffixes
suffixes=(
# order matters for import matching
[invalid]='.invalid'
[valid]=''
)
our_testpath='test'
mjt_testpath='tests'
shopt -s globstar
edo() {
echo "${@}"
"${@}" || exit 100
}
_copy_if_different() {
local copied=1
if ! diff -q -N "${1}" "${2}" &> /dev/null; then
[[ -d ${2%/*} ]] || edo mkdir -p "${2%/*}"
edo cp -f "${1}" "${2}"
copied=0
fi
return ${copied}
}
_export_tests() {
local mjt=${1}
local mypath=${2}
local exported=0
for phase in "${!mappings[@]}"; do
for result in "${!suffixes[@]}"; do
for f in "${mypath}/${our_testpath}/${phase}/${result}/"*.java; do
base=${f##*/}
_copy_if_different "${f}" "${mjt}/${mjt_testpath}/${mappings[${phase}]}/${base%.java}${suffixes[${result}]}.mj" \
&& exported=1
done
done
done
for f in "${mypath}/${our_testpath}/exec/"*.java; do
base=${f##*/}
target="${mjt}/${mjt_testpath}/exec/${base}"
[[ -e ${target} ]] || target=${target%.java}.mj
_copy_if_different "${f}" "${target}" \
&& exported=1
done
for f in "${mypath}/${our_testpath}/testlib/lib/"**/*.java; do
base=${f#"${mypath}/${our_testpath}/testlib/"}
p="${mjt}/${mjt_testpath}/exec/${base%/*}"
[[ ${base%/*} != */* || -d ${p} ]] || edo mkdir -p "${p}"
_copy_if_different "${f}" "${mjt}/${mjt_testpath}/exec/${base}" \
&& exported=1
done
[[ ${exported} -gt 0 ]] && echo -e "\e[1;31m!!!\e[0m Exported tests, please add, commit and submit in mjtests"
}
_import_tests() {
local mjt=${1}
local mypath=${2}
local imported=0
for phase in "${!mappings[@]}"; do
for f in "${mjt}/${mjt_testpath}/${mappings[${phase}]}/"*.mj; do
for result in "${!suffixes[@]}"; do
base=${f##*/}
if [[ ${base} =~ .*"${suffixes[${result}]}.mj" ]]; then
_copy_if_different "${f}" "${mypath}/${our_testpath}/${phase}/${result}/${base%${suffixes[${result}]}.mj}.java" \
&& imported=1
break;
fi
done
done
done
for f in "${mjt}/${mjt_testpath}/exec/"*.{mj,java}; do
base=${f##*/}
_copy_if_different "${f}" "${mypath}/${our_testpath}/exec/${base%.*}.java" \
&& imported=1
done
for f in "${mjt}/${mjt_testpath}/exec/lib/"**/*.java; do
base=${f#"${mjt}/${mjt_testpath}/exec/"}
p="${mypath}/${our_testpath}/testlib/${base%/*}"
[[ ${base%/*} != */* || -d ${p} ]] || edo mkdir -p "${p}"
_copy_if_different "${f}" "${mypath}/${our_testpath}/testlib/${base}" \
&& imported=1
done
[[ ${imported} -gt 0 ]] && echo -e "\e[1;31m!!!\e[0m Imported tests, please add and commit"
}
_main() {
[[ ${#} -eq 1 && -d ${1} && -x ${1}/mjt.py ]] || { echo "Need to pass path to mjtest as the single argument"; exit 1; }
local dir=${1}
local mypath=${0%/*}
[[ -d ${mypath}/${our_testpath} ]] || { echo "Couldn't find our test dir. How did you run this script?"; exit 2; }
_import_tests "${dir}" "${mypath}"
_export_tests "${dir}" "${mypath}"
exit 0
}
_main "${@}"