diff options
-rw-r--r-- | goodfile | 26 | ||||
-rw-r--r-- | tests/lib.rs | 50 |
2 files changed, 65 insertions, 11 deletions
@@ -6,14 +6,18 @@ Build.run({"cargo", "build"}) Step.advance("test") Build.run({"cargo", "test"}, {name="test default features"}) -Build.run({"cargo", "test", "--no-default-features"}, {name="test no features"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "std"}, {name="test std only"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "colors"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "use-serde"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "address-parse"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "std,colors"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "std,use-serde"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "std,address-parse"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "use-serde,colors,address-parse"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "std,colors,address-parse"}, {name="test feature combinations"}) -Build.run({"cargo", "test", "--no-default-features", "--features", "std,use-serde,colors"}, {name="test feature combinations"}) + +-- `cargo test` ends up running doc tests. great! but yaxpeax-arch's docs reference items in std only. +-- so for other feature combinations, skip doc tests. do this by passing `--tests` explicitly, +-- which disables the automagic "run everything" settings. +Build.run({"cargo", "test", "--no-default-features", "--tests"}, {name="test no features"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "std"}, {name="test std only"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "colors"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "use-serde"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "address-parse"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "std,colors"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "std,use-serde"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "std,address-parse"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "use-serde,colors,address-parse"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "std,colors,address-parse"}, {name="test feature combinations"}) +Build.run({"cargo", "test", "--no-default-features", "--tests", "--features", "std,use-serde,colors"}, {name="test feature combinations"}) diff --git a/tests/lib.rs b/tests/lib.rs index 1d5e964..9dc1449 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -12,6 +12,7 @@ fn test_u16() { } #[test] +#[cfg(std)] fn generic_error_can_bail() { use yaxpeax_arch::{Arch, Decoder, Reader}; @@ -23,6 +24,7 @@ fn generic_error_can_bail() { } } #[test] +#[cfg(std)] fn error_can_bail() { use yaxpeax_arch::{Arch, AddressDiff, Decoder, Reader, LengthedInstruction, Instruction, StandardDecodeError, U8Reader}; struct TestIsa {} @@ -76,3 +78,51 @@ fn error_can_bail() { assert_eq!(exercise_eq(), Err(Error::TestDecode(StandardDecodeError::ExhaustedInput))); } + +#[test] +fn example_arch_impl() { + use yaxpeax_arch::{Arch, AddressDiff, Decoder, Reader, LengthedInstruction, Instruction, StandardDecodeError, U8Reader}; + struct TestIsa {} + #[derive(Debug, Default)] + struct TestInst {} + impl Arch for TestIsa { + type Word = u8; + type Address = u64; + type Instruction = TestInst; + type Decoder = TestIsaDecoder; + type DecodeError = StandardDecodeError; + type Operand = (); + } + + impl Instruction for TestInst { + fn well_defined(&self) -> bool { true } + } + + impl LengthedInstruction for TestInst { + type Unit = AddressDiff<u64>; + fn len(&self) -> Self::Unit { AddressDiff::from_const(1) } + fn min_size() -> Self::Unit { AddressDiff::from_const(1) } + } + + struct TestIsaDecoder {} + + impl Default for TestIsaDecoder { + fn default() -> Self { + TestIsaDecoder {} + } + } + + impl Decoder<TestIsa> for TestIsaDecoder { + fn decode_into<T: Reader<u64, u8>>(&self, _inst: &mut TestInst, _words: &mut T) -> Result<(), StandardDecodeError> { + Err(StandardDecodeError::ExhaustedInput) + } + } + + fn exercise_eq() -> Result<(), StandardDecodeError> { + let mut reader = U8Reader::new(&[]); + TestIsaDecoder::default().decode(&mut reader)?; + Ok(()) + } + + assert_eq!(exercise_eq(), Err(StandardDecodeError::ExhaustedInput)); +} |