@@ -99,12 +99,15 @@ def collect(self):
99
99
100
100
101
101
_ACTUAL_KW = kw .keyword ('actual' )
102
+ _ERROR_KW = kw .keyword ('error' )
102
103
_EXPECTED_KW = kw .keyword ('expected' )
104
+ _FAILURE_KW = kw .keyword ('failure' )
103
105
_FAILURES_KW = kw .keyword ('failures' )
104
106
_MESSAGE_KW = kw .keyword ('message' )
105
107
_LINE_KW = kw .keyword ('line' )
106
108
_EXPR_KW = kw .keyword ('expr' )
107
109
_TEST_SECTION_KW = kw .keyword ('test-section' )
110
+ _TYPE_KW = kw .keyword ('type' )
108
111
109
112
110
113
class BasilispTestItem (pytest .Item ):
@@ -147,31 +150,47 @@ def repr_failure(self, excinfo):
147
150
messages = []
148
151
149
152
for details in failures :
150
- msg : str = details .entry (_MESSAGE_KW )
151
-
152
- actual = details .entry (_ACTUAL_KW )
153
- expected = details .entry (_EXPECTED_KW )
154
-
155
- test_section = details .entry (_TEST_SECTION_KW )
156
- line = details .entry (_LINE_KW )
157
- section_msg = Maybe (test_section ).map (lambda s : f" { s } :: " ).or_else_get ("" )
158
-
159
- messages .append ("\n " .join ([
160
- f"FAIL in ({ self .name } ) ({ self ._filename } :{ line } )" ,
161
- f" { section_msg } { msg } " ,
162
- "" ,
163
- f" expected: { lrepr (expected )} " ,
164
- f" actual: { lrepr (actual )} "
165
- ]))
153
+ type_ = details .entry (_TYPE_KW )
154
+ if type_ == _FAILURE_KW :
155
+ messages .append (self ._failure_msg (details ))
156
+ elif type_ == _ERROR_KW :
157
+ exc = details .entry (_ACTUAL_KW )
158
+ line = details .entry (_LINE_KW )
159
+ messages .append (self ._error_msg (exc , line = line ))
160
+ else :
161
+ assert False , "Test failure type must be in #{:error :failure}"
166
162
167
163
return "\n \n " .join (messages )
168
164
elif isinstance (excinfo .value , Exception ):
169
165
exc = excinfo .value
170
- messages = [f"ERROR in ({ self .name } ) ({ self ._filename } )" , "\n \n " ]
171
- messages .extend (traceback .format_exception (Exception , exc , exc .__traceback__ ))
172
- return "" .join (messages )
166
+ return self ._error_msg (exc )
173
167
else :
174
168
return None
175
169
176
170
def reportinfo (self ):
177
171
return self .fspath , 0 , self .name
172
+
173
+ def _error_msg (self , exc : Exception , line : Optional [int ] = None ) -> str :
174
+ line_msg = Maybe (line ).map (lambda l : f":{ l } " ).or_else_get ("" )
175
+ messages = [f"ERROR in ({ self .name } ) ({ self ._filename } { line_msg } )" , "\n \n " ]
176
+ messages .extend (traceback .format_exception (Exception , exc , exc .__traceback__ ))
177
+ return "" .join (messages )
178
+
179
+ def _failure_msg (self , details : lmap .Map ) -> str :
180
+ assert details .entry (_TYPE_KW ) == _FAILURE_KW
181
+ msg : str = details .entry (_MESSAGE_KW )
182
+
183
+ actual = details .entry (_ACTUAL_KW )
184
+ expected = details .entry (_EXPECTED_KW )
185
+
186
+ test_section = details .entry (_TEST_SECTION_KW )
187
+ line = details .entry (_LINE_KW )
188
+ section_msg = Maybe (test_section ).map (lambda s : f" { s } :: " ).or_else_get ("" )
189
+
190
+ return "\n " .join ([
191
+ f"FAIL in ({ self .name } ) ({ self ._filename } :{ line } )" ,
192
+ f" { section_msg } { msg } " ,
193
+ "" ,
194
+ f" expected: { lrepr (expected )} " ,
195
+ f" actual: { lrepr (actual )} "
196
+ ])
0 commit comments