Skip to content

Commit

Permalink
Add function for creating temporary files
Browse files Browse the repository at this point in the history
  • Loading branch information
fishrockz authored and cmyr committed Apr 17, 2020
1 parent c42a71b commit 559ad1f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion druid/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,43 @@

//! Additional unit tests that cross file or module boundaries.
mod harness;
pub(crate) mod harness;
mod helpers;
mod layout_tests;

use std::cell::Cell;
use std::env;
use std::fs;
use std::rc::Rc;
use tempfile;

use crate::widget::*;
use crate::*;
use harness::*;
use helpers::*;

/// This function creates a temporary directory and returns a PathBuf to it.
///
/// This directory will be created relative to the executable and will therefor
/// be created in the target directory for tests when running with cargo. The
/// directory will be cleaned up at the end of the PathBufs lifetime. This
/// uses the `tempfile` crate.
#[allow(dead_code)]
pub fn temp_dir_for_test() -> std::path::PathBuf {
let current_exe_path = env::current_exe().unwrap();
let mut exe_dir = current_exe_path.parent().unwrap();
if exe_dir.ends_with("deps") {
exe_dir = exe_dir.parent().unwrap();
}
let test_dir = exe_dir.parent().unwrap().join("tests");
fs::create_dir_all(&test_dir).unwrap();
tempfile::Builder::new()
.prefix("TempDir")
.tempdir_in(test_dir)
.unwrap()
.into_path()
}

/// test that the first widget to request focus during an event gets it.
#[test]
fn propogate_hot() {
Expand Down

0 comments on commit 559ad1f

Please sign in to comment.