summaryrefslogtreecommitdiffstats
path: root/ffi/tests
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-05-13 15:41:16 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-05-13 15:41:16 +0200
commitec19b193720cca4529dc0bb109e615dff7a5959f (patch)
tree8d2b5059bc42595baf30a1c04b1816ed2eb92031 /ffi/tests
parentf77e71462d27181760bd1fe4eb5a5b34594e58a2 (diff)
openpgp-ffi, ffi: Improve c-tests.rs.
- Use failure, improve error message when invoking make fails.
Diffstat (limited to 'ffi/tests')
-rw-r--r--ffi/tests/c-tests.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/ffi/tests/c-tests.rs b/ffi/tests/c-tests.rs
index 986468fd..7cbec614 100644
--- a/ffi/tests/c-tests.rs
+++ b/ffi/tests/c-tests.rs
@@ -1,3 +1,5 @@
+extern crate failure;
+use failure::{Fallible as Result, ResultExt};
extern crate filetime;
extern crate nettle;
@@ -77,7 +79,7 @@ fn c_doctests() {
}
/// Builds the shared object.
-fn build_so(base: &Path) -> io::Result<()> {
+fn build_so(base: &Path) -> Result<()> {
let st = Command::new("cargo")
.current_dir(base)
.arg("build")
@@ -86,7 +88,8 @@ fn build_so(base: &Path) -> io::Result<()> {
.arg("sequoia-ffi")
.status().unwrap();
if ! st.success() {
- return Err(io::Error::new(io::ErrorKind::Other, "compilation failed"));
+ return Err(io::Error::new(io::ErrorKind::Other, "compilation failed")
+ .into());
}
Ok(())
@@ -94,8 +97,8 @@ fn build_so(base: &Path) -> io::Result<()> {
/// Maps the given function `fun` over all Rust files in `src`.
fn for_all_rs<F>(src: &Path, mut fun: F)
- -> io::Result<()>
- where F: FnMut(&Path) -> io::Result<()> {
+ -> Result<()>
+ where F: FnMut(&Path) -> Result<()> {
let mut dirs = vec![src.to_path_buf()];
while let Some(dir) = dirs.pop() {
@@ -134,8 +137,8 @@ fn is_valid_identifier(c: char) -> bool {
///
/// XXX: We need to parse the file properly with syn.
fn for_all_tests<F>(path: &Path, mut fun: F)
- -> io::Result<()>
- where F: FnMut(&Path, usize, &str, Vec<String>, bool) -> io::Result<()> {
+ -> Result<()>
+ where F: FnMut(&Path, usize, &str, Vec<String>, bool) -> Result<()> {
let mut lineno = 0;
let mut test_starts_at = 0;
let f = fs::File::open(path)?;
@@ -192,7 +195,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
/// Writes and builds the c test iff it is out of date.
fn build(include_dirs: &[PathBuf], ldpath: &Path, target_dir: &Path,
src: &Path, lineno: usize, name: &str, mut lines: Vec<String>)
- -> io::Result<PathBuf> {
+ -> Result<PathBuf> {
let target = target_dir.join(&format!("{}", name));
let target_c = target_dir.join(&format!("{}.c", name));
let meta_rs = fs::metadata(&src).expect("rust source must be there");
@@ -230,16 +233,19 @@ fn build(include_dirs: &[PathBuf], ldpath: &Path, target_dir: &Path,
.arg("-C").arg(&target_dir)
.arg("--quiet")
.arg(target.file_name().unwrap())
- .status()?;
+ .status()
+ .context("Compiling the C-tests requires Make \
+ and a cc-compatible compiler")?;
if ! st.success() {
- return Err(io::Error::new(io::ErrorKind::Other, "compilation failed"));
+ return Err(io::Error::new(io::ErrorKind::Other, "compilation failed")
+ .into());
}
Ok(target)
}
/// Runs the test case.
-fn run(ldpath: &Path, exe: &Path) -> io::Result<()> {
+fn run(ldpath: &Path, exe: &Path) -> Result<()> {
let st =
if let Ok(valgrind) = env::var("SEQUOIA_CTEST_VALGRIND") {
Command::new(valgrind)
@@ -256,7 +262,7 @@ fn run(ldpath: &Path, exe: &Path) -> io::Result<()> {
.status()?
};
if ! st.success() {
- return Err(io::Error::new(io::ErrorKind::Other, "failed"));
+ return Err(io::Error::new(io::ErrorKind::Other, "failed").into());
}
Ok(())
}