diff options
Diffstat (limited to 'test/long_mode/evex_generated.rs')
-rw-r--r-- | test/long_mode/evex_generated.rs | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/test/long_mode/evex_generated.rs b/test/long_mode/evex_generated.rs index dcb4e01..46d99a7 100644 --- a/test/long_mode/evex_generated.rs +++ b/test/long_mode/evex_generated.rs @@ -11,7 +11,17 @@ fn test_invalid(data: &[u8]) { fn test_invalid_under(decoder: &InstDecoder, data: &[u8]) { let mut reader = U8Reader::new(data); if let Ok(inst) = decoder.decode(&mut reader) { - panic!("decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder); + // realistically, the chances an error only shows up under non-fmt builds seems unlikely, + // but try to report *something* in such cases. + cfg_if::cfg_if! { + if #[cfg(feature="fmt")] { + panic!("decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder); + } else { + // don't warn about the unused inst here + let _ = inst; + panic!("decoded instruction <non-fmt build> from {:02x?} under decoder <non-fmt build>", data); + } + } } else { // this is fine } @@ -27,25 +37,39 @@ fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str for b in data { write!(hex, "{:02x}", b).unwrap(); } - let mut reader = U8Reader::new(data); + let mut reader = yaxpeax_arch::U8Reader::new(data); match decoder.decode(&mut reader) { Ok(instr) => { - let text = format!("{}", instr); - assert!( - text == expected, - "display error for {}:\n decoded: {:?} under decoder {}\n displayed: {}\n expected: {}\n", - hex, - instr, - decoder, - text, - expected - ); + cfg_if::cfg_if! { + if #[cfg(feature="fmt")] { + let text = format!("{}", instr); + assert!( + text == expected, + "display error for {}:\n decoded: {:?} under decoder {}\n displayed: {}\n expected: {}\n", + hex, + instr, + decoder, + text, + expected + ); + } else { + eprintln!("non-fmt build cannot compare text equality") + } + } // while we're at it, test that the instruction is as long, and no longer, than its // input assert_eq!((0u64.wrapping_offset(instr.len()).to_linear()) as usize, data.len(), "instruction length is incorrect, wanted instruction {}", expected); }, Err(e) => { - assert!(false, "decode error ({}) for {} under decoder {}:\n expected: {}\n", e, hex, decoder, expected); + cfg_if::cfg_if! { + if #[cfg(feature="fmt")] { + assert!(false, "decode error ({}) for {} under decoder {}:\n expected: {}\n", e, hex, decoder, expected); + } else { + // avoid the unused `e` warning + let _ = e; + assert!(false, "decode error (<non-fmt build>) for {} under decoder <non-fmt build>:\n expected: {}\n", hex, expected); + } + } } } } |