@@ -142,9 +142,15 @@ impl Record {
142
142
/// # Panics
143
143
/// If the record is an internally injected record which should not occur in the test file.
144
144
pub fn unparse ( & self , w : & mut impl std:: io:: Write ) -> std:: io:: Result < ( ) > {
145
+ write ! ( w, "{}" , self )
146
+ }
147
+ }
148
+
149
+ impl std:: fmt:: Display for Record {
150
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
145
151
match self {
146
152
Record :: Include { loc : _, filename } => {
147
- write ! ( w , "include {}" , filename)
153
+ write ! ( f , "include {}" , filename)
148
154
}
149
155
Record :: Statement {
150
156
loc : _,
@@ -153,21 +159,21 @@ impl Record {
153
159
sql,
154
160
expected_count,
155
161
} => {
156
- write ! ( w , "statement " ) ?;
162
+ write ! ( f , "statement " ) ?;
157
163
match ( expected_count, expected_error) {
158
- ( None , None ) => write ! ( w , "ok" ) ?,
164
+ ( None , None ) => write ! ( f , "ok" ) ?,
159
165
( None , Some ( err) ) => {
160
166
if err. as_str ( ) . is_empty ( ) {
161
- write ! ( w , "error" ) ?;
167
+ write ! ( f , "error" ) ?;
162
168
} else {
163
- write ! ( w , "error {}" , err) ?;
169
+ write ! ( f , "error {}" , err) ?;
164
170
}
165
171
}
166
- ( Some ( cnt) , None ) => write ! ( w , "count {}" , cnt) ?,
172
+ ( Some ( cnt) , None ) => write ! ( f , "count {}" , cnt) ?,
167
173
( Some ( _) , Some ( _) ) => unreachable ! ( ) ,
168
174
}
169
- writeln ! ( w ) ?;
170
- write ! ( w , "{}" , sql)
175
+ writeln ! ( f ) ?;
176
+ write ! ( f , "{}" , sql)
171
177
}
172
178
Record :: Query {
173
179
loc : _,
@@ -179,60 +185,60 @@ impl Record {
179
185
sql,
180
186
expected_results,
181
187
} => {
182
- write ! ( w , "query" ) ?;
188
+ write ! ( f , "query" ) ?;
183
189
if let Some ( err) = expected_error {
184
- writeln ! ( w , " error {}" , err) ?;
185
- return write ! ( w , "{}" , sql) ;
190
+ writeln ! ( f , " error {}" , err) ?;
191
+ return write ! ( f , "{}" , sql) ;
186
192
}
187
193
188
194
write ! (
189
- w ,
195
+ f ,
190
196
" {}" ,
191
197
type_string. iter( ) . map( |c| format!( "{c}" ) ) . join( "" )
192
198
) ?;
193
199
if let Some ( sort_mode) = sort_mode {
194
- write ! ( w , " {}" , sort_mode. as_str( ) ) ?;
200
+ write ! ( f , " {}" , sort_mode. as_str( ) ) ?;
195
201
}
196
202
if let Some ( label) = label {
197
- write ! ( w , " {}" , label) ?;
203
+ write ! ( f , " {}" , label) ?;
198
204
}
199
- writeln ! ( w ) ?;
200
- writeln ! ( w , "{}" , sql) ?;
205
+ writeln ! ( f ) ?;
206
+ writeln ! ( f , "{}" , sql) ?;
201
207
202
- write ! ( w , "----" ) ?;
208
+ write ! ( f , "----" ) ?;
203
209
for result in expected_results {
204
- write ! ( w , "\n {}" , result) ?;
210
+ write ! ( f , "\n {}" , result) ?;
205
211
}
206
212
Ok ( ( ) )
207
213
}
208
214
Record :: Sleep { loc : _, duration } => {
209
- write ! ( w , "sleep {}" , humantime:: format_duration( * duration) )
215
+ write ! ( f , "sleep {}" , humantime:: format_duration( * duration) )
210
216
}
211
217
Record :: Subtest { loc : _, name } => {
212
- write ! ( w , "subtest {}" , name)
218
+ write ! ( f , "subtest {}" , name)
213
219
}
214
220
Record :: Halt { loc : _ } => {
215
- write ! ( w , "halt" )
221
+ write ! ( f , "halt" )
216
222
}
217
223
Record :: Control ( c) => match c {
218
- Control :: SortMode ( m) => write ! ( w , "control sortmode {}" , m. as_str( ) ) ,
224
+ Control :: SortMode ( m) => write ! ( f , "control sortmode {}" , m. as_str( ) ) ,
219
225
} ,
220
226
Record :: Condition ( cond) => match cond {
221
227
Condition :: OnlyIf { engine_name } => {
222
- write ! ( w , "onlyif {}" , engine_name)
228
+ write ! ( f , "onlyif {}" , engine_name)
223
229
}
224
230
Condition :: SkipIf { engine_name } => {
225
- write ! ( w , "skipif {}" , engine_name)
231
+ write ! ( f , "skipif {}" , engine_name)
226
232
}
227
233
} ,
228
234
Record :: HashThreshold { loc : _, threshold } => {
229
- write ! ( w , "hash-threshold {}" , threshold)
235
+ write ! ( f , "hash-threshold {}" , threshold)
230
236
}
231
237
Record :: Comment ( comment) => {
232
238
let mut iter = comment. iter ( ) ;
233
- write ! ( w , "#{}" , iter. next( ) . unwrap( ) . trim_end( ) ) ?;
239
+ write ! ( f , "#{}" , iter. next( ) . unwrap( ) . trim_end( ) ) ?;
234
240
for line in iter {
235
- write ! ( w , "\n #{}" , line. trim_end( ) ) ?;
241
+ write ! ( f , "\n #{}" , line. trim_end( ) ) ?;
236
242
}
237
243
Ok ( ( ) )
238
244
}
0 commit comments