1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use std::process::Command;
13 use std::path::{Path, PathBuf};
21 lock: Option<&'static str>,
24 const TEST_REPOS: &'static [Test] = &[Test {
26 repo: "https://github.com/rust-lang/cargo",
27 sha: "2d85908217f99a30aa5f68e05a8980704bb71fad",
32 repo: "https://github.com/iron/iron",
33 sha: "16c858ec2901e2992fe5e529780f59fa8ed12903",
34 lock: Some(include_str!("lockfiles/iron-Cargo.lock")),
39 let args = env::args().collect::<Vec<_>>();
40 let ref cargo = args[1];
41 let out_dir = Path::new(&args[2]);
42 let ref cargo = Path::new(cargo);
44 for test in TEST_REPOS.iter().rev() {
45 test_repo(cargo, out_dir, test);
49 fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
50 println!("testing {}", test.repo);
51 let dir = clone_repo(test, out_dir);
52 if let Some(lockfile) = test.lock {
53 File::create(&dir.join("Cargo.lock"))
55 .write_all(lockfile.as_bytes())
58 if !run_cargo_test(cargo, &dir) {
59 panic!("tests failed for {}", test.repo);
63 fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
64 let out_dir = out_dir.join(test.name);
66 if !out_dir.join(".git").is_dir() {
67 let status = Command::new("git")
72 assert!(status.success());
75 // Try progressively deeper fetch depths to find the commit
76 let mut found = false;
77 for depth in &[0, 1, 10, 100, 1000, 100000] {
79 let status = Command::new("git")
83 .arg(&format!("--depth={}", depth))
84 .current_dir(&out_dir)
87 assert!(status.success());
90 let status = Command::new("git")
94 .current_dir(&out_dir)
105 panic!("unable to find commit {}", test.sha)
107 let status = Command::new("git")
110 .current_dir(&out_dir)
113 assert!(status.success());
118 fn run_cargo_test(cargo_path: &Path, crate_path: &Path) -> bool {
119 let status = Command::new(cargo_path)
121 // Disable rust-lang/cargo's cross-compile tests
122 .env("CFG_DISABLE_CROSS_TESTS", "1")
123 .current_dir(crate_path)