]>
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
] = &[Test
{
26 repo
: "https://github.com/rust-lang/cargo",
27 sha
: "806e3c368a15f618244a3b4e918bf77f9c403fd0",
32 repo
: "https://github.com/iron/iron",
33 sha
: "16c858ec2901e2992fe5e529780f59fa8ed12903",
34 lock
: Some(include_str
!("lockfiles/iron-Cargo.lock")),
39 // One of the projects being tested here is Cargo, and when being tested
40 // Cargo will at some point call `nmake.exe` on Windows MSVC. Unfortunately
41 // `nmake` will read these two environment variables below and try to
42 // intepret them. We're likely being run, however, from MSYS `make` which
43 // uses the same variables.
45 // As a result, to prevent confusion and errors, we remove these variables
46 // from our environment to prevent passing MSYS make flags to nmake, causing
48 if cfg
!(target_env
= "msvc") {
49 env
::remove_var("MAKE");
50 env
::remove_var("MAKEFLAGS");
53 let args
= env
::args().collect
::<Vec
<_
>>();
54 let ref cargo
= args
[1];
55 let out_dir
= Path
::new(&args
[2]);
56 let ref cargo
= Path
::new(cargo
);
58 for test
in TEST_REPOS
.iter().rev() {
59 test_repo(cargo
, out_dir
, test
);
63 fn test_repo(cargo
: &Path
, out_dir
: &Path
, test
: &Test
) {
64 println
!("testing {}", test
.repo
);
65 let dir
= clone_repo(test
, out_dir
);
66 if let Some(lockfile
) = test
.lock
{
67 File
::create(&dir
.join("Cargo.lock"))
69 .write_all(lockfile
.as_bytes())
72 if !run_cargo_test(cargo
, &dir
) {
73 panic
!("tests failed for {}", test
.repo
);
77 fn clone_repo(test
: &Test
, out_dir
: &Path
) -> PathBuf
{
78 let out_dir
= out_dir
.join(test
.name
);
80 if !out_dir
.join(".git").is_dir() {
81 let status
= Command
::new("git")
86 assert
!(status
.success());
89 // Try progressively deeper fetch depths to find the commit
90 let mut found
= false;
91 for depth
in &[0, 1, 10, 100, 1000, 100000] {
93 let status
= Command
::new("git")
97 .arg(&format
!("--depth={}", depth
))
98 .current_dir(&out_dir
)
101 assert
!(status
.success());
104 let status
= Command
::new("git")
108 .current_dir(&out_dir
)
112 if status
.success() {
119 panic
!("unable to find commit {}", test
.sha
)
121 let status
= Command
::new("git")
124 .current_dir(&out_dir
)
127 assert
!(status
.success());
132 fn run_cargo_test(cargo_path
: &Path
, crate_path
: &Path
) -> bool
{
133 let status
= Command
::new(cargo_path
)
135 // Disable rust-lang/cargo's cross-compile tests
136 .env("CFG_DISABLE_CROSS_TESTS", "1")
137 .current_dir(crate_path
)