Explorar el Código

Silence only panics that expect panic

On panic, evaluate the test case for the expected panic flag, silence if so flagged.
sjj hace 7 años
padre
commit
9512b551f8
Se han modificado 1 ficheros con 13 adiciones y 2 borrados
  1. 13 2
      data-url/tests/wpt.rs

+ 13 - 2
data-url/tests/wpt.rs

@@ -1,7 +1,18 @@
 #[macro_use]
 extern crate serde;
 
-fn run_data_url(input: String, expected_mime: Option<String>, expected_body: Option<Vec<u8>>) {
+fn run_data_url(
+    input: String,
+    expected_mime: Option<String>,
+    expected_body: Option<Vec<u8>>,
+    expected_panic: bool,
+) {
+    let priorhook = std::panic::take_hook();
+    std::panic::set_hook(Box::new(move |p| {
+        if !expected_panic {
+            priorhook(p);
+        }
+    }));
     let url = data_url::DataUrl::process(&input);
     if let Some(expected_mime) = expected_mime {
         let url = url.unwrap();
@@ -43,7 +54,7 @@ where
             format!("data: URL {:?}", input),
             should_panic,
             rustc_test::TestFn::dyn_test_fn(move || {
-                run_data_url(input, expected_mime, expected_body)
+                run_data_url(input, expected_mime, expected_body, should_panic)
             }),
         );
     }