5 use std::path::{Path, PathBuf};
6 use std::process::Command;
12 lock: Option<&'static str>,
13 packages: &'static [&'static str],
16 const TEST_REPOS: &'static [Test] = &[
19 repo: "https://github.com/iron/iron",
20 sha: "cf056ea5e8052c1feea6141e40ab0306715a2c33",
26 repo: "https://github.com/BurntSushi/ripgrep",
27 sha: "ad9befbc1d3b5c695e7f6b6734ee1b8e683edd41",
33 repo: "https://github.com/XAMPPRocky/tokei",
34 sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
40 repo: "https://github.com/dzamlo/treeify",
41 sha: "999001b223152441198f117a68fb81f57bc086dd",
47 repo: "https://github.com/BurntSushi/xsv",
48 sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f",
54 repo: "https://github.com/servo/servo",
55 sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b",
57 // Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
58 // This takes much less time to build than all of Servo and supports stable Rust.
59 packages: &["selectors"],
64 let args = env::args().collect::<Vec<_>>();
65 let ref cargo = args[1];
66 let out_dir = Path::new(&args[2]);
67 let ref cargo = Path::new(cargo);
69 for test in TEST_REPOS.iter().rev() {
70 test_repo(cargo, out_dir, test);
74 fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
75 println!("testing {}", test.repo);
76 let dir = clone_repo(test, out_dir);
77 if let Some(lockfile) = test.lock {
78 fs::write(&dir.join("Cargo.lock"), lockfile).unwrap();
80 if !run_cargo_test(cargo, &dir, test.packages) {
81 panic!("tests failed for {}", test.repo);
85 fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
86 let out_dir = out_dir.join(test.name);
88 if !out_dir.join(".git").is_dir() {
89 let status = Command::new("git").arg("init").arg(&out_dir).status().expect("");
90 assert!(status.success());
93 // Try progressively deeper fetch depths to find the commit
94 let mut found = false;
95 for depth in &[0, 1, 10, 100, 1000, 100000] {
97 let status = Command::new("git")
101 .arg(&format!("--depth={}", depth))
102 .current_dir(&out_dir)
105 assert!(status.success());
108 let status = Command::new("git")
112 .current_dir(&out_dir)
116 if status.success() {
123 panic!("unable to find commit {}", test.sha)
126 Command::new("git").arg("clean").arg("-fdx").current_dir(&out_dir).status().unwrap();
127 assert!(status.success());
132 fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
133 let mut command = Command::new(cargo_path);
135 for name in packages {
136 command.arg("-p").arg(name);
139 // Disable rust-lang/cargo's cross-compile tests
140 .env("CFG_DISABLE_CROSS_TESTS", "1")
141 // Relax #![deny(warnings)] in some crates
142 .env("RUSTFLAGS", "--cap-lints warn")
143 .current_dir(crate_path)