@@ -1231,3 +1231,81 @@ fn any_debug() {
1231
1231
// Downcasting to the underlying type should succeed.
1232
1232
assert_eq ! ( x. downcast_ref:: <MyStruct >( ) , Some ( & MyStruct { x: 7 } ) ) ;
1233
1233
}
1234
+
1235
+ /// The staging tests use insta for snapshot testing.
1236
+ /// See bootstrap's README on how to bless the snapshots.
1237
+ mod staging {
1238
+ use crate :: core:: builder:: tests:: {
1239
+ TEST_TRIPLE_1 , configure, configure_with_args, render_steps, run_build,
1240
+ } ;
1241
+
1242
+ #[ test]
1243
+ fn build_compiler_stage_1 ( ) {
1244
+ let mut cache = run_build (
1245
+ & [ "compiler" . into ( ) ] ,
1246
+ configure_with_args ( & [ "build" , "--stage" , "1" ] , & [ TEST_TRIPLE_1 ] , & [ TEST_TRIPLE_1 ] ) ,
1247
+ ) ;
1248
+ let steps = cache. into_executed_steps ( ) ;
1249
+ insta:: assert_snapshot!( render_steps( & steps) , @r"
1250
+ [build] rustc 0 <target1> -> std 0 <target1>
1251
+ [build] llvm <target1>
1252
+ [build] rustc 0 <target1> -> rustc 1 <target1>
1253
+ [build] rustc 0 <target1> -> rustc 1 <target1>
1254
+ " ) ;
1255
+ }
1256
+ }
1257
+
1258
+ /// Renders the executed bootstrap steps for usage in snapshot tests with insta.
1259
+ /// Only renders certain important steps.
1260
+ /// Each value in `steps` should be a tuple of (Step, step output).
1261
+ fn render_steps ( steps : & [ ( Box < dyn Any > , Box < dyn Any > ) ] ) -> String {
1262
+ steps
1263
+ . iter ( )
1264
+ . filter_map ( |( step, output) | {
1265
+ // FIXME: implement an optional method on Step to produce metadata for test, instead
1266
+ // of this downcasting
1267
+ if let Some ( ( rustc, output) ) = downcast_step :: < compile:: Rustc > ( step, output) {
1268
+ Some ( format ! (
1269
+ "[build] {} -> {}" ,
1270
+ render_compiler( rustc. build_compiler) ,
1271
+ // FIXME: return the correct stage from the `Rustc` step, now it behaves weirdly
1272
+ render_compiler( Compiler :: new( rustc. build_compiler. stage + 1 , rustc. target) ) ,
1273
+ ) )
1274
+ } else if let Some ( ( std, output) ) = downcast_step :: < compile:: Std > ( step, output) {
1275
+ Some ( format ! (
1276
+ "[build] {} -> std {} <{}>" ,
1277
+ render_compiler( std. compiler) ,
1278
+ std. compiler. stage,
1279
+ std. target
1280
+ ) )
1281
+ } else if let Some ( ( llvm, output) ) = downcast_step :: < llvm:: Llvm > ( step, output) {
1282
+ Some ( format ! ( "[build] llvm <{}>" , llvm. target) )
1283
+ } else {
1284
+ None
1285
+ }
1286
+ } )
1287
+ . map ( |line| {
1288
+ line. replace ( TEST_TRIPLE_1 , "target1" )
1289
+ . replace ( TEST_TRIPLE_2 , "target2" )
1290
+ . replace ( TEST_TRIPLE_3 , "target3" )
1291
+ } )
1292
+ . collect :: < Vec < _ > > ( )
1293
+ . join ( "\n " )
1294
+ }
1295
+
1296
+ fn downcast_step < ' a , S : Step > (
1297
+ step : & ' a Box < dyn Any > ,
1298
+ output : & ' a Box < dyn Any > ,
1299
+ ) -> Option < ( & ' a S , & ' a S :: Output ) > {
1300
+ let Some ( step) = step. downcast_ref :: < S > ( ) else {
1301
+ return None ;
1302
+ } ;
1303
+ let Some ( output) = output. downcast_ref :: < S :: Output > ( ) else {
1304
+ return None ;
1305
+ } ;
1306
+ Some ( ( step, output) )
1307
+ }
1308
+
1309
+ fn render_compiler ( compiler : Compiler ) -> String {
1310
+ format ! ( "rustc {} <{}>" , compiler. stage, compiler. host)
1311
+ }
0 commit comments