1
+ extern crate diff;
2
+ #[ macro_use]
3
+ extern crate lazy_static;
1
4
extern crate libbindgen;
2
5
extern crate tempdir;
3
- extern crate diff;
4
6
5
7
use std:: env;
6
8
use std:: fs;
@@ -9,18 +11,21 @@ use std::path::{Path, PathBuf};
9
11
use std:: process:: Command ;
10
12
use tempdir:: TempDir ;
11
13
12
- fn test_generated_bindings ( header : & PathBuf , output : & str ) -> Result < ( ) , ( ) > {
13
- let temp_dir = TempDir :: new ( "bindgen-tests" )
14
- . expect ( "Couldn't create temp dir" ) ;
14
+ lazy_static ! {
15
+ static ref TEMP_DIR : PathBuf = TempDir :: new( "libbindgen-tests" )
16
+ . expect( "Couldn't create temporary directory" )
17
+ . into_path( ) ;
18
+ }
15
19
20
+ fn test_generated_bindings ( header : & PathBuf , output : & str ) -> Result < ( ) , ( ) > {
16
21
let file_name = header. file_name ( )
17
22
. expect ( "test_generated_bindings expects a file" ) ;
18
23
19
- let mut source = temp_dir . path ( ) . to_owned ( ) ;
24
+ let mut source = TEMP_DIR . to_path_buf ( ) ;
20
25
source. push ( file_name) ;
21
26
source. set_extension ( "rs" ) ;
22
27
23
- let mut binary = temp_dir . path ( ) . to_owned ( ) ;
28
+ let mut binary = TEMP_DIR . to_path_buf ( ) ;
24
29
binary. push ( file_name) ;
25
30
binary. set_extension ( "bin" ) ;
26
31
@@ -168,6 +173,10 @@ fn run_bindgen_tests() {
168
173
169
174
let num_failures = failures. len ( ) ;
170
175
176
+ let temp_dir = TEMP_DIR . as_path ( ) ;
177
+ fs:: remove_dir_all ( temp_dir)
178
+ . expect ( format ! ( "Couldn't clean up temporary directory: {:?}" , temp_dir) . as_str ( ) ) ;
179
+
171
180
if num_failures > 0 {
172
181
panic ! ( "{} test failures!" , num_failures) ;
173
182
}
0 commit comments