-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathvalidate_report_files.sh
More file actions
executable file
·68 lines (57 loc) · 2.02 KB
/
validate_report_files.sh
File metadata and controls
executable file
·68 lines (57 loc) · 2.02 KB
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
#!/usr/bin/env bash
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
GL_VALID=1
XSD_DIR="${SCRIPT_DIR}/xsd"
XML_JAR_DIR="${SCRIPT_DIR}/lib"
#XML Validator
XML_VALIDATOR="$XML_JAR_DIR/xml_validator.jar"
HTML_VALIDATOR_URL="http://localhost:8888/"
HTML_FILENAME="coverage.html"
declare -A XML_FILES
XML_FILES["junit_test_results.xml"]="junit4.xsd"
XML_FILES["tfs_test_results.xml"]="junit_windy.xsd"
function ValidateHtml {
EXCLUSION_REGEX=".*Element\s.?ol.?\snot\sallowed\sas\schild\sof\selement\s.?pre.*"
#HTML Validation API
VALIDATOR_OUT="gnu"
WARNING_REGEX="info warning:"
ERROR_REGEX="error:"
#Validate HTML
HTML_VALIDATION_RESULTS=$(curl -H "Content-Type: text/html; charset=utf-8" --data-binary @$1 "$HTML_VALIDATOR_URL?out=$VALIDATOR_OUT&filterpattern=$EXCLUSION_REGEX")
ERROR_COUNT=$(echo "$HTML_VALIDATION_RESULTS" | grep -c "$ERROR_REGEX")
WARNING_COUNT=$(echo "$HTML_VALIDATION_RESULTS" | grep -c "$WARNING_REGEX")
if [ "$ERROR_COUNT" -gt 0 ]; then
GL_VALID=0
echo ""
echo "******************************"
echo "HTML File is invalid"
echo "There are $ERROR_COUNT errors, $WARNING_COUNT warning in $HTML_FILENAME"
echo "Please see results:"
echo "$HTML_VALIDATION_RESULTS" | grep "$ERROR_REGEX"
fi
}
function ValidateXML() {
echo "Validate File $2 against schema $1"
VALIDATION_RESULT=$(java -jar $XML_VALIDATOR -s $1 $2 2>&1)
if [ $? -ne 0 ]; then
GL_VALID=0
echo ""
echo "******************************"
echo "XML is invalid"
echo "Please see results:"
echo "$VALIDATION_RESULT"
fi
}
ValidateHtml "$HTML_FILENAME"
for XMLFILE in "${!XML_FILES[@]}"; do
#echo "$XMLFILE" "${XML_FILES[$XMLFILE]}";
ValidateXML "$XSD_DIR/${XML_FILES[$XMLFILE]}" "$XMLFILE"
done
if [ $GL_VALID -ne 1 ]; then
echo ""
echo "******************************"
echo "Validation failed please see results above."
exit 1
else
exit 0
fi