Skip to content

Commit 69c9765

Browse files
committed
Add test asserting we catch Rust parser panics
1 parent 8222381 commit 69c9765

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/test/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ fn stdin_formatting_smoke_test() {
288288
assert_eq!(buf, "fn main() {}\r\n".as_bytes());
289289
}
290290

291+
#[test]
292+
fn stdin_parser_panic_caught() {
293+
// https://github.com/rust-lang/rustfmt/issues/3239
294+
for text in ["{", "}"].iter().cloned().map(String::from) {
295+
let res = ::std::panic::catch_unwind(|| {
296+
let mut buf = vec![];
297+
let mut session = Session::new(Default::default(), Some(&mut buf));
298+
session.format(Input::Text(text))
299+
});
300+
assert!(res.is_ok());
301+
}
302+
}
303+
291304
#[test]
292305
fn stdin_disable_all_formatting_test() {
293306
match option_env!("CFG_RELEASE_CHANNEL") {

0 commit comments

Comments
 (0)