summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/tests
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp-ffi/tests')
-rw-r--r--openpgp-ffi/tests/c-tests.rs31
1 files changed, 25 insertions, 6 deletions
diff --git a/openpgp-ffi/tests/c-tests.rs b/openpgp-ffi/tests/c-tests.rs
index e3057e5c..6802de0c 100644
--- a/openpgp-ffi/tests/c-tests.rs
+++ b/openpgp-ffi/tests/c-tests.rs
@@ -117,7 +117,26 @@ fn for_all_rs<F>(src: &Path, mut fun: F)
Ok(())
}
+/// If this looks like an exported function, returns its name.
+fn exported_function_name(line: &str) -> Option<&str> {
+ if line.starts_with("pub extern \"system\" fn ")
+ || line.starts_with("fn pgp_")
+ {
+ let fn_i = line.find("fn ")?;
+ let name_start = fn_i + 3;
+ (&line[name_start..]).split(|c| !is_valid_identifier(c)).next()
+ } else {
+ None
+ }
+}
+
+fn is_valid_identifier(c: char) -> bool {
+ char::is_alphanumeric(c) || c == '_'
+}
+
/// Maps the given function `fun` over all tests found in `path`.
+///
+/// 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<()> {
@@ -143,12 +162,12 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
continue;
}
- if line.starts_with("pub extern \"system\" fn ") && test.len() > 0 {
- let name = &line[23..].split_terminator('(')
- .next().unwrap().to_owned();
- fun(path, test_starts_at, &name, replace(&mut test, Vec::new()),
- run)?;
- test.clear();
+ if let Some(name) = exported_function_name(&line) {
+ if test.len() > 0 {
+ fun(path, test_starts_at, &name, replace(&mut test, vec![]),
+ run)?;
+ test.clear();
+ }
}
} else {
if line == "/// ```" {