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] = &[
27 repo: "https://github.com/rust-lang/cargo",
28 sha: "0e1e34be7540bdaed4918457654fbf028cf69e56",
33 repo: "https://github.com/iron/iron",
34 sha: "21c7dae29c3c214c08533c2a55ac649b418f2fe3",
35 lock: Some(include_str!("lockfiles/iron-Cargo.lock")),
39 repo: "https://github.com/BurntSushi/ripgrep",
40 sha: "b65bb37b14655e1a89c7cd19c8b011ef3e312791",
45 repo: "https://github.com/Aaronepower/tokei",
46 sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
51 repo: "https://github.com/dzamlo/treeify",
52 sha: "999001b223152441198f117a68fb81f57bc086dd",
57 repo: "https://github.com/BurntSushi/xsv",
58 sha: "a9a7163f2a2953cea426fee1216bec914fe2f56a",
64 // One of the projects being tested here is Cargo, and when being tested
65 // Cargo will at some point call `nmake.exe` on Windows MSVC. Unfortunately
66 // `nmake` will read these two environment variables below and try to
67 // intepret them. We're likely being run, however, from MSYS `make` which
68 // uses the same variables.
70 // As a result, to prevent confusion and errors, we remove these variables
71 // from our environment to prevent passing MSYS make flags to nmake, causing
73 if cfg!(target_env = "msvc") {
74 env::remove_var("MAKE");
75 env::remove_var("MAKEFLAGS");
78 let args = env::args().collect::<Vec<_>>();
79 let ref cargo = args[1];
80 let out_dir = Path::new(&args[2]);
81 let ref cargo = Path::new(cargo);
83 for test in TEST_REPOS.iter().rev() {
84 test_repo(cargo, out_dir, test);
88 fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
89 println!("testing {}", test.repo);
90 let dir = clone_repo(test, out_dir);
91 if let Some(lockfile) = test.lock {
92 File::create(&dir.join("Cargo.lock"))
94 .write_all(lockfile.as_bytes())
97 if !run_cargo_test(cargo, &dir) {
98 panic!("tests failed for {}", test.repo);
102 fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
103 let out_dir = out_dir.join(test.name);
105 if !out_dir.join(".git").is_dir() {
106 let status = Command::new("git")
111 assert!(status.success());
114 // Try progressively deeper fetch depths to find the commit
115 let mut found = false;
116 for depth in &[0, 1, 10, 100, 1000, 100000] {
118 let status = Command::new("git")
122 .arg(&format!("--depth={}", depth))
123 .current_dir(&out_dir)
126 assert!(status.success());
129 let status = Command::new("git")
133 .current_dir(&out_dir)
137 if status.success() {
144 panic!("unable to find commit {}", test.sha)
146 let status = Command::new("git")
149 .current_dir(&out_dir)
152 assert!(status.success());
157 fn run_cargo_test(cargo_path: &Path, crate_path: &Path) -> bool {
158 let status = Command::new(cargo_path)
160 // Disable rust-lang/cargo's cross-compile tests
161 .env("CFG_DISABLE_CROSS_TESTS", "1")
162 .current_dir(crate_path)