-
Notifications
You must be signed in to change notification settings - Fork 0
/
luatest_auto.sh
executable file
·64 lines (51 loc) · 1.5 KB
/
luatest_auto.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
#!/bin/bash
if ! [[ -f /tmp/luatest_auto.txt ]]; then
echo "Error: luatest_auto.txt is not present"
exit 1
fi
rm -f /tmp/luatest_auto.work.txt
mv /tmp/luatest_auto.txt /tmp/luatest_auto.work.txt
fileline=`head -n 1 /tmp/luatest_auto.work.txt`
value=`tail -n +2 /tmp/luatest_auto.work.txt`
if [[ "$value" == "" ]]; then
echo "Error: no value"
exit 1
fi
if [[ `echo "$value" | wc -l` -ne 1 ]]; then
echo "Error: value is not one-line"
exit 1
fi
value=$(echo "$value" | sed 's/\//\\\//g')
value=$(echo "$value" | sed 's/\[/\{/g')
value=$(echo "$value" | sed 's/\]/\}/g')
value=$(echo "$value" | sed -E "s/\{'([^']+)'\:/\{\1 =/g")
value=$(echo "$value" | sed -E "s/, '([^']+)'\:/, \1 =/g")
if ! [[ $value =~ ^.*\'.*$ ]]; then
value=$(echo "$value" | sed "s/\"/'/g")
fi
if ! [[ "$fileline" =~ ^@(.*):([0-9]+)$ ]]; then
echo "Error: Filed to parse filename and line"
exit 1
fi
filename=${BASH_REMATCH[1]}
fileline=${BASH_REMATCH[2]}
if ! [[ -f "$filename" ]]; then
echo "Error: test file was not found"
exit 1
fi
if ! [[ -d /tmp/luatest_auto ]]; then
mkdir /tmp/luatest_auto
fi
if ! [[ -f /tmp/luatest_auto/i ]]; then
echo 0 > /tmp/luatest_auto/i
fi
i=`cat /tmp/luatest_auto/i`
tmp_file=`printf %02d $i`
tmp_file="/tmp/luatest_auto/backup$tmp_file"
((i=(i+1)%100))
echo $i > /tmp/luatest_auto/i
rm -f $tmp_file
mv "$filename" "$tmp_file"
((before=fileline-1))
head -n $before "$tmp_file" > "$filename"
tail -n "+$fileline" "$tmp_file" | sed -z "s/\"auto\"/$value/" >> "$filename"