Skip to content

Commit 4d9fdc8

Browse files
committed
Global temporary directory
1 parent a603c16 commit 4d9fdc8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

libbindgen/tests/tests.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
extern crate diff;
2+
#[macro_use]
3+
extern crate lazy_static;
14
extern crate libbindgen;
25
extern crate tempdir;
3-
extern crate diff;
46

57
use std::env;
68
use std::fs;
@@ -9,18 +11,21 @@ use std::path::{Path, PathBuf};
911
use std::process::Command;
1012
use tempdir::TempDir;
1113

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+
}
1519

20+
fn test_generated_bindings(header: &PathBuf, output: &str) -> Result<(), ()> {
1621
let file_name = header.file_name()
1722
.expect("test_generated_bindings expects a file");
1823

19-
let mut source = temp_dir.path().to_owned();
24+
let mut source = TEMP_DIR.to_path_buf();
2025
source.push(file_name);
2126
source.set_extension("rs");
2227

23-
let mut binary = temp_dir.path().to_owned();
28+
let mut binary = TEMP_DIR.to_path_buf();
2429
binary.push(file_name);
2530
binary.set_extension("bin");
2631

@@ -168,6 +173,10 @@ fn run_bindgen_tests() {
168173

169174
let num_failures = failures.len();
170175

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+
171180
if num_failures > 0 {
172181
panic!("{} test failures!", num_failures);
173182
}

0 commit comments

Comments
 (0)