Fix file-based tests on iOS.

I agree to license my contributions to each file under the terms given
at the top of each file I changed.
This commit is contained in:
Mathieu Poumeyrol 2017-01-26 11:55:18 +01:00 committed by Brian Smith
parent f53e7a6f68
commit e4443e8541
2 changed files with 20 additions and 1 deletions

View File

@ -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 };

View File

@ -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<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();