]>
Commit | Line | Data |
---|---|---|
54a0048b | 1 | use std::env; |
0731742a | 2 | use std::fs; |
dfeec247 XL |
3 | use std::path::{Path, PathBuf}; |
4 | use std::process::Command; | |
54a0048b | 5 | |
a7813a04 XL |
6 | struct Test { |
7 | repo: &'static str, | |
8 | name: &'static str, | |
9 | sha: &'static str, | |
10 | lock: Option<&'static str>, | |
abe05a73 | 11 | packages: &'static [&'static str], |
a7813a04 XL |
12 | } |
13 | ||
3dfed10e | 14 | const TEST_REPOS: &[Test] = &[ |
32a655c1 SL |
15 | Test { |
16 | name: "iron", | |
17 | repo: "https://github.com/iron/iron", | |
e74abb32 XL |
18 | sha: "cf056ea5e8052c1feea6141e40ab0306715a2c33", |
19 | lock: None, | |
abe05a73 | 20 | packages: &[], |
32a655c1 SL |
21 | }, |
22 | Test { | |
23 | name: "ripgrep", | |
24 | repo: "https://github.com/BurntSushi/ripgrep", | |
1b1a35ee | 25 | sha: "3de31f752729525d85a3d1575ac1978733b3f7e7", |
32a655c1 | 26 | lock: None, |
abe05a73 | 27 | packages: &[], |
32a655c1 SL |
28 | }, |
29 | Test { | |
30 | name: "tokei", | |
532ac7d7 | 31 | repo: "https://github.com/XAMPPRocky/tokei", |
1b1a35ee | 32 | sha: "fdf3f8cb279a7aeac0696c87e5d8b0cd946e4f9e", |
32a655c1 | 33 | lock: None, |
abe05a73 | 34 | packages: &[], |
32a655c1 SL |
35 | }, |
36 | Test { | |
37 | name: "xsv", | |
38 | repo: "https://github.com/BurntSushi/xsv", | |
abe05a73 | 39 | sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f", |
32a655c1 | 40 | lock: None, |
abe05a73 XL |
41 | packages: &[], |
42 | }, | |
43 | Test { | |
44 | name: "servo", | |
45 | repo: "https://github.com/servo/servo", | |
416331ca | 46 | sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b", |
abe05a73 XL |
47 | lock: None, |
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. | |
0bf4aa26 | 50 | packages: &["selectors"], |
abe05a73 | 51 | }, |
32a655c1 | 52 | ]; |
54a0048b SL |
53 | |
54 | fn main() { | |
a7813a04 | 55 | let args = env::args().collect::<Vec<_>>(); |
3dfed10e | 56 | let cargo = &args[1]; |
a7813a04 | 57 | let out_dir = Path::new(&args[2]); |
3dfed10e | 58 | let cargo = &Path::new(cargo); |
54a0048b | 59 | |
a7813a04 XL |
60 | for test in TEST_REPOS.iter().rev() { |
61 | test_repo(cargo, out_dir, test); | |
54a0048b SL |
62 | } |
63 | } | |
64 | ||
a7813a04 XL |
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 { | |
0731742a | 69 | fs::write(&dir.join("Cargo.lock"), lockfile).unwrap(); |
54a0048b | 70 | } |
abe05a73 | 71 | if !run_cargo_test(cargo, &dir, test.packages) { |
a7813a04 | 72 | panic!("tests failed for {}", test.repo); |
54a0048b SL |
73 | } |
74 | } | |
75 | ||
a7813a04 XL |
76 | fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf { |
77 | let out_dir = out_dir.join(test.name); | |
54a0048b | 78 | |
a7813a04 | 79 | if !out_dir.join(".git").is_dir() { |
3dfed10e | 80 | let status = Command::new("git").arg("init").arg(&out_dir).status().unwrap(); |
54a0048b | 81 | assert!(status.success()); |
a7813a04 XL |
82 | } |
83 | ||
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] { | |
87 | if *depth > 0 { | |
88 | let status = Command::new("git") | |
dfeec247 XL |
89 | .arg("fetch") |
90 | .arg(test.repo) | |
91 | .arg("master") | |
92 | .arg(&format!("--depth={}", depth)) | |
93 | .current_dir(&out_dir) | |
94 | .status() | |
3dfed10e | 95 | .unwrap(); |
a7813a04 XL |
96 | assert!(status.success()); |
97 | } | |
54a0048b SL |
98 | |
99 | let status = Command::new("git") | |
dfeec247 XL |
100 | .arg("reset") |
101 | .arg(test.sha) | |
102 | .arg("--hard") | |
103 | .current_dir(&out_dir) | |
104 | .status() | |
3dfed10e | 105 | .unwrap(); |
54a0048b SL |
106 | |
107 | if status.success() { | |
108 | found = true; | |
109 | break; | |
110 | } | |
111 | } | |
112 | ||
a7813a04 XL |
113 | if !found { |
114 | panic!("unable to find commit {}", test.sha) | |
115 | } | |
dfeec247 XL |
116 | let status = |
117 | Command::new("git").arg("clean").arg("-fdx").current_dir(&out_dir).status().unwrap(); | |
a7813a04 | 118 | assert!(status.success()); |
54a0048b | 119 | |
a7813a04 | 120 | out_dir |
54a0048b SL |
121 | } |
122 | ||
abe05a73 XL |
123 | fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool { |
124 | let mut command = Command::new(cargo_path); | |
125 | command.arg("test"); | |
126 | for name in packages { | |
127 | command.arg("-p").arg(name); | |
128 | } | |
129 | let status = command | |
54a0048b SL |
130 | // Disable rust-lang/cargo's cross-compile tests |
131 | .env("CFG_DISABLE_CROSS_TESTS", "1") | |
abe05a73 XL |
132 | // Relax #![deny(warnings)] in some crates |
133 | .env("RUSTFLAGS", "--cap-lints warn") | |
54a0048b SL |
134 | .current_dir(crate_path) |
135 | .status() | |
3dfed10e | 136 | .unwrap(); |
54a0048b SL |
137 | |
138 | status.success() | |
139 | } |