@@ -277,6 +277,7 @@ fn meta_test_deep_pretty_print_registry() {
277
277
fn registry_strategy (
278
278
max_crates : usize ,
279
279
max_versions : usize ,
280
+ shrinkage : usize ,
280
281
) -> impl Strategy < Value = PrettyPrintRegistry > {
281
282
let name = string_regex ( "[A-Za-z_-][A-Za-z0-9_-]*(-sys)?" ) . unwrap ( ) ;
282
283
@@ -285,7 +286,7 @@ fn registry_strategy(
285
286
286
287
// If this is false than the crate will depend on the nonexistent "bad"
287
288
// instead of the complex set we generated for it.
288
- let allow_deps = prop:: bool:: weighted ( 0.95 ) ;
289
+ let allow_deps = prop:: bool:: weighted ( 0.99 ) ;
289
290
290
291
let list_of_versions =
291
292
btree_set ( ( raw_version, allow_deps) , 1 ..=max_versions) . prop_map ( move |ver| {
@@ -304,8 +305,9 @@ fn registry_strategy(
304
305
vers
305
306
} ) ;
306
307
307
- // each version of each crate can depend on each crate smaller then it
308
- let max_deps = 1 + max_versions * ( max_crates * ( max_crates - 1 ) ) / 2 ;
308
+ // each version of each crate can depend on each crate smaller then it.
309
+ // In theory shrinkage should be 2, but in practice we get better trees with a larger value.
310
+ let max_deps = max_versions * ( max_crates * ( max_crates - 1 ) ) / shrinkage;
309
311
310
312
let raw_version_range = ( any :: < Index > ( ) , any :: < Index > ( ) ) ;
311
313
let raw_dependency = ( any :: < Index > ( ) , any :: < Index > ( ) , raw_version_range) ;
@@ -370,10 +372,9 @@ fn registry_strategy(
370
372
/// that it makes registries with large dependency trees
371
373
#[ test]
372
374
fn meta_test_deep_trees_from_strategy ( ) {
373
- let mut seen_an_error = false ;
374
- let mut seen_a_deep_tree = false ;
375
+ let mut dis = [ 0 ; 21 ] ;
375
376
376
- let strategy = registry_strategy ( 50 , 10 ) ;
377
+ let strategy = registry_strategy ( 50 , 10 , 50 ) ;
377
378
for _ in 0 ..256 {
378
379
let PrettyPrintRegistry ( input) = strategy
379
380
. new_tree ( & mut TestRunner :: default ( ) )
@@ -386,29 +387,17 @@ fn meta_test_deep_trees_from_strategy() {
386
387
vec ! [ dep_req( & this. name( ) , & format!( "={}" , this. version( ) ) ) ] ,
387
388
& reg,
388
389
) ;
389
- match res {
390
- Ok ( r) => {
391
- if r. len ( ) >= 7 {
392
- seen_a_deep_tree = true ;
393
- }
394
- }
395
- Err ( _) => {
396
- seen_an_error = true ;
397
- }
398
- }
399
- if seen_a_deep_tree && seen_an_error {
390
+ dis[ res. as_ref ( ) . map ( |x| min ( x. len ( ) , dis. len ( ) ) - 1 ) . unwrap_or ( 0 ) ] += 1 ;
391
+ if dis. iter ( ) . all ( |& x| x > 0 ) {
400
392
return ;
401
393
}
402
394
}
403
395
}
404
396
405
397
assert ! (
406
- seen_an_error,
407
- "In 2560 tries we did not see any crates that could not be built!"
408
- ) ;
409
- assert ! (
410
- seen_a_deep_tree,
411
- "In 2560 tries we did not see any crates that had more then 7 pkg in the dependency tree!"
398
+ dis. iter( ) . all( |& x| x > 0 ) ,
399
+ "In 2560 tries we did not see a wide enough distribution of dependency trees! dis:{:?}" ,
400
+ dis
412
401
) ;
413
402
}
414
403
@@ -432,7 +421,7 @@ proptest! {
432
421
} ) ]
433
422
#[ test]
434
423
fn limited_independence_of_irrelevant_alternatives(
435
- PrettyPrintRegistry ( input) in registry_strategy( 50 , 10 ) ,
424
+ PrettyPrintRegistry ( input) in registry_strategy( 50 , 10 , 50 ) ,
436
425
indexs_to_unpublish in vec( any:: <prop:: sample:: Index >( ) , 10 )
437
426
) {
438
427
let reg = registry( input. clone( ) ) ;
0 commit comments