Skip to content

Commit 803f3ca

Browse files
author
Aaron Roller
committed
refactor: extracted validation into function AM-415/rostests
1 parent cb84309 commit 803f3ca

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

detection.sh

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,31 @@ file_or_folder="$1"
1010
# uses simple grep to look for failures="0" and errors="0"
1111

1212

13+
find_fail(){
14+
target=$1
15+
file=$2
16+
suite_line=$(cat "$file" | grep "$target")
17+
if echo "$suite_line" | grep "failures=\"0\"";then
18+
if echo "$suite_line" | grep "errors=\"0\"";then
19+
return 0
20+
else
21+
echo "Error found in $file: $suite_line"
22+
return 1
23+
fi
24+
else
25+
echo "Failure found in $file: $suite_line"
26+
return 1
27+
fi
28+
}
1329
suite_success(){
1430
file="$1"
1531
# look for 0 failures and errors
1632
# grep reports non zero code if anything but zero failures/errors
17-
target="<testsuites "
18-
if cat "$file" | grep "$target";then
19-
suite_line=$(cat "$file" | grep "$target")
20-
if echo "$suite_line" | grep "failures=\"0\"";then
21-
if echo "$suite_line" | grep "errors=\"0\"";then
22-
return 0
23-
else
24-
echo "Error found in $file: $suite_line"
25-
return 1
26-
fi
27-
else
28-
echo "Failure found in $file: $suite_line"
29-
return 1
30-
fi
33+
plural="<testsuites "
34+
singular="<testsuite "
35+
if cat "$file" | grep "$plural";then
36+
find_fail $plural $file
37+
return $?
3138
else
3239
echo "Skipping file without suite: $file"
3340
fi

test/all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -e
77
test/one.sh test/success_fixture.xml 0
88
test/one.sh test/failure_fixture.xml 1
99
test/one.sh test/error_fixture.xml 1
10+
1011
test/one.sh test 1
1112
test/one.sh test/success 0
1213
test/one.sh test/failure 1
File renamed without changes.

0 commit comments

Comments
 (0)