1
1
use std:: fs;
2
2
use std:: path:: Path ;
3
- use std:: process:: Command ;
3
+ use std:: process:: { exit , Command } ;
4
4
5
5
#[ allow( dead_code) ]
6
6
pub fn assert_files_eq < T : AsRef < Path > , Q : AsRef < Path > > ( ref_file : T , gen_file : Q ) {
@@ -25,17 +25,28 @@ pub fn assert_files_eq<T: AsRef<Path>, Q: AsRef<Path>>(ref_file: T, gen_file: Q)
25
25
}
26
26
27
27
/// execute cargo build and check that build is successfull
28
- pub fn assert_cargo_build ( package_folder : tempfile:: TempDir ) {
28
+ pub fn assert_cargo_build ( package_folder : & tempfile:: TempDir , toolchain_override : Option < String > ) {
29
+ Command :: new ( "cargo" )
30
+ . arg ( "clean" )
31
+ . current_dir ( package_folder. path ( ) )
32
+ . output ( )
33
+ . expect ( "Failed to clean package" ) ;
29
34
// Run cargo to build
30
35
let mut command = Command :: new ( "cargo" ) ;
36
+ let toolchain_id = if let Some ( ref toolchain_id) = toolchain_override {
37
+ command. arg ( format ! ( "+{}" , toolchain_id) ) ;
38
+ toolchain_id
39
+ } else {
40
+ "default"
41
+ } ;
31
42
command. arg ( "build" ) ;
32
43
command. current_dir ( package_folder. path ( ) ) ;
33
44
let exec_result = command. output ( ) ;
34
45
35
46
if exec_result. is_err ( ) {
36
- // This to preserve the project for further debugging
37
- let _ = package_folder . into_path ( ) ;
38
- panic ! ( "Failed to execute" ) ;
47
+ eprintln ! ( "Failed to execute using toolchain: {}" , toolchain_id ) ;
48
+ // This to preserve the temp folders for further debugging
49
+ exit ( - 1 ) ;
39
50
}
40
51
let output_result = exec_result. unwrap ( ) ;
41
52
if !output_result. status . success ( ) {
@@ -45,29 +56,46 @@ pub fn assert_cargo_build(package_folder: tempfile::TempDir) {
45
56
. expect ( "Failed to parse stderr returned from cargo build" ) ;
46
57
eprintln ! ( "Failed compilation of test project stdout: {}" , stdout_msg) ;
47
58
eprintln ! ( "Failed compilation of test project stderr: {}" , stderr_msg) ;
48
- // This to preserve the project for further debugging
49
- let _ = package_folder. into_path ( ) ;
50
- panic ! ( "Failed compilation of test project" ) ;
59
+ eprintln ! (
60
+ "Failed compilation of test project using toolchain: {}" ,
61
+ toolchain_id
62
+ ) ;
63
+ // This to preserve the temp folders for further debugging
64
+ exit ( -1 ) ;
51
65
}
52
66
}
53
67
54
68
#[ allow( dead_code) ]
55
- pub fn assert_cargo_test ( package_folder : tempfile:: TempDir ) {
69
+ pub fn assert_cargo_test ( package_folder : & tempfile:: TempDir , toolchain_override : Option < String > ) {
70
+ Command :: new ( "cargo" )
71
+ . arg ( "clean" )
72
+ . current_dir ( package_folder. path ( ) )
73
+ . output ( )
74
+ . expect ( "Failed to clean package" ) ;
56
75
// Run cargo to build
57
76
let mut command = Command :: new ( "cargo" ) ;
77
+ let toolchain_id = if let Some ( ref toolchain_id) = toolchain_override {
78
+ command. arg ( format ! ( "+{}" , toolchain_id) ) ;
79
+ toolchain_id
80
+ } else {
81
+ "default"
82
+ } ;
58
83
command. arg ( "test" ) ;
59
84
command. current_dir ( package_folder. path ( ) ) ;
60
85
61
86
let exec_result = command. output ( ) ;
62
87
63
88
if exec_result. is_err ( ) {
64
- // This to preserve the project for further debugging
65
- let _ = package_folder . into_path ( ) ;
66
- panic ! ( "Failed to execute tests" ) ;
89
+ eprintln ! ( "Failed to execute tests using toolchain: {}" , toolchain_id ) ;
90
+ // This to preserve the temp folders for further debugging
91
+ exit ( - 1 ) ;
67
92
}
68
93
if !exec_result. unwrap ( ) . status . success ( ) {
69
- // This to preserve the project for further debugging
70
- let _ = package_folder. into_path ( ) ;
71
- panic ! ( "Failed running tests of test project" ) ;
94
+ eprintln ! (
95
+ "Failed running tests of test project using toolchain: {}" ,
96
+ toolchain_id
97
+ ) ;
98
+ // This to preserve the temp folders for further debugging
99
+ exit ( -1 ) ;
72
100
}
73
101
}
0 commit comments