summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/tests
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-23 16:59:42 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-23 17:52:15 +0100
commitb709e25b133d397fc0e6b591f566945257150374 (patch)
tree0ba43a4046c131a651632d6a78d636fd70d91696 /openpgp-ffi/tests
parent0aecb008d48ab955d5b9eca7de035cc27b38090d (diff)
openpgp-ffi: Paper over the shady parsing in c-tests.
- Fixes tests not being found because the functions signature were formatted differently. In the end, only proper parsing will help here.
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 == "/// ```" {