diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 220d97dd..d0b1aaea 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -27,11 +27,25 @@ jobs: toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }} default: true profile: minimal # minimal component installation (ie, no documentation) + components: clippy, rustfmt + + - name: Ensure `cargo fmt` has been run + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + - name: Run clippy (on minimum supported rust version to prevent warnings we can't fix) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --locked --all-targets - name: Run tests uses: actions-rs/cargo@v1 with: command: test + args: --locked build: name: ${{ matrix.job.os }} (${{ matrix.job.target }}) diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index e57ca71c..367cc4e7 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -61,6 +61,7 @@ fn run() -> Result<(), AnyhowError> { .short("l") .takes_value(true) .value_name("N") + .conflicts_with_all(&["length", "bytes"]) .hidden(true) .help("Yet another alias for -n/--length"), ) @@ -304,9 +305,9 @@ impl NonNegativeI64 { } } -impl Into for NonNegativeI64 { - fn into(self) -> u64 { - u64::try_from(self.0) +impl From for u64 { + fn from(x: NonNegativeI64) -> u64 { + u64::try_from(x.0) .expect("invariant broken: NonNegativeI64 should contain a non-negative i64 value") } } @@ -328,9 +329,9 @@ impl PositiveI64 { } } -impl Into for PositiveI64 { - fn into(self) -> u64 { - u64::try_from(self.0) +impl From for u64 { + fn from(x: PositiveI64) -> u64 { + u64::try_from(x.0) .expect("invariant broken: PositiveI64 should contain a positive i64 value") } } @@ -357,9 +358,9 @@ impl Unit { match self { Self::Byte => 1, Self::Kilobyte => 1000, - Self::Megabyte => 1000_000, - Self::Gigabyte => 1000_000_000, - Self::Terabyte => 1000_000_000_000, + Self::Megabyte => 1_000_000, + Self::Gigabyte => 1_000_000_000, + Self::Terabyte => 1_000_000_000_000, Self::Kibibyte => 1 << 10, Self::Mebibyte => 1 << 20, Self::Gibibyte => 1 << 30, diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 0508e532..bc718add 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -85,6 +85,30 @@ mod length { .assert() .failure(); } + + #[test] + fn fail_if_length_and_count_options_are_used_simultaneously() { + hexyl() + .arg("hello_world_elf64") + .arg("--length=32") + .arg("-l=10") + .assert() + .failure(); + } +} + +mod bytes { + use super::hexyl; + + #[test] + fn fail_if_bytes_and_count_options_are_used_simultaneously() { + hexyl() + .arg("hello_world_elf64") + .arg("--bytes=32") + .arg("-l=10") + .assert() + .failure(); + } } mod skip {