@@ -22,7 +22,7 @@ pub(crate) struct FakeRelease<'a> {
2222 storage : Arc < AsyncStorage > ,
2323 runtime : Arc < Runtime > ,
2424 package : MetadataPackage ,
25- builds : Vec < FakeBuild > ,
25+ builds : Option < Vec < FakeBuild > > ,
2626 /// name, content
2727 source_files : Vec < ( & ' a str , & ' a [ u8 ] ) > ,
2828 /// name, content
@@ -90,7 +90,7 @@ impl<'a> FakeRelease<'a> {
9090 . cloned ( )
9191 . collect :: < HashMap < String , Vec < String > > > ( ) ,
9292 } ,
93- builds : vec ! [ ] ,
93+ builds : None ,
9494 source_files : Vec :: new ( ) ,
9595 rustdoc_files : Vec :: new ( ) ,
9696 doc_targets : Vec :: new ( ) ,
@@ -147,20 +147,31 @@ impl<'a> FakeRelease<'a> {
147147 // TODO: How should `has_docs` actually be handled?
148148 pub ( crate ) fn build_result_failed ( self ) -> Self {
149149 assert ! (
150- self . builds. is_empty ( ) ,
150+ self . builds. is_none ( ) ,
151151 "cannot use custom builds with build_result_failed"
152152 ) ;
153153 Self {
154154 has_docs : false ,
155- builds : vec ! [ FakeBuild :: default ( ) . successful( false ) ] ,
155+ builds : Some ( vec ! [ FakeBuild :: default ( ) . successful( false ) ] ) ,
156156 ..self
157157 }
158158 }
159159
160160 pub ( crate ) fn builds ( self , builds : Vec < FakeBuild > ) -> Self {
161- assert ! ( self . builds. is_empty ( ) ) ;
161+ assert ! ( self . builds. is_none ( ) ) ;
162162 assert ! ( !builds. is_empty( ) ) ;
163- Self { builds, ..self }
163+ Self {
164+ builds : Some ( builds) ,
165+ ..self
166+ }
167+ }
168+
169+ pub ( crate ) fn no_builds ( self ) -> Self {
170+ assert ! ( self . builds. is_none( ) ) ;
171+ Self {
172+ builds : Some ( vec ! [ ] ) ,
173+ ..self
174+ }
164175 }
165176
166177 pub ( crate ) fn yanked ( mut self , new : bool ) -> Self {
@@ -281,7 +292,7 @@ impl<'a> FakeRelease<'a> {
281292 }
282293
283294 /// Returns the release_id
284- pub ( crate ) async fn create_async ( mut self ) -> Result < i32 > {
295+ pub ( crate ) async fn create_async ( self ) -> Result < i32 > {
285296 use std:: fs;
286297 use std:: path:: Path ;
287298
@@ -417,12 +428,9 @@ impl<'a> FakeRelease<'a> {
417428 debug ! ( "added source files {}" , source_meta) ;
418429
419430 // If the test didn't add custom builds, inject a default one
420- if self . builds . is_empty ( ) {
421- self . builds . push ( FakeBuild :: default ( ) ) ;
422- }
423- let last_build_result = & self . builds . last ( ) . unwrap ( ) . result ;
431+ let builds = self . builds . unwrap_or_else ( || vec ! [ FakeBuild :: default ( ) ] ) ;
424432
425- if last_build_result . successful {
433+ if builds . last ( ) . map ( |b| b . result . successful ) . unwrap_or ( false ) {
426434 let index = [ & package. name , "index.html" ] . join ( "/" ) ;
427435 if package. is_library ( ) && !rustdoc_files. iter ( ) . any ( |( path, _) | path == & index) {
428436 rustdoc_files. push ( ( & index, DEFAULT_CONTENT ) ) ;
@@ -494,7 +502,7 @@ impl<'a> FakeRelease<'a> {
494502 & self . registry_crate_data ,
495503 )
496504 . await ?;
497- for build in & self . builds {
505+ for build in builds {
498506 build
499507 . create ( & mut async_conn, & storage, release_id, default_target)
500508 . await ?;
0 commit comments