Skip to content

Commit 0538507

Browse files
committed
add an additional fuzz test
1 parent 8d13988 commit 0538507

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

tests/testsuite/resolve.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::support::project;
88
use crate::support::registry::Package;
99
use crate::support::resolver::{
1010
assert_contains, assert_same, dep, dep_kind, dep_loc, dep_req, loc_names, names, pkg, pkg_dep,
11-
pkg_id, pkg_loc, registry, registry_strategy, resolve, resolve_and_validated,
11+
pkg_id, pkg_loc, registry, registry_strategy, remove_dep, resolve, resolve_and_validated,
1212
resolve_with_config, PrettyPrintRegistry, ToDep, ToPkgId,
1313
};
1414

@@ -108,11 +108,53 @@ proptest! {
108108
}
109109
}
110110

111+
/// NOTE: if you think this test has failed spuriously see the note at the top of this macro.
112+
#[test]
113+
fn removing_a_dep_cant_brake(
114+
PrettyPrintRegistry(input) in registry_strategy(50, 20, 60),
115+
indexs_to_remove in collection::vec((any::<prop::sample::Index>(), any::<prop::sample::Index>()), ..10)
116+
) {
117+
let reg = registry(input.clone());
118+
let mut removed_input = input.clone();
119+
for (summery_idx, dep_idx) in indexs_to_remove {
120+
if removed_input.len() > 0 {
121+
let summery_idx = summery_idx.index(removed_input.len());
122+
let deps = removed_input[summery_idx].dependencies();
123+
if deps.len() > 0 {
124+
let new = remove_dep(&removed_input[summery_idx], dep_idx.index(deps.len()));
125+
removed_input[summery_idx] = new;
126+
}
127+
}
128+
}
129+
let removed_reg = registry(removed_input);
130+
// there is only a small chance that eny one
131+
// crate will be interesting.
132+
// So we try some of the most complicated.
133+
for this in input.iter().rev().take(10) {
134+
if resolve(
135+
&pkg_id("root"),
136+
vec![dep_req(&this.name(), &format!("={}", this.version()))],
137+
&reg,
138+
).is_ok() {
139+
prop_assert!(
140+
resolve(
141+
&pkg_id("root"),
142+
vec![dep_req(&this.name(), &format!("={}", this.version()))],
143+
&removed_reg,
144+
).is_ok(),
145+
"full index worked for `{} = \"={}\"` but removing some deps broke it!",
146+
this.name(),
147+
this.version(),
148+
)
149+
}
150+
}
151+
}
152+
111153
/// NOTE: if you think this test has failed spuriously see the note at the top of this macro.
112154
#[test]
113155
fn limited_independence_of_irrelevant_alternatives(
114156
PrettyPrintRegistry(input) in registry_strategy(50, 20, 60),
115-
indexs_to_unpublish in collection::vec(any::<prop::sample::Index>(), 10)
157+
indexs_to_unpublish in collection::vec(any::<prop::sample::Index>(), ..10)
116158
) {
117159
let reg = registry(input.clone());
118160
// there is only a small chance that eny one

tests/testsuite/support/resolver.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,20 @@ pub fn pkg_loc(name: &str, loc: &str) -> Summary {
230230
.unwrap()
231231
}
232232

233+
pub fn remove_dep(sum: &Summary, ind: usize) -> Summary {
234+
let mut deps = sum.dependencies().to_vec();
235+
deps.remove(ind);
236+
// note: more things will need to be copied over in the future, but it works for now.
237+
Summary::new(
238+
sum.package_id(),
239+
deps,
240+
&BTreeMap::<String, Vec<String>>::new(),
241+
sum.links().map(|a| a.as_str()),
242+
sum.namespaced_features(),
243+
)
244+
.unwrap()
245+
}
246+
233247
pub fn dep(name: &str) -> Dependency {
234248
dep_req(name, "*")
235249
}

0 commit comments

Comments
 (0)