test the new backtracking does all of its bookkeeping
authorEh2406 <YeomanYaacov@gmail.com>
Wed, 21 Mar 2018 21:05:55 +0000 (17:05 -0400)
committerEh2406 <YeomanYaacov@gmail.com>
Sat, 24 Mar 2018 15:32:24 +0000 (11:32 -0400)
src/cargo/core/resolver/mod.rs
tests/testsuite/resolve.rs

index bd049bd9148c29072c57465b985b3dea6d347268..30d65e18ad3e0816186bdafd4faf477f40be6fd1 100644 (file)
@@ -1307,10 +1307,12 @@ fn activate_deps_loop(
                                                         && cx.is_conflicting(None, con)
                                                 })
                                             }) {
-                                            conflicting_activations.insert(
-                                                debs.parent.package_id().clone(),
-                                                conflict.get(&pid).unwrap().clone(),
-                                            );
+                                            let mut conflict = conflict.clone();
+                                            let rel = conflict.get(&pid).unwrap().clone();
+                                            conflict.insert(debs.parent.package_id().clone(), rel);
+                                            conflict.remove(&pid);
+
+                                            conflicting_activations.extend(conflict);
                                             has_past_conflicting_dep = true;
                                             break 'deps;
                                         }
index 80539fec63beb5ed7b3c5d620a364ab8c6c2af53..bff6d88a1f48a5c4cde8cd8f2b614a27bbb78f74 100644 (file)
@@ -757,61 +757,12 @@ fn resolving_with_deep_traps() {
     assert!(res.is_err());
 }
 
-#[test]
-fn resolving_with_constrained_cousins_backtrack_s1() {
-    // ToDo: Remove when the longer version below passes! DON'T merge
-    let mut reglist = Vec::new();
-
-    const DEPTH: usize = 200;
-    const BRANCHING_FACTOR: usize = 100;
-
-    // Each backtrack_trap depends on the next.
-    // The last depends on a specific ver of constrained.
-    for l in 0..DEPTH {
-        let name = format!("backtrack_trap{}", l);
-        let next = format!("backtrack_trap{}", l + 1);
-        for i in 1..BRANCHING_FACTOR {
-            let vsn = format!("1.0.{}", i);
-            reglist.push(pkg!((name.as_str(), vsn.as_str()) => [dep_req(next.as_str(), "*")]));
-        }
-    }
-    {
-        let name = format!("backtrack_trap{}", DEPTH);
-        for i in 1..BRANCHING_FACTOR {
-            let vsn = format!("1.0.{}", i);
-            reglist.push(pkg!((name.as_str(), vsn.as_str()) => [dep_req("constrained", "=1.0.0")]));
-        }
-    }
-    {
-        // slightly less constrained to make sure `constrained` gets picked last.
-        for i in 0..(BRANCHING_FACTOR + 10) {
-            let vsn = format!("1.0.{}", i);
-            reglist.push(pkg!(("constrained", vsn.as_str())));
-        }
-    }
-
-    let reg = registry(reglist.clone());
-
-    // `backtrack_trap0 = "*"` is a lot of ways of saying `constrained = "=1.0.0"`
-    // Only then to try and solve `constrained= "1.0.1"` which is incompatible.
-    let res = resolve(
-        &pkg_id("root"),
-        vec![
-            dep_req("backtrack_trap0", "*"),
-            dep_req("constrained", "1.0.1"),
-        ],
-        &reg,
-    );
-
-    assert!(res.is_err());
-}
-
 #[test]
 fn resolving_with_constrained_cousins_backtrack() {
     let mut reglist = Vec::new();
 
-    const DEPTH: usize = 200;
-    const BRANCHING_FACTOR: usize = 100;
+    const DEPTH: usize = 100;
+    const BRANCHING_FACTOR: usize = 50;
 
     // Each backtrack_trap depends on the next.
     // The last depends on a specific ver of constrained.
@@ -827,7 +778,9 @@ fn resolving_with_constrained_cousins_backtrack() {
         let name = format!("backtrack_trap{}", DEPTH);
         for i in 1..BRANCHING_FACTOR {
             let vsn = format!("1.0.{}", i);
-            reglist.push(pkg!((name.as_str(), vsn.as_str()) => [dep_req("constrained", "=1.0.0")]));
+            reglist.push(
+                pkg!((name.as_str(), vsn.as_str()) => [dep_req("constrained", ">=1.1.0, <=2.0.0")]),
+            );
         }
     }
     {
@@ -836,17 +789,23 @@ fn resolving_with_constrained_cousins_backtrack() {
             let vsn = format!("1.0.{}", i);
             reglist.push(pkg!(("constrained", vsn.as_str())));
         }
+        reglist.push(pkg!(("constrained", "1.1.0")));
+        reglist.push(pkg!(("constrained", "2.0.0")));
+        reglist.push(pkg!(("constrained", "2.0.1")));
     }
+    reglist.push(pkg!(("cloaking", "1.0.0") => [dep_req("constrained", "~1.0.0")]));
 
     let reg = registry(reglist.clone());
 
-    // `backtrack_trap0 = "*"` is a lot of ways of saying `constrained = "=1.0.0"`
-    // Only then to try and solve `constrained= "1.0.1"` which is incompatible.
+    // `backtrack_trap0 = "*"` is a lot of ways of saying `constrained = ">=1.1.0, <=2.0.0"`
+    // but `constrained= "2.0.1"` is already picked.
+    // Only then to try and solve `constrained= "~1.0.0"` which is incompatible.
     let res = resolve(
         &pkg_id("root"),
         vec![
             dep_req("backtrack_trap0", "*"),
-            dep_req("constrained", "1.0.1"),
+            dep_req("constrained", "2.0.1"),
+            dep_req("cloaking", "*"),
         ],
         &reg,
     );
@@ -863,22 +822,32 @@ fn resolving_with_constrained_cousins_backtrack() {
             reglist.push(pkg!((name.as_str(), vsn.as_str()) => [dep_req(next.as_str(), "*")]));
         }
     }
-    reglist.push(pkg!((format!("level{}", DEPTH).as_str(), "1.0.0") => [dep_req("backtrack_trap0", "*"),
-            dep_req("constrained", "1.0.1")]));
+    reglist.push(
+        pkg!((format!("level{}", DEPTH).as_str(), "1.0.0") => [dep_req("backtrack_trap0", "*"),
+            dep_req("cloaking", "*")
+            ]),
+    );
 
     let reg = registry(reglist.clone());
 
-    // `backtrack_trap0 = "*"` is a lot of ways of saying `constrained = "=1.0.0"`
-    // Only then to try and solve `constrained= "1.0.1"` which is incompatible.
     let res = resolve(
         &pkg_id("root"),
-        vec![
-            dep_req("level0", "*"),
-        ],
+        vec![dep_req("level0", "*"), dep_req("constrained", "2.0.1")],
         &reg,
     );
 
     assert!(res.is_err());
+
+    let res = resolve(
+        &pkg_id("root"),
+        vec![dep_req("level0", "*"), dep_req("constrained", "2.0.0")],
+        &reg,
+    ).unwrap();
+
+    assert_that(
+        &res,
+        contains(names(&[("constrained", "2.0.0"), ("cloaking", "1.0.0")])),
+    );
 }
 
 #[test]