]>
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 | ||
32a655c1 | 14 | const TEST_REPOS: &'static [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", | |
b7449926 | 25 | sha: "ad9befbc1d3b5c695e7f6b6734ee1b8e683edd41", |
32a655c1 | 26 | lock: None, |
abe05a73 | 27 | packages: &[], |
32a655c1 SL |
28 | }, |
29 | Test { | |
30 | name: "tokei", | |
532ac7d7 | 31 | repo: "https://github.com/XAMPPRocky/tokei", |
32a655c1 SL |
32 | sha: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928", |
33 | lock: None, | |
abe05a73 | 34 | packages: &[], |
32a655c1 SL |
35 | }, |
36 | Test { | |
37 | name: "treeify", | |
38 | repo: "https://github.com/dzamlo/treeify", | |
39 | sha: "999001b223152441198f117a68fb81f57bc086dd", | |
40 | lock: None, | |
abe05a73 | 41 | packages: &[], |
32a655c1 SL |
42 | }, |
43 | Test { | |
44 | name: "xsv", | |
45 | repo: "https://github.com/BurntSushi/xsv", | |
abe05a73 | 46 | sha: "66956b6bfd62d6ac767a6b6499c982eae20a2c9f", |
32a655c1 | 47 | lock: None, |
abe05a73 XL |
48 | packages: &[], |
49 | }, | |
50 | Test { | |
51 | name: "servo", | |
52 | repo: "https://github.com/servo/servo", | |
416331ca | 53 | sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b", |
abe05a73 XL |
54 | lock: None, |
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. | |
0bf4aa26 | 57 | packages: &["selectors"], |
abe05a73 | 58 | }, |
32a655c1 | 59 | ]; |
54a0048b SL |
60 | |
61 | fn main() { | |
a7813a04 XL |
62 | let args = env::args().collect::<Vec<_>>(); |
63 | let ref cargo = args[1]; | |
64 | let out_dir = Path::new(&args[2]); | |
54a0048b SL |
65 | let ref cargo = Path::new(cargo); |
66 | ||
a7813a04 XL |
67 | for test in TEST_REPOS.iter().rev() { |
68 | test_repo(cargo, out_dir, test); | |
54a0048b SL |
69 | } |
70 | } | |
71 | ||
a7813a04 XL |
72 | fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) { |
73 | println!("testing {}", test.repo); | |
74 | let dir = clone_repo(test, out_dir); | |
75 | if let Some(lockfile) = test.lock { | |
0731742a | 76 | fs::write(&dir.join("Cargo.lock"), lockfile).unwrap(); |
54a0048b | 77 | } |
abe05a73 | 78 | if !run_cargo_test(cargo, &dir, test.packages) { |
a7813a04 | 79 | panic!("tests failed for {}", test.repo); |
54a0048b SL |
80 | } |
81 | } | |
82 | ||
a7813a04 XL |
83 | fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf { |
84 | let out_dir = out_dir.join(test.name); | |
54a0048b | 85 | |
a7813a04 | 86 | if !out_dir.join(".git").is_dir() { |
dfeec247 | 87 | let status = Command::new("git").arg("init").arg(&out_dir).status().expect(""); |
54a0048b | 88 | assert!(status.success()); |
a7813a04 XL |
89 | } |
90 | ||
91 | // Try progressively deeper fetch depths to find the commit | |
92 | let mut found = false; | |
93 | for depth in &[0, 1, 10, 100, 1000, 100000] { | |
94 | if *depth > 0 { | |
95 | let status = Command::new("git") | |
dfeec247 XL |
96 | .arg("fetch") |
97 | .arg(test.repo) | |
98 | .arg("master") | |
99 | .arg(&format!("--depth={}", depth)) | |
100 | .current_dir(&out_dir) | |
101 | .status() | |
102 | .expect(""); | |
a7813a04 XL |
103 | assert!(status.success()); |
104 | } | |
54a0048b SL |
105 | |
106 | let status = Command::new("git") | |
dfeec247 XL |
107 | .arg("reset") |
108 | .arg(test.sha) | |
109 | .arg("--hard") | |
110 | .current_dir(&out_dir) | |
111 | .status() | |
112 | .expect(""); | |
54a0048b SL |
113 | |
114 | if status.success() { | |
115 | found = true; | |
116 | break; | |
117 | } | |
118 | } | |
119 | ||
a7813a04 XL |
120 | if !found { |
121 | panic!("unable to find commit {}", test.sha) | |
122 | } | |
dfeec247 XL |
123 | let status = |
124 | Command::new("git").arg("clean").arg("-fdx").current_dir(&out_dir).status().unwrap(); | |
a7813a04 | 125 | assert!(status.success()); |
54a0048b | 126 | |
a7813a04 | 127 | out_dir |
54a0048b SL |
128 | } |
129 | ||
abe05a73 XL |
130 | fn run_cargo_test(cargo_path: &Path, crate_path: &Path, packages: &[&str]) -> bool { |
131 | let mut command = Command::new(cargo_path); | |
132 | command.arg("test"); | |
133 | for name in packages { | |
134 | command.arg("-p").arg(name); | |
135 | } | |
136 | let status = command | |
54a0048b SL |
137 | // Disable rust-lang/cargo's cross-compile tests |
138 | .env("CFG_DISABLE_CROSS_TESTS", "1") | |
abe05a73 XL |
139 | // Relax #![deny(warnings)] in some crates |
140 | .env("RUSTFLAGS", "--cap-lints warn") | |
54a0048b SL |
141 | .current_dir(crate_path) |
142 | .status() | |
143 | .expect(""); | |
144 | ||
145 | status.success() | |
146 | } |