Skip to content

Commit

Permalink
Global temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jdub committed Nov 6, 2016
1 parent 7d7fbff commit eec7d27
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions libbindgen/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extern crate diff;
#[macro_use]
extern crate lazy_static;
extern crate libbindgen;
extern crate tempdir;
extern crate diff;

use std::env;
use std::fs;
Expand All @@ -9,18 +11,21 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use tempdir::TempDir;

fn test_generated_bindings(header: &PathBuf, output: &str) -> Result<(), ()> {
let temp_dir = TempDir::new("bindgen-tests")
.expect("Couldn't create temp dir");
lazy_static! {
static ref TEMP_DIR: PathBuf = TempDir::new("libbindgen-tests")
.expect("Couldn't create temporary directory")
.into_path();
}

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

let mut source = temp_dir.path().to_owned();
let mut source = TEMP_DIR.to_path_buf();
source.push(file_name);
source.set_extension("rs");

let mut binary = temp_dir.path().to_owned();
let mut binary = TEMP_DIR.to_path_buf();
binary.push(file_name);
binary.set_extension("bin");

Expand Down Expand Up @@ -168,6 +173,10 @@ fn run_bindgen_tests() {

let num_failures = failures.len();

let temp_dir = TEMP_DIR.as_path();
fs::remove_dir_all(temp_dir)
.expect(format!("Couldn't clean up temporary directory: {:?}", temp_dir).as_str());

if num_failures > 0 {
panic!("{} test failures!", num_failures);
}
Expand Down

0 comments on commit eec7d27

Please sign in to comment.