From 692b2bbfec202c8b57adff5c3fdc1593f0b4b32f Mon Sep 17 00:00:00 2001 From: Mathieu Poumeyrol Date: Thu, 26 Jan 2017 11:55:18 +0100 Subject: [PATCH] external files in test support on iOS I agree to license my contributions to each file under the terms given at the top of each file I changed. --- src/bssl.rs | 2 ++ src/test.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/bssl.rs b/src/bssl.rs index e5ff7552b1..ccfc45e825 100644 --- a/src/bssl.rs +++ b/src/bssl.rs @@ -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() @@ -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 }; diff --git a/src/test.rs b/src/test.rs index ac0b3e51ab..56dbf8b46c 100644 --- a/src/test.rs +++ b/src/test.rs @@ -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 @@ -225,7 +242,7 @@ impl TestCase { pub fn from_file(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();