From a02f6a12f8b178c88723eff815f52e8cd53f4399 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Mon, 20 May 2019 11:14:09 -0400 Subject: [PATCH] add pub-piv prop tests. This was supposed to be in #6653, but was lost in the edits of history. Reconstructed from https://github.com/Eh2406/cargo/commit/5522aba5e8875d9c9e14eb66b5469ad481cba7a1 --- tests/testsuite/support/resolver.rs | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/support/resolver.rs b/tests/testsuite/support/resolver.rs index 7c8ce7f2fc1..f2e8f68a429 100644 --- a/tests/testsuite/support/resolver.rs +++ b/tests/testsuite/support/resolver.rs @@ -1,6 +1,6 @@ use std::cmp::PartialEq; use std::cmp::{max, min}; -use std::collections::{BTreeMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::fmt; use std::time::Instant; @@ -54,6 +54,34 @@ pub fn resolve_and_validated( } let out = resolve.sort(); assert_eq!(out.len(), used.len()); + + let mut pub_deps: HashMap> = HashMap::new(); + for &p in out.iter() { + // make the list of `p` public dependencies + let mut self_pub_dep = HashSet::new(); + self_pub_dep.insert(p); + for (dp, deps) in resolve.deps(p) { + if deps.iter().any(|d| d.is_public()) { + self_pub_dep.extend(pub_deps[&dp].iter().cloned()) + } + } + pub_deps.insert(p, self_pub_dep); + + // check if `p` has a public dependencies conflicts + let seen_dep: BTreeSet<_> = resolve + .deps(p) + .flat_map(|(dp, _)| pub_deps[&dp].iter().cloned()) + .collect(); + let seen_dep: Vec<_> = seen_dep.iter().collect(); + for a in seen_dep.windows(2) { + if a[0].name() == a[1].name() { + panic!( + "the package {:?} can publicly see {:?} and {:?}", + p, a[0], a[1] + ) + } + } + } Ok(out) }