3 use std::path::{Path, PathBuf};
4 use std::process::Command;
10 lock: Option<&'static str>,
11 packages: &'static [&'static str],
14 const TEST_REPOS: &[Test] = &[
17 repo: "https://github.com/iron/iron",
18 sha: "cf056ea5e8052c1feea6141e40ab0306715a2c33",
24 repo: "https://github.com/BurntSushi/ripgrep",
25 sha: "3de31f752729525d85a3d1575ac1978733b3f7e7",
31 repo: "https://github.com/XAMPPRocky/tokei",
32 sha: "fdf3f8cb279a7aeac0696c87e5d8b0cd946e4f9e",
38 repo: "https://github.com/BurntSushi/xsv",
39 sha: "3de6c04269a7d315f7e9864b9013451cd9580a08",
45 repo: "https://github.com/servo/servo",
46 sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b",
48 // Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
49 // This takes much less time to build than all of Servo and supports stable Rust.
50 packages: &["selectors"],
55 let args = env::args().collect::<Vec<_>>();
57 let out_dir = Path::new(&args[2]);
58 let cargo = &Path::new(cargo);
60 for test in TEST_REPOS.iter().rev() {
61 test_repo(cargo, out_dir, test);
65 fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
66 println!("testing {}", test.repo);
67 let dir = clone_repo(test, out_dir);
68 if let Some(lockfile) = test.lock {
69 fs::write(&dir.join("Cargo.lock"), lockfile).unwrap();
71 if !run_cargo_test(cargo, &dir, test.packages) {
72 panic!("tests failed for {}", test.repo);
76 fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
77 let out_dir = out_dir.join(test.name);
79 if !out_dir.join(".git").is_dir() {
80 let status = Command::new("git").arg("init").arg(&out_dir).status().unwrap();
81 assert!(status.success());
84 // Try progressively deeper fetch depths to find the commit
85 let mut found = false;
86 for depth in &[0, 1, 10, 100, 1000, 100000] {
88 let status = Command::new("git")
92 .arg(&format!("--depth={}", depth))
93 .current_dir(&out_dir)
96 assert!(status.success());
99 let status = Command::new("git")
103 .current_dir(&out_dir)
107 if status.success() {
114 panic!("unable to find commit {}", test.sha)
117 Command::new("git").arg("clean").arg("-fdx").current_dir(&out_dir).status().unwrap();
118 assert!(status.success());
123 fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool {
124 let mut command = Command::new(cargo_path);
126 for name in packages {
127 command.arg("-p").arg(name);
130 // Disable rust-lang/cargo's cross-compile tests
131 .env("CFG_DISABLE_CROSS_TESTS", "1")
132 // Relax #![deny(warnings)] in some crates
133 .env("RUSTFLAGS", "--cap-lints warn")
134 .current_dir(crate_path)