2 use std::process::Command;
3 use std::path::{Path, PathBuf};
10 lock: Option<&'static str>,
11 packages: &'static [&'static str],
14 const TEST_REPOS: &'static [Test] = &[
17 repo: "https://github.com/iron/iron",
18 sha: "21c7dae29c3c214c08533c2a55ac649b418f2fe3",
19 lock: Some(include_str!("lockfiles/iron-Cargo.lock")),
24 repo: "https://github.com/BurntSushi/ripgrep",
25 sha: "ad9befbc1d3b5c695e7f6b6734ee1b8e683edd41",
31 repo: "https://github.com/XAMPPRocky/tokei",
32 sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
38 repo: "https://github.com/dzamlo/treeify",
39 sha: "999001b223152441198f117a68fb81f57bc086dd",
45 repo: "https://github.com/BurntSushi/xsv",
46 sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f",
52 repo: "https://github.com/servo/servo",
53 sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b",
55 // Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
56 // This takes much less time to build than all of Servo and supports stable Rust.
57 packages: &["selectors"],
61 repo: "https://github.com/servo/webrender",
62 sha: "cdadd068f4c7218bd983d856981d561e605270ab",
69 let args = env::args().collect::<Vec<_>>();
70 let ref cargo = args[1];
71 let out_dir = Path::new(&args[2]);
72 let ref cargo = Path::new(cargo);
74 for test in TEST_REPOS.iter().rev() {
75 test_repo(cargo, out_dir, test);
79 fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
80 println!("testing {}", test.repo);
81 let dir = clone_repo(test, out_dir);
82 if let Some(lockfile) = test.lock {
83 fs::write(&dir.join("Cargo.lock"), lockfile).unwrap();
85 if !run_cargo_test(cargo, &dir, test.packages) {
86 panic!("tests failed for {}", test.repo);
90 fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
91 let out_dir = out_dir.join(test.name);
93 if !out_dir.join(".git").is_dir() {
94 let status = Command::new("git")
99 assert!(status.success());
102 // Try progressively deeper fetch depths to find the commit
103 let mut found = false;
104 for depth in &[0, 1, 10, 100, 1000, 100000] {
106 let status = Command::new("git")
110 .arg(&format!("--depth={}", depth))
111 .current_dir(&out_dir)
114 assert!(status.success());
117 let status = Command::new("git")
121 .current_dir(&out_dir)
125 if status.success() {
132 panic!("unable to find commit {}", test.sha)
134 let status = Command::new("git")
137 .current_dir(&out_dir)
140 assert!(status.success());
145 fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
146 let mut command = Command::new(cargo_path);
148 for name in packages {
149 command.arg("-p").arg(name);
152 // Disable rust-lang/cargo's cross-compile tests
153 .env("CFG_DISABLE_CROSS_TESTS", "1")
154 // Relax #![deny(warnings)] in some crates
155 .env("RUSTFLAGS", "--cap-lints warn")
156 .current_dir(crate_path)