@@ -9,20 +9,18 @@ ClassMethod RunTest(
99 qspec As %String ,
1010 ByRef userparam ) As %Status
1111{
12- kill ^||%UnitTest .Manager .LastResult
1312 quit ##super (.testspec ,.qspec ,.userparam )
1413}
1514
16- /// Does the default behavior, then stashes the latest run index
15+ /// Does the default behavior, then accumulates the test run index
1716Method SaveResult (duration )
1817{
1918 do ##super (.duration )
20- set ^||%UnitTest .Manager .LastResult = i%LogIndex
2119
2220 // Accumulate ALL test LogIndexes in an array
2321 // Uses $increment to append so nested calls add to the array
24- set tCount = $increment (^||%UnitTest .Manager .AllResultsCount )
25- set ^||%UnitTest .Manager .AllResults (tCount ) = i%LogIndex
22+ set count = $increment (^||%UnitTest .Manager .AllResultsCount )
23+ set ^||%UnitTest .Manager .AllResults (count ) = i%LogIndex
2624
2725 quit
2826}
@@ -54,51 +52,6 @@ ClassMethod LoadTestDirectory(
5452 quit tSC
5553}
5654
57- /// Returns $$$OK if the last unit test run was successful, or an error if it was unsuccessful.
58- ClassMethod GetLastStatus (Output pFailureCount As %Integer ) As %Status
59- {
60- set tSC = $$$OK
61- try {
62- if '$data (^||%UnitTest .Manager .LastResult ,tLogIndex )#2 {
63- set tLogIndex = $order (^UnitTest .Result (" " ),-1 )
64- }
65- kill ^||%UnitTest .Manager .LastResult // Clean up
66- if tLogIndex {
67- set tRes = ##class (%SQL.Statement ).%ExecDirect (," select count(*) " _
68- " from %UnitTest_Result.TestAssert where Status = 0 " _
69- " and TestMethod->TestCase->TestSuite->TestInstance->InstanceIndex = ?" ,tLogIndex )
70- if (tRes .%SQLCODE < 0 ) {
71- throw ##class (%Exception.SQL ).CreateFromSQLCODE (tRes .%SQLCODE ,tRes .%Message )
72- }
73- do tRes .%Next (.tSC )
74- $$$ThrowOnError(tSC )
75- set pFailureCount = tRes .%GetData (1 )
76- if (pFailureCount > 0 ) {
77- set tSC = $$$ERROR($$$GeneralError,$$$FormatText(" %1 assertion(s) failed." ,pFailureCount ))
78- } else {
79- // Double check that no other failures were reported - e.g., failures loading that would lead to no assertions passing or failing!
80- set tRes = ##class (%SQL.Statement ).%ExecDirect (," select count(*) " _
81- " from %UnitTest_Result.TestSuite where Status = 0 " _
82- " and TestInstance->InstanceIndex = ?" ,tLogIndex )
83- if (tRes .%SQLCODE < 0 ) {
84- throw ##class (%Exception.SQL ).CreateFromSQLCODE (tRes .%SQLCODE ,tRes .%Message )
85- }
86- do tRes .%Next (.tSC )
87- $$$ThrowOnError(tSC )
88- set pFailureCount = tRes .%GetData (1 )
89- if (pFailureCount > 0 ) {
90- set tSC = $$$ERROR($$$GeneralError,$$$FormatText(" %1 test suite(s) failed." ,pFailureCount ))
91- }
92- }
93- } else {
94- set tSC = $$$ERROR($$$GeneralError," No unit test results recorded." )
95- }
96- } catch e {
97- set tSC = e .AsStatus ()
98- }
99- quit tSC
100- }
101-
10255/// Check all test LogIndexes accumulated in AllResults and return aggregated status
10356/// Returns error if any test had failures
10457/// startIndex: Only check results from this index onwards (for nested phases, e.g. calling `zpm verify` inside `zpm verify`)
@@ -111,17 +64,12 @@ ClassMethod GetAllTestsStatus(
11164 try {
11265 set testCount = $get (^||%UnitTest .Manager .AllResultsCount , 0 )
11366
114- // If no tests were tracked, fall back to GetLastStatus
115- if (testCount = 0 ) {
116- return ##class (%IPM.Test.Manager ).GetLastStatus (.failureCount )
117- }
118-
11967 // Check tracked test LogIndexes from startIndex onwards
12068 // This ensures nested phases only see their own results, not parent's
12169 for i =(startIndex +1 ):1 :testCount {
12270 set logIndex = $get (^||%UnitTest .Manager .AllResults (i ))
12371 if (logIndex '= " " ) {
124- // Query for assertion failures in this test run (matches GetLastStatus pattern)
72+ // Query for assertion failures in this test run
12573 set res = ##class (%SQL.Statement ).%ExecDirect (," select count(*) " _
12674 " from %UnitTest_Result.TestAssert where Status = 0 " _
12775 " and TestMethod->TestCase->TestSuite->TestInstance->InstanceIndex = ?" ,logIndex )
@@ -158,46 +106,65 @@ ClassMethod GetAllTestsStatus(
158106 quit sc
159107}
160108
161- ClassMethod OutputFailures ()
109+ /// Output test failures from accumulated results
110+ /// startIndex: Only output failures from this index onwards (for nested phases)
111+ ClassMethod OutputFailures (startIndex As %Integer = 0 )
162112{
163- set tSC = $$$OK
113+ set sc = $$$OK
164114 try {
165- if '$data (^||%UnitTest .Manager .LastResult ,tLogIndex )#2 {
166- set tLogIndex = $order (^UnitTest .Result (" " ),-1 )
115+ set testCount = $get (^||%UnitTest .Manager .AllResultsCount , 0 )
116+
117+ // Output failures from all tracked test LogIndexes from startIndex onwards
118+ // This ensures parent phase outputs failures from both parent and nested tests
119+ for i =(startIndex +1 ):1 :testCount {
120+ set logIndex = $get (^||%UnitTest .Manager .AllResults (i ))
121+ if (logIndex '= " " ) {
122+ do ..OutputFailuresForLogIndex (logIndex )
123+ }
167124 }
168- kill ^||%UnitTest .Manager .LastResult // Clean up
169- if 'tLogIndex {
170- quit
125+
126+ // Only clean up AllResults at top level (startIndex=0), not in nested phases
127+ if (startIndex = 0 ) {
128+ kill ^||%UnitTest .Manager .AllResults
129+ kill ^||%UnitTest .Manager .AllResultsCount
171130 }
172- set tLogGN = $name (^UnitTest .Result (tLogIndex ))
173- set tRoot = " "
131+ } catch e {
132+ set sc = e .AsStatus ()
133+ }
134+ quit sc
135+ }
136+
137+ /// Helper method to output failures for a single LogIndex
138+ ClassMethod OutputFailuresForLogIndex (logIndex As %Integer )
139+ {
140+ if 'logIndex {
141+ quit
142+ }
143+ set logGN = $name (^UnitTest .Result (logIndex ))
144+ set root = " "
145+ for {
146+ set root = $order (@logGN @(root ))
147+ quit :root =" "
148+ set suite = " "
174149 for {
175- set tRoot = $order (@tLogGN @( tRoot ))
176- quit :tRoot =" "
177- set tSuite = " "
150+ set suite = $order (@logGN @( root , suite ))
151+ quit :suite =" "
152+ set method = " "
178153 for {
179- set tSuite = $order (@tLogGN @(tRoot , tSuite ))
180- quit :tSuite =" "
181- set tMethod = " "
154+ set method = $order (@logGN @(root , suite , method ))
155+ quit :method =" "
156+
157+ set assert = " "
182158 for {
183- set tMethod = $order (@tLogGN @(tRoot , tSuite , tMethod ))
184- quit :tMethod =" "
185-
186- set tAssert = " "
187- for {
188- set tAssert = $order (@tLogGN @(tRoot , tSuite , tMethod , tAssert ), 1 , tAssertInfo )
189- quit :tAssert =" "
190- set $listbuild (status , type , text ) = tAssertInfo
191- continue :status
192- write !,$$$FormattedLine($$$Red, " FAILED " _ tSuite _ " :" _ tMethod ), " : " _ type _ " - " _ text
193- }
159+ set assert = $order (@logGN @(root , suite , method , assert ), 1 , assertInfo )
160+ quit :assert =" "
161+ set $listbuild (status , type , text ) = assertInfo
162+ continue :status
163+ write !,$$$FormattedLine($$$Red, " FAILED " _ suite _ " :" _ method ), " : " _ type _ " - " _ text
194164 }
195165 }
196166 }
197- } catch e {
198- set tSC = e .AsStatus ()
199167 }
200- quit tSC
201168}
202169
203170}
0 commit comments