diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-04-05 12:37:02 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-04-05 12:40:00 +0200 |
commit | 4bdb96f2b53b585f40b74254f4a508d4862dbd5c (patch) | |
tree | c97a5ba5e422445448f82fb85aef7df4a0edb029 /openpgp/tests/for-each-artifact.rs | |
parent | 77a277e247ae9f215cf681cf1b0afa1be2a12f4f (diff) |
openpgp: Improve test by roundtripping all messages.
- Fixes #243.
Diffstat (limited to 'openpgp/tests/for-each-artifact.rs')
-rw-r--r-- | openpgp/tests/for-each-artifact.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/openpgp/tests/for-each-artifact.rs b/openpgp/tests/for-each-artifact.rs index d92faded..d8728a09 100644 --- a/openpgp/tests/for-each-artifact.rs +++ b/openpgp/tests/for-each-artifact.rs @@ -43,6 +43,24 @@ mod for_each_artifact { Ok(()) }).unwrap(); } + + #[test] + fn message_roundtrip() { + for_all_files(&test_data_dir(), |src| { + let p = if let Ok(tpk) = openpgp::Message::from_file(src) { + tpk + } else { + // Ignore non-Message files. + return Ok(()); + }; + + let mut v = Vec::new(); + p.serialize(&mut v)?; + let q = openpgp::Message::from_bytes(&v)?; + assert_eq!(p, q, "roundtripping {:?} failed", src); + Ok(()) + }).unwrap(); + } } /// Computes the path to the test directory. @@ -66,7 +84,13 @@ fn for_all_files<F>(src: &Path, mut fun: F) -> openpgp::Result<()> let entry = entry?; let path = entry.path(); if path.is_file() { - fun(&path)?; + match fun(&path) { + Ok(_) => (), + Err(e) => { + eprintln!("Failed on file {:?}:\n", path); + return Err(e); + }, + } } if path.is_dir() { dirs.push(path.clone()); |