5
5
#![ feature( decl_macro) ] // `macro`
6
6
#![ feature( pin_macro) ] // `core::pin::pin!`
7
7
#![ warn( must_not_suspend) ]
8
- use anyhow:: Context ;
8
+ use anyhow:: { bail , Context } ;
9
9
use clap:: Parser ;
10
10
use std:: { env, path:: Path } ;
11
- use thiserror:: Error ;
12
11
13
12
mod driverinterface;
14
13
mod selection;
@@ -31,23 +30,6 @@ async fn main() {
31
30
}
32
31
}
33
32
34
- // TODO: Top-level error enum is useless; replace it with `anyhow`
35
- #[ derive( Error , Debug ) ]
36
- enum MainError {
37
- #[ error( "Could not initialize the test driver interface." ) ]
38
- TestDriver ( #[ source] driverinterface:: TestDriverNewError ) ,
39
- #[ error( "Could not connect to the target." ) ]
40
- ConnectTarget ( #[ source] anyhow:: Error ) ,
41
- #[ error( "Could not build the test '{0}'." ) ]
42
- BuildTest ( String , #[ source] driverinterface:: TestDriverRunError ) ,
43
- #[ error( "Could not run the test '{0}'." ) ]
44
- RunTest ( String , #[ source] driverinterface:: TestDriverRunError ) ,
45
- #[ error( "Test failed." ) ]
46
- TestFail ,
47
- #[ error( "The target architecture '{0}' is invalid or unsupported." ) ]
48
- BadTarget ( targets:: Arch ) ,
49
- }
50
-
51
33
/// R3 test runner
52
34
#[ derive( Parser ) ]
53
35
struct Opt {
@@ -161,9 +143,9 @@ async fn main_inner() -> anyhow::Result<()> {
161
143
let target_arch = opt. target_arch . unwrap_or_else ( || opt. target . target_arch ( ) ) ;
162
144
log:: debug!( "target_arch = {}" , target_arch) ;
163
145
164
- let target_arch_opt = target_arch
165
- . build_opt ( )
166
- . ok_or ( MainError :: BadTarget ( target_arch ) ) ?;
146
+ let target_arch_opt = target_arch. build_opt ( ) . with_context ( || {
147
+ format ! ( "The target architecture '{target_arch}' is invalid or unsupported." )
148
+ } ) ?;
167
149
log:: debug!( "target_arch_opt = {:?}" , target_arch_opt) ;
168
150
169
151
// Initialize the test driver interface
@@ -175,7 +157,7 @@ async fn main_inner() -> anyhow::Result<()> {
175
157
opt. additional_rustflags . unwrap_or_default ( ) ,
176
158
)
177
159
. await
178
- . map_err ( MainError :: TestDriver ) ?;
160
+ . context ( "Could not initialize the test driver interface." ) ?;
179
161
180
162
// Select tests
181
163
let test_source = selection:: TestSource {
@@ -215,7 +197,7 @@ async fn main_inner() -> anyhow::Result<()> {
215
197
opt. target
216
198
. connect ( )
217
199
. await
218
- . map_err ( MainError :: ConnectTarget ) ?,
200
+ . context ( "Could not connect to the target." ) ?,
219
201
)
220
202
} ;
221
203
@@ -243,7 +225,7 @@ async fn main_inner() -> anyhow::Result<()> {
243
225
} ,
244
226
)
245
227
. await
246
- . map_err ( |e| MainError :: BuildTest ( full_test_name. clone ( ) , e ) ) ?;
228
+ . with_context ( || format ! ( "Could not build the test '{ full_test_name}'." ) ) ?;
247
229
248
230
// Run the specified program
249
231
let mut test_result = if opt. exec . is_empty ( ) {
@@ -278,7 +260,7 @@ async fn main_inner() -> anyhow::Result<()> {
278
260
test_result = test_driver
279
261
. run ( test_run, & mut * * debug_probe)
280
262
. await
281
- . map_err ( |e| MainError :: RunTest ( full_test_name , e ) ) ?;
263
+ . with_context ( || format ! ( "Could not run the test '{full_test_name}'." ) ) ?;
282
264
}
283
265
}
284
266
@@ -316,7 +298,7 @@ async fn main_inner() -> anyhow::Result<()> {
316
298
}
317
299
}
318
300
319
- return Err ( MainError :: TestFail . into ( ) ) ;
301
+ bail ! ( "Test failed." ) ;
320
302
}
321
303
322
304
assert ! ( tests_skipped_to_fail_fast. is_empty( ) ) ;
0 commit comments