@@ -22,7 +22,7 @@ pub(crate) struct FakeRelease<'a> {
22
22
storage : Arc < AsyncStorage > ,
23
23
runtime : Arc < Runtime > ,
24
24
package : MetadataPackage ,
25
- builds : Vec < FakeBuild > ,
25
+ builds : Option < Vec < FakeBuild > > ,
26
26
/// name, content
27
27
source_files : Vec < ( & ' a str , & ' a [ u8 ] ) > ,
28
28
/// name, content
@@ -90,7 +90,7 @@ impl<'a> FakeRelease<'a> {
90
90
. cloned ( )
91
91
. collect :: < HashMap < String , Vec < String > > > ( ) ,
92
92
} ,
93
- builds : vec ! [ ] ,
93
+ builds : None ,
94
94
source_files : Vec :: new ( ) ,
95
95
rustdoc_files : Vec :: new ( ) ,
96
96
doc_targets : Vec :: new ( ) ,
@@ -147,20 +147,31 @@ impl<'a> FakeRelease<'a> {
147
147
// TODO: How should `has_docs` actually be handled?
148
148
pub ( crate ) fn build_result_failed ( self ) -> Self {
149
149
assert ! (
150
- self . builds. is_empty ( ) ,
150
+ self . builds. is_none ( ) ,
151
151
"cannot use custom builds with build_result_failed"
152
152
) ;
153
153
Self {
154
154
has_docs : false ,
155
- builds : vec ! [ FakeBuild :: default ( ) . successful( false ) ] ,
155
+ builds : Some ( vec ! [ FakeBuild :: default ( ) . successful( false ) ] ) ,
156
156
..self
157
157
}
158
158
}
159
159
160
160
pub ( crate ) fn builds ( self , builds : Vec < FakeBuild > ) -> Self {
161
- assert ! ( self . builds. is_empty ( ) ) ;
161
+ assert ! ( self . builds. is_none ( ) ) ;
162
162
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
+ }
164
175
}
165
176
166
177
pub ( crate ) fn yanked ( mut self , new : bool ) -> Self {
@@ -281,7 +292,7 @@ impl<'a> FakeRelease<'a> {
281
292
}
282
293
283
294
/// 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 > {
285
296
use std:: fs;
286
297
use std:: path:: Path ;
287
298
@@ -417,12 +428,9 @@ impl<'a> FakeRelease<'a> {
417
428
debug ! ( "added source files {}" , source_meta) ;
418
429
419
430
// 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 ( ) ] ) ;
424
432
425
- if last_build_result . successful {
433
+ if builds . last ( ) . map ( |b| b . result . successful ) . unwrap_or ( false ) {
426
434
let index = [ & package. name , "index.html" ] . join ( "/" ) ;
427
435
if package. is_library ( ) && !rustdoc_files. iter ( ) . any ( |( path, _) | path == & index) {
428
436
rustdoc_files. push ( ( & index, DEFAULT_CONTENT ) ) ;
@@ -494,7 +502,7 @@ impl<'a> FakeRelease<'a> {
494
502
& self . registry_crate_data ,
495
503
)
496
504
. await ?;
497
- for build in & self . builds {
505
+ for build in builds {
498
506
build
499
507
. create ( & mut async_conn, & storage, release_id, default_target)
500
508
. await ?;
0 commit comments