Skip to content

Commit

Permalink
external files in test support on iOS
Browse files Browse the repository at this point in the history
I agree to license my contributions to each file under the terms given
at the top of each file I changed.
  • Loading branch information
kali committed Jan 26, 2017
1 parent 200edfc commit 692b2bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/bssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ macro_rules! bssl_test {
}

init::init_once();
::std::env::set_current_dir(::test::ring_src_path()).unwrap();

let result = unsafe {
$bssl_test_main_fn_name()
Expand All @@ -61,6 +62,7 @@ macro_rules! bssl_test_rng {
}

init::init_once();
::std::env::set_current_dir(::test::ring_src_path()).unwrap();

let rng = rand::SystemRandom::new();
let mut rng = rand::RAND { rng: &rng };
Expand Down
19 changes: 18 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ impl TestCase {
}
}

/// Returns the path for *ring* source code root.
///
/// On iOS, source are assumed to be copied in the application bundle, as
/// a "src" directory along the test runner.
#[cfg(target_os = "ios")]
pub fn ring_src_path() -> std::path::PathBuf {
std::env::current_exe().unwrap().parent().unwrap().join("src")
}

/// Returns the path for *ring* source code root.
///
/// On most platforms, the tests are run by cargo, so it's just the current
/// working directory.
#[cfg(not(target_os = "ios"))]
pub fn ring_src_path() -> std::path::PathBuf {
std::path::PathBuf::from(".")
}

/// Reads test cases out of the file with the path given by
/// `test_data_relative_file_path`, calling `f` on each vector until `f` fails
Expand All @@ -225,7 +242,7 @@ impl TestCase {
pub fn from_file<F>(test_data_relative_file_path: &str, mut f: F)
where F: FnMut(&str, &mut TestCase)
-> Result<(), error::Unspecified> {
let path = std::path::Path::new(test_data_relative_file_path);
let path = ring_src_path().join(test_data_relative_file_path);
let file = std::fs::File::open(path).unwrap();
let mut lines = std::io::BufReader::new(&file).lines();

Expand Down

0 comments on commit 692b2bb

Please sign in to comment.