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};
20 lock: Option<&'static str>,
21 packages: &'static [&'static str],
24 const TEST_REPOS: &'static [Test] = &[
27 repo: "https://github.com/iron/iron",
28 sha: "21c7dae29c3c214c08533c2a55ac649b418f2fe3",
29 lock: Some(include_str!("lockfiles/iron-Cargo.lock")),
34 repo: "https://github.com/BurntSushi/ripgrep",
35 sha: "ad9befbc1d3b5c695e7f6b6734ee1b8e683edd41",
41 repo: "https://github.com/Aaronepower/tokei",
42 sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
48 repo: "https://github.com/dzamlo/treeify",
49 sha: "999001b223152441198f117a68fb81f57bc086dd",
55 repo: "https://github.com/BurntSushi/xsv",
56 sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f",
62 repo: "https://github.com/servo/servo",
63 sha: "987e376ca7a4245dbc3e0c06e963278ee1ac92d1",
65 // Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
66 // This takes much less time to build than all of Servo and supports stable Rust.
67 packages: &["selectors"],
71 repo: "https://github.com/servo/webrender",
72 sha: "57250b2b8fa63934f80e5376a29f7dcb3f759ad6",
79 let args = env::args().collect::<Vec<_>>();
80 let ref cargo = args[1];
81 let out_dir = Path::new(&args[2]);
82 let ref cargo = Path::new(cargo);
84 for test in TEST_REPOS.iter().rev() {
85 test_repo(cargo, out_dir, test);
89 fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
90 println!("testing {}", test.repo);
91 let dir = clone_repo(test, out_dir);
92 if let Some(lockfile) = test.lock {
93 fs::write(&dir.join("Cargo.lock"), lockfile).unwrap();
95 if !run_cargo_test(cargo, &dir, test.packages) {
96 panic!("tests failed for {}", test.repo);
100 fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
101 let out_dir = out_dir.join(test.name);
103 if !out_dir.join(".git").is_dir() {
104 let status = Command::new("git")
109 assert!(status.success());
112 // Try progressively deeper fetch depths to find the commit
113 let mut found = false;
114 for depth in &[0, 1, 10, 100, 1000, 100000] {
116 let status = Command::new("git")
120 .arg(&format!("--depth={}", depth))
121 .current_dir(&out_dir)
124 assert!(status.success());
127 let status = Command::new("git")
131 .current_dir(&out_dir)
135 if status.success() {
142 panic!("unable to find commit {}", test.sha)
144 let status = Command::new("git")
147 .current_dir(&out_dir)
150 assert!(status.success());
155 fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
156 let mut command = Command::new(cargo_path);
158 for name in packages {
159 command.arg("-p").arg(name);
162 // Disable rust-lang/cargo's cross-compile tests
163 .env("CFG_DISABLE_CROSS_TESTS", "1")
164 // Relax #![deny(warnings)] in some crates
165 .env("RUSTFLAGS", "--cap-lints warn")
166 .current_dir(crate_path)