From 274032a91a3343790f67f6c4d420420f75792ab5 Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Fri, 25 Mar 2022 20:37:22 +0900 Subject: [PATCH 1/3] Add `rustfmt` and `clippy` to the CI --- .github/workflows/CICD.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 }}) From 8ce616ba0ad40869ad59b7be5a588ba659d3712e Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Fri, 25 Mar 2022 21:19:52 +0900 Subject: [PATCH 2/3] Fix Clippy warnings --- src/bin/hexyl.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index e57ca71c..1417c17a 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -304,9 +304,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 +328,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 +357,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, From 39745f66a6d6571ef0bb856b09b3cb1561b000da Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Fri, 25 Mar 2022 22:54:56 +0900 Subject: [PATCH 3/3] Change `-l` to conflict with `-n` and `-c` --- src/bin/hexyl.rs | 1 + tests/integration_tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index 1417c17a..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"), ) 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 {