33TEST_NAMES=()
44TEST_STATUSES=()
55TEST_DURATIONS=()
6- TEST_ERRORS=()
76
87function logger::test_snapshot() {
9- logger::log " $1 " " $2 " " snapshot " " $3 "
8+ logger::log " $1 " " $2 " " $3 " " snapshot "
109}
1110
1211function logger::test_incomplete() {
13- logger::log " $1 " " $2 " " incomplete " " $3 "
12+ logger::log " $1 " " $2 " " $3 " " incomplete "
1413}
1514
1615function logger::test_skipped() {
17- logger::log " $1 " " $2 " " skipped " " $3 "
16+ logger::log " $1 " " $2 " " $3 " " skipped "
1817}
1918
2019function logger::test_passed() {
21- logger::log " $1 " " $2 " " passed " " $3 "
20+ logger::log " $1 " " $2 " " $3 " " passed "
2221}
2322
2423function logger::test_failed() {
25- logger::log " $1 " " $2 " " failed " " $3 "
24+ logger::log " $1 " " $2 " " $3 " " failed "
2625}
2726
2827function logger::log() {
29- local test_name =" $1 "
30- local start_time =" $2 "
31- local status =" $3 "
32- local error_msg =" ${4 :- } "
28+ local file =" $1 "
29+ local test_name =" $2 "
30+ local start_time =" $3 "
31+ local status =" $4 "
3332
3433 local end_time
3534 end_time=$( clock::now)
3635 local duration=$(( end_time - start_time))
3736
37+ TEST_FILES+=(" $file " )
3838 TEST_NAMES+=(" $test_name " )
3939 TEST_STATUSES+=(" $status " )
4040 TEST_DURATIONS+=(" $duration " )
41- TEST_ERRORS+=(" $error_msg " )
4241}
4342
4443function logger::generate_junit_xml() {
@@ -64,19 +63,136 @@ function logger::generate_junit_xml() {
6463 echo " skipped=\" $tests_skipped \" snapshot=\" $tests_snapshot \" >"
6564
6665 for i in " ${! TEST_NAMES[@]} " ; do
66+ local file=" ${TEST_FILES[$i]} "
6767 local name=" ${TEST_NAMES[$i]} "
6868 local status=" ${TEST_STATUSES[$i]} "
6969 local test_time=" ${TEST_DURATIONS[$i]} "
70- local msg=" ${TEST_ERRORS[$i]} "
7170
72- echo " <testcase name=\" $name \" time=\" $test_time \" status=\" $status \" >"
73- if [[ -n $msg ]]; then
74- echo " <message>$msg <message/>"
75- fi
71+ echo " <testcase file=\" $file \" "
72+ echo " name=\" $name \" "
73+ echo " status=\" $status \" time=\" $test_time \" >"
7674 echo " </testcase>"
7775 done
7876
7977 echo " </testsuite>"
8078 echo " </testsuites>"
8179 } > " $output_file "
8280}
81+
82+ function logger::generate_report_html() {
83+ local output_file=" $1 "
84+ local test_passed
85+ test_passed=$( state::get_tests_passed)
86+ local tests_skipped
87+ tests_skipped=$( state::get_tests_skipped)
88+ local tests_incomplete
89+ tests_incomplete=$( state::get_tests_incomplete)
90+ local tests_snapshot
91+ tests_snapshot=$( state::get_tests_snapshot)
92+ local tests_failed
93+ tests_failed=$( state::get_tests_failed)
94+ local time
95+ time=$( clock::runtime_in_milliseconds)
96+
97+ # Temporary file to store test cases by file
98+ local temp_file=" temp_test_cases.txt"
99+
100+ # Collect test cases by file
101+ : > " $temp_file " # Clear temp file if it exists
102+ for i in " ${! TEST_NAMES[@]} " ; do
103+ local file=" ${TEST_FILES[$i]} "
104+ local name=" ${TEST_NAMES[$i]} "
105+ local status=" ${TEST_STATUSES[$i]} "
106+ local test_time=" ${TEST_DURATIONS[$i]} "
107+ local test_case=" $file |$name |$status |$test_time "
108+
109+ echo " $test_case " >> " $temp_file "
110+ done
111+
112+ {
113+ echo " <!DOCTYPE html>"
114+ echo " <html lang=\" en\" >"
115+ echo " <head>"
116+ echo " <meta charset=\" UTF-8\" >"
117+ echo " <meta name=\" viewport\" content=\" width=device-width, initial-scale=1.0\" >"
118+ echo " <title>Test Report</title>"
119+ echo " <style>"
120+ echo " body { font-family: Arial, sans-serif; }"
121+ echo " table { width: 100%; border-collapse: collapse; }"
122+ echo " th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }"
123+ echo " th { background-color: #f2f2f2; }"
124+ echo " .passed { background-color: #dff0d8; }"
125+ echo " .failed { background-color: #f2dede; }"
126+ echo " .skipped { background-color: #fcf8e3; }"
127+ echo " .incomplete { background-color: #d9edf7; }"
128+ echo " .snapshot { background-color: #dfe6e9; }"
129+ echo " </style>"
130+ echo " </head>"
131+ echo " <body>"
132+ echo " <h1>Test Report</h1>"
133+ echo " <table>"
134+ echo " <thead>"
135+ echo " <tr>"
136+ echo " <th>Total Tests</th>"
137+ echo " <th>Passed</th>"
138+ echo " <th>Failed</th>"
139+ echo " <th>Incomplete</th>"
140+ echo " <th>Skipped</th>"
141+ echo " <th>Snapshot</th>"
142+ echo " <th>Time (ms)</th>"
143+ echo " </tr>"
144+ echo " </thead>"
145+ echo " <tbody>"
146+ echo " <tr>"
147+ echo " <td>${# TEST_NAMES[@]} </td>"
148+ echo " <td>$test_passed </td>"
149+ echo " <td>$tests_failed </td>"
150+ echo " <td>$tests_incomplete </td>"
151+ echo " <td>$tests_skipped </td>"
152+ echo " <td>$tests_snapshot </td>"
153+ echo " <td>${time} </td>"
154+ echo " </tr>"
155+ echo " </tbody>"
156+ echo " </table>"
157+ echo " <p>Time: $time ms</p>"
158+
159+ # Read the temporary file and group by file
160+ local current_file=" "
161+ while IFS=' |' read -r file name status test_time; do
162+ if [ " $file " != " $current_file " ]; then
163+ if [ -n " $current_file " ]; then
164+ echo " </tbody>"
165+ echo " </table>"
166+ fi
167+ echo " <h2>File: $file </h2>"
168+ echo " <table>"
169+ echo " <thead>"
170+ echo " <tr>"
171+ echo " <th>Test Name</th>"
172+ echo " <th>Status</th>"
173+ echo " <th>Time (ms)</th>"
174+ echo " </tr>"
175+ echo " </thead>"
176+ echo " <tbody>"
177+ current_file=" $file "
178+ fi
179+ echo " <tr class=\" $status \" >"
180+ echo " <td>$name </td>"
181+ echo " <td>$status </td>"
182+ echo " <td>$test_time </td>"
183+ echo " </tr>"
184+ done < " $temp_file "
185+
186+ # Close the last table
187+ if [ -n " $current_file " ]; then
188+ echo " </tbody>"
189+ echo " </table>"
190+ fi
191+
192+ echo " </body>"
193+ echo " </html>"
194+ } > " $output_file "
195+
196+ # Clean up temporary file
197+ rm -f " $temp_file "
198+ }
0 commit comments