Skip to content

Commit

Permalink
Test validate()
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Aug 1, 2024
1 parent 6288a67 commit 03786e5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,36 @@ mod tests {

Ok(())
}

#[test]
fn test_validate() -> Result<(), Box<dyn Error>> {
// Success first.
let meta = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("corpus")
.join("v2")
.join("minimal.json");

match validate(meta.as_os_str().to_str().unwrap()) {
Ok(_) => (),
Err(e) => panic!("Validation failed: {e}"),
}

// Invalid next.
let meta = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("corpus")
.join("invalid.json");

match std::panic::catch_unwind(|| validate(meta.as_os_str().to_str().unwrap())) {
Ok(_) => panic!("Should have failed on invalid.json but did not"),
Err(e) => {
if let Ok(msg) = e.downcast::<String>() {
assert!(msg.contains(" missing properties 'version"));
} else {
panic!("Unexpected panic error");
}
}
}

Ok(())
}
}

0 comments on commit 03786e5

Please sign in to comment.