Skip to content

Commit 1cc0af1

Browse files
committed
Adds first version of writing out a full test report
1 parent c87f332 commit 1cc0af1

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

rosetta-test/rosetta-test.scm

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'() ; exclude tests
2525
'() ; exclude capabilities
2626
'() ; expected failures
27+
"" ; bridge name
2728
)))
2829

2930
(define (suite-name suite)
@@ -46,6 +47,8 @@
4647
(list-ref suite 9))
4748
(define (suite-expected-failures suite)
4849
(list-ref suite 10))
50+
(define (suite-bridge-name suite)
51+
(list-ref suite 11))
4952
(define (suite-set-only-tests! suite only-tests)
5053
(list-set! suite 6 only-tests))
5154
(define (suite-set-only-capabilities! suite only-capabilities)
@@ -56,6 +59,8 @@
5659
(list-set! suite 9 exclude-capabilities))
5760
(define (suite-set-expected-failures! suite expected-failures)
5861
(list-set! suite 10 expected-failures))
62+
(define (suite-set-bridge-name! suite bridge-name)
63+
(list-set! suite 11 bridge-name))
5964

6065
(define (suite-all-tests suite)
6166
(capability-all-tests (suite-root-capability suite)))
@@ -92,11 +97,83 @@
9297

9398
(define (display-run-options-help)
9499
(display "Options:\n")
95-
(display " --full-report: Write a full report of suite results to file [suite-name]-[suite-version]-results.xml.\n")
100+
(display " --full-report: Write a full report of suite results to file [suite-name]-[suite-version]-results.json.\n")
96101
(display " --help: Display this help message.\n"))
97102

103+
; Writes full report to .json file
104+
; Full report includes:
105+
; - Hierarchical structure of capabilities and tests
106+
; - Test results (success, failure, error, expected failure, unexpected pass, skipped)
107+
; - Capabilities skipped
98108
(define (write-full-report suite test-results expected-failures)
99-
(display "Writing full report not implemented yet\n"))
109+
(let
110+
((test-results-hash (alist->hash-table (map
111+
(lambda (test-result) (list (test-full-name (test-result-test test-result)) test-result))
112+
test-results))))
113+
(call-with-output-file
114+
(string-append (suite-name suite) "-" (suite-version suite) "-results.json")
115+
(lambda (out)
116+
(write-string
117+
(string-append
118+
"{"
119+
" \"suite\": {\n"
120+
" \"name\": \"" (suite-name suite) "\",\n"
121+
" \"version\": \"" (suite-version suite) "\",\n"
122+
" \"host\": \"" (rosetta-test-host) "\",\n"
123+
" \"bridge\": \"" (suite-bridge-name suite) "\",\n"
124+
" \"capabilities\": [\n"
125+
(full-capability-report (suite-root-capability suite) test-results-hash suite expected-failures)
126+
"\n ]"
127+
" }"
128+
"}")
129+
out)))))
130+
131+
(define (full-capability-report capability test-results-hash suite expected-failures)
132+
(let
133+
((capability-name (capability-name capability))
134+
(capability-child-capabilities (capability-child-capabilities capability))
135+
(capability-tests (capability-tests capability)))
136+
(string-append
137+
" {"
138+
" \"name\": \"" capability-name "\",\n"
139+
" \"state\": \"" (if (member capability-name (suite-exclude-capabilities suite)) "skipped" "run") "\",\n" ; TODO: This is not perfect, the capability might have been in the only list
140+
" \"capabilities\": [\n"
141+
(if (null? capability-child-capabilities)
142+
""
143+
(string-join
144+
(map
145+
(lambda (child-capability)
146+
(full-capability-report child-capability test-results-hash suite expected-failures))
147+
capability-child-capabilities)
148+
",\n"))
149+
" ],\n"
150+
" \"tests\": [\n"
151+
(full-test-report capability-tests test-results-hash expected-failures)
152+
" ]\n"
153+
" }")))
154+
155+
; Write out json array of test result objects with state (success, failure, error, expected failure, unexpected pass, skipped)
156+
(define (full-test-report tests test-results-hash expected-failures)
157+
(let
158+
((selected-test-results (alist->hash-table (map
159+
(lambda (test)
160+
(if (member (test-full-name test) (hash-keys test-results-hash))
161+
(list
162+
(test-full-name test)
163+
(short-hand-test-result (hash-ref test-results-hash (test-full-name test)) expected-failures))
164+
(list (test-full-name test) "skipped")))
165+
tests))))
166+
(string-join
167+
(map
168+
(lambda (test)
169+
(string-append
170+
" {\n"
171+
" \"name\": \"" (test-name test) "\",\n"
172+
" \"state\": \"" (hash-ref selected-test-results (test-full-name test)) "\""
173+
(if (= "E" (hash-ref selected-test-results (test-full-name test))) ",\n \"exception\": \"some error\"\n" "\n")
174+
" }"))
175+
tests)
176+
",\n")))
100177

101178
(define (suite-run suite options)
102179
(display (string-append "Running suite: " (suite-name suite) " " (suite-version suite) "\n"))
@@ -341,8 +418,6 @@
341418
; Executing suites
342419
;
343420

344-
345-
346421
(define (expected-failures-test-result? test-result expected-failures)
347422
(member (test-full-name (test-result-test test-result)) expected-failures))
348423

0 commit comments

Comments
 (0)