]>
git.proxmox.com Git - rustc.git/blob - src/tools/cargotest/main.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use std
::process
::Command
;
13 use std
::path
::{Path, PathBuf}
;
21 lock
: Option
<&'
static str>,
24 const TEST_REPOS
: &'
static [Test
] = &[
27 repo
: "https://github.com/iron/iron",
28 sha
: "21c7dae29c3c214c08533c2a55ac649b418f2fe3",
29 lock
: Some(include_str
!("lockfiles/iron-Cargo.lock")),
33 repo
: "https://github.com/BurntSushi/ripgrep",
34 sha
: "b65bb37b14655e1a89c7cd19c8b011ef3e312791",
39 repo
: "https://github.com/Aaronepower/tokei",
40 sha
: "5e11c4852fe4aa086b0e4fe5885822fbe57ba928",
45 repo
: "https://github.com/dzamlo/treeify",
46 sha
: "999001b223152441198f117a68fb81f57bc086dd",
51 repo
: "https://github.com/BurntSushi/xsv",
52 sha
: "a9a7163f2a2953cea426fee1216bec914fe2f56a",
58 let args
= env
::args().collect
::<Vec
<_
>>();
59 let ref cargo
= args
[1];
60 let out_dir
= Path
::new(&args
[2]);
61 let ref cargo
= Path
::new(cargo
);
63 for test
in TEST_REPOS
.iter().rev() {
64 test_repo(cargo
, out_dir
, test
);
68 fn test_repo(cargo
: &Path
, out_dir
: &Path
, test
: &Test
) {
69 println
!("testing {}", test
.repo
);
70 let dir
= clone_repo(test
, out_dir
);
71 if let Some(lockfile
) = test
.lock
{
72 File
::create(&dir
.join("Cargo.lock"))
74 .write_all(lockfile
.as_bytes())
77 if !run_cargo_test(cargo
, &dir
) {
78 panic
!("tests failed for {}", test
.repo
);
82 fn clone_repo(test
: &Test
, out_dir
: &Path
) -> PathBuf
{
83 let out_dir
= out_dir
.join(test
.name
);
85 if !out_dir
.join(".git").is_dir() {
86 let status
= Command
::new("git")
91 assert
!(status
.success());
94 // Try progressively deeper fetch depths to find the commit
95 let mut found
= false;
96 for depth
in &[0, 1, 10, 100, 1000, 100000] {
98 let status
= Command
::new("git")
102 .arg(&format
!("--depth={}", depth
))
103 .current_dir(&out_dir
)
106 assert
!(status
.success());
109 let status
= Command
::new("git")
113 .current_dir(&out_dir
)
117 if status
.success() {
124 panic
!("unable to find commit {}", test
.sha
)
126 let status
= Command
::new("git")
129 .current_dir(&out_dir
)
132 assert
!(status
.success());
137 fn run_cargo_test(cargo_path
: &Path
, crate_path
: &Path
) -> bool
{
138 let status
= Command
::new(cargo_path
)
140 // Disable rust-lang/cargo's cross-compile tests
141 .env("CFG_DISABLE_CROSS_TESTS", "1")
142 .current_dir(crate_path
)