88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- extern crate tempdir;
12-
13- use tempdir:: TempDir ;
1411use std:: env;
1512use std:: process:: Command ;
16- use std:: path:: Path ;
13+ use std:: path:: { Path , PathBuf } ;
1714use std:: fs:: File ;
1815use std:: io:: Write ;
1916
20- const TEST_REPOS : & ' static [ ( & ' static str , & ' static str , Option < & ' static str > ) ] = & [
21- ( "https://github.com/rust-lang/cargo" ,
22- "fae9c539388f1b7c70c31fd0a21b5dd9cd071177" ,
23- None ) ,
24- ( "https://github.com/iron/iron" ,
25- "16c858ec2901e2992fe5e529780f59fa8ed12903" ,
26- Some ( include_str ! ( "lockfiles/iron-Cargo.lock" ) ) )
17+ struct Test {
18+ repo : & ' static str ,
19+ name : & ' static str ,
20+ sha : & ' static str ,
21+ lock : Option < & ' static str > ,
22+ }
23+
24+ const TEST_REPOS : & ' static [ Test ] = & [
25+ Test {
26+ name : "cargo" ,
27+ repo : "https://github.com/rust-lang/cargo" ,
28+ sha : "fae9c539388f1b7c70c31fd0a21b5dd9cd071177" ,
29+ lock : None ,
30+ } ,
31+ Test {
32+ name : "iron" ,
33+ repo : "https://github.com/iron/iron" ,
34+ sha : "16c858ec2901e2992fe5e529780f59fa8ed12903" ,
35+ lock : Some ( include_str ! ( "lockfiles/iron-Cargo.lock" ) ) ,
36+ } ,
2737] ;
2838
2939
3040fn main ( ) {
31- let ref cargo = env:: args ( ) . collect :: < Vec < _ > > ( ) [ 1 ] ;
41+ let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
42+ let ref cargo = args[ 1 ] ;
43+ let out_dir = Path :: new ( & args[ 2 ] ) ;
3244 let ref cargo = Path :: new ( cargo) ;
3345
34- for & ( repo , sha , lockfile ) in TEST_REPOS . iter ( ) . rev ( ) {
35- test_repo ( cargo, repo , sha , lockfile ) ;
46+ for test in TEST_REPOS . iter ( ) . rev ( ) {
47+ test_repo ( cargo, out_dir , test ) ;
3648 }
3749}
3850
39- fn test_repo ( cargo : & Path , repo : & str , sha : & str , lockfile : Option < & str > ) {
40- println ! ( "testing {}" , repo) ;
41- let dir = clone_repo ( repo , sha ) ;
42- if let Some ( lockfile) = lockfile {
43- File :: create ( & dir. path ( ) . join ( "Cargo.lock" ) ) . expect ( "" )
51+ fn test_repo ( cargo : & Path , out_dir : & Path , test : & Test ) {
52+ println ! ( "testing {}" , test . repo) ;
53+ let dir = clone_repo ( test , out_dir ) ;
54+ if let Some ( lockfile) = test . lock {
55+ File :: create ( & dir. join ( "Cargo.lock" ) ) . expect ( "" )
4456 . write_all ( lockfile. as_bytes ( ) ) . expect ( "" ) ;
4557 }
46- if !run_cargo_test ( cargo, dir. path ( ) ) {
47- panic ! ( "tests failed for {}" , repo) ;
58+ if !run_cargo_test ( cargo, & dir) {
59+ panic ! ( "tests failed for {}" , test . repo) ;
4860 }
4961}
5062
51- fn clone_repo ( repo : & str , sha : & str ) -> TempDir {
52- let dir = TempDir :: new ( "cargotest" ) . expect ( "" ) ;
53- let status = Command :: new ( "git" )
54- . arg ( "init" )
55- . arg ( dir. path ( ) )
56- . status ( )
57- . expect ( "" ) ;
58- assert ! ( status. success( ) ) ;
63+ fn clone_repo ( test : & Test , out_dir : & Path ) -> PathBuf {
64+ let out_dir = out_dir. join ( test. name ) ;
5965
60- // Try progressively deeper fetch depths to find the commit
61- let mut found = false ;
62- for depth in & [ 1 , 10 , 100 , 1000 , 100000 ] {
66+ if !out_dir. join ( ".git" ) . is_dir ( ) {
6367 let status = Command :: new ( "git" )
64- . arg ( "fetch" )
65- . arg ( repo)
66- . arg ( "master" )
67- . arg ( & format ! ( "--depth={}" , depth) )
68- . current_dir ( dir. path ( ) )
68+ . arg ( "init" )
69+ . arg ( & out_dir)
6970 . status ( )
7071 . expect ( "" ) ;
7172 assert ! ( status. success( ) ) ;
73+ }
74+
75+ // Try progressively deeper fetch depths to find the commit
76+ let mut found = false ;
77+ for depth in & [ 0 , 1 , 10 , 100 , 1000 , 100000 ] {
78+ if * depth > 0 {
79+ let status = Command :: new ( "git" )
80+ . arg ( "fetch" )
81+ . arg ( test. repo )
82+ . arg ( "master" )
83+ . arg ( & format ! ( "--depth={}" , depth) )
84+ . current_dir ( & out_dir)
85+ . status ( )
86+ . expect ( "" ) ;
87+ assert ! ( status. success( ) ) ;
88+ }
7289
7390 let status = Command :: new ( "git" )
7491 . arg ( "reset" )
75- . arg ( sha)
92+ . arg ( test . sha )
7693 . arg ( "--hard" )
77- . current_dir ( dir . path ( ) )
94+ . current_dir ( & out_dir )
7895 . status ( )
7996 . expect ( "" ) ;
8097
@@ -84,9 +101,18 @@ fn clone_repo(repo: &str, sha: &str) -> TempDir {
84101 }
85102 }
86103
87- if !found { panic ! ( "unable to find commit {}" , sha) }
104+ if !found {
105+ panic ! ( "unable to find commit {}" , test. sha)
106+ }
107+ let status = Command :: new ( "git" )
108+ . arg ( "clean" )
109+ . arg ( "-fdx" )
110+ . current_dir ( & out_dir)
111+ . status ( )
112+ . unwrap ( ) ;
113+ assert ! ( status. success( ) ) ;
88114
89- dir
115+ out_dir
90116}
91117
92118fn run_cargo_test ( cargo_path : & Path , crate_path : & Path ) -> bool {
0 commit comments