Skip to content

Commit 45411e2

Browse files
committed
if found a case that causes a panic and did not use all of the input. lets print the part of the input that was used. Helpful in minimization.
1 parent bf28b0f commit 45411e2

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

tests/testsuite/support/resolver.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,20 @@ pub fn resolve_with_config_raw(
7373
registry: &[Summary],
7474
config: Option<&Config>,
7575
) -> CargoResult<Resolve> {
76-
struct MyRegistry<'a>(&'a [Summary]);
76+
struct MyRegistry<'a> {
77+
list: &'a [Summary],
78+
used: HashSet<PackageId>,
79+
};
7780
impl<'a> Registry for MyRegistry<'a> {
7881
fn query(
7982
&mut self,
8083
dep: &Dependency,
8184
f: &mut dyn FnMut(Summary),
8285
fuzzy: bool,
8386
) -> CargoResult<()> {
84-
for summary in self.0.iter() {
87+
for summary in self.list.iter() {
8588
if fuzzy || dep.matches(summary) {
89+
self.used.insert(summary.package_id());
8690
f(summary.clone());
8791
}
8892
}
@@ -97,7 +101,28 @@ pub fn resolve_with_config_raw(
97101
false
98102
}
99103
}
100-
let mut registry = MyRegistry(registry);
104+
impl<'a> Drop for MyRegistry<'a> {
105+
fn drop(&mut self) {
106+
if std::thread::panicking() && self.list.len() != self.used.len() {
107+
// we found a case that causes a panic and did not use all of the input.
108+
// lets print the part of the input that was used for minimization.
109+
println!(
110+
"{:?}",
111+
PrettyPrintRegistry(
112+
self.list
113+
.iter()
114+
.filter(|s| { self.used.contains(&s.package_id()) })
115+
.cloned()
116+
.collect()
117+
)
118+
);
119+
}
120+
}
121+
}
122+
let mut registry = MyRegistry {
123+
list: registry,
124+
used: HashSet::new(),
125+
};
101126
let summary = Summary::new(
102127
pkg,
103128
deps,
@@ -348,8 +373,6 @@ fn meta_test_deep_pretty_print_registry() {
348373
pkg!(("baz", "1.0.1")),
349374
pkg!(("cat", "1.0.2") => [dep_req_kind("other", "2", Kind::Build, false)]),
350375
pkg!(("cat", "1.0.3") => [dep_req_kind("other", "2", Kind::Development, false)]),
351-
pkg!(("cat", "1.0.4") => [dep_req_kind("other", "2", Kind::Build, false)]),
352-
pkg!(("cat", "1.0.5") => [dep_req_kind("other", "2", Kind::Development, false)]),
353376
pkg!(("dep_req", "1.0.0")),
354377
pkg!(("dep_req", "2.0.0")),
355378
])
@@ -363,8 +386,6 @@ fn meta_test_deep_pretty_print_registry() {
363386
pkg!((\"baz\", \"1.0.1\")),\
364387
pkg!((\"cat\", \"1.0.2\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, false),]),\
365388
pkg!((\"cat\", \"1.0.3\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, false),]),\
366-
pkg!((\"cat\", \"1.0.4\") => [dep_req_kind(\"other\", \"^2\", Kind::Build, false),]),\
367-
pkg!((\"cat\", \"1.0.5\") => [dep_req_kind(\"other\", \"^2\", Kind::Development, false),]),\
368389
pkg!((\"dep_req\", \"1.0.0\")),\
369390
pkg!((\"dep_req\", \"2.0.0\")),]"
370391
)

0 commit comments

Comments
 (0)