-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdetection.sh
executable file
·51 lines (43 loc) · 1.36 KB
/
detection.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
#!/bin/sh
#NOTICE: Shell, not bash, so it runs on Alpine
set -e
file_or_folder="$1"
# detects failures or errors because xunit-viewer unfortunately does not report
# exits with non zero code if any error or failure is found
# uses simple grep to look for failures="0" and errors="0"
find_fail(){
target=$1
file=$2
suite_line=$(cat "$file" | grep "$target")
if echo "$suite_line" | grep -q -E "failures=\"[1-9]\\d*\""; then
echo "Failure(s) found in $file: $suite_line"
return 1
elif echo "$suite_line" | grep -q -E "errors=\"[1-9]\\d*\""; then
echo "Error(s) found in $file: $suite_line"
return 1
fi
}
suite_success(){
file="$1"
# look for 0 failures and errors
# grep reports non zero code if anything but zero failures/errors
plural="<testsuites "
singular="<testsuite "
if cat "$file" | grep "$plural";then
find_fail $plural $file
return $?
elif cat "$file" | grep "$singular";then
find_fail $singular $file
return $?
else
echo "Skipping file without suite: $file"
fi
}
echo "Inspecting '$file_or_folder'"
if [ -d "$file_or_folder" ];then
for file in $file_or_folder/*.xml ; do suite_success "$file"; done
elif [ -f "$file_or_folder" ]; then
suite_success "$file_or_folder"
else
echo "Skipping: No file or folder found at $file_or_folder"
fi