8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- extern crate tempdir;
12
-
13
- use tempdir:: TempDir ;
14
11
use std:: env;
15
12
use std:: process:: Command ;
16
- use std:: path:: Path ;
13
+ use std:: path:: { Path , PathBuf } ;
17
14
use std:: fs:: File ;
18
15
use std:: io:: Write ;
19
16
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
+ } ,
27
37
] ;
28
38
29
39
30
40
fn 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 ] ) ;
32
44
let ref cargo = Path :: new ( cargo) ;
33
45
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 ) ;
36
48
}
37
49
}
38
50
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 ( "" )
44
56
. write_all ( lockfile. as_bytes ( ) ) . expect ( "" ) ;
45
57
}
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) ;
48
60
}
49
61
}
50
62
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 ) ;
59
65
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 ( ) {
63
67
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)
69
70
. status ( )
70
71
. expect ( "" ) ;
71
72
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
+ }
72
89
73
90
let status = Command :: new ( "git" )
74
91
. arg ( "reset" )
75
- . arg ( sha)
92
+ . arg ( test . sha )
76
93
. arg ( "--hard" )
77
- . current_dir ( dir . path ( ) )
94
+ . current_dir ( & out_dir )
78
95
. status ( )
79
96
. expect ( "" ) ;
80
97
@@ -84,9 +101,18 @@ fn clone_repo(repo: &str, sha: &str) -> TempDir {
84
101
}
85
102
}
86
103
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( ) ) ;
88
114
89
- dir
115
+ out_dir
90
116
}
91
117
92
118
fn run_cargo_test ( cargo_path : & Path , crate_path : & Path ) -> bool {
0 commit comments