Prettier format panic message in spectest.

This commit is contained in:
losfair 2020-03-10 02:45:31 +08:00
parent 3ff3554345
commit 79613e42d7

View File

@ -256,6 +256,16 @@ mod tests {
Memory, Table,
};
fn format_panic(e: &dyn std::any::Any) -> String {
if let Some(s) = e.downcast_ref::<&str>() {
format!("{}", s)
} else if let Some(s) = e.downcast_ref::<String>() {
format!("{}", s)
} else {
"(unknown)".into()
}
}
fn parse_and_run(
path: &PathBuf,
file_excludes: &HashSet<String>,
@ -342,7 +352,7 @@ mod tests {
file: filename.to_string(),
line: line,
kind: format!("{}", "Module"),
message: format!("caught panic {:?}", e),
message: format!("caught panic {:?}", format_panic(&e)),
},
&test_key,
excludes,
@ -798,7 +808,7 @@ mod tests {
file: filename.to_string(),
line: line,
kind: format!("{}", "AssertInvalid"),
message: format!("caught panic {:?}", p),
message: format!("caught panic {:?}", format_panic(&p)),
},
&test_key,
excludes,
@ -851,7 +861,7 @@ mod tests {
file: filename.to_string(),
line: line,
kind: format!("{}", "AssertMalformed"),
message: format!("caught panic {:?}", p),
message: format!("caught panic {:?}", format_panic(&p)),
},
&test_key,
excludes,
@ -975,7 +985,7 @@ mod tests {
file: filename.to_string(),
line: line,
kind: format!("{}", "AssertUnlinkable"),
message: format!("caught panic {:?}", e),
message: format!("caught panic {:?}", format_panic(&e)),
},
&test_key,
excludes,