Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Change -l to conflict with -n and -c #152

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand Down
19 changes: 10 additions & 9 deletions src/bin/hexyl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down Expand Up @@ -304,9 +305,9 @@ impl NonNegativeI64 {
}
}

impl Into<u64> for NonNegativeI64 {
fn into(self) -> u64 {
u64::try_from(self.0)
impl From<NonNegativeI64> for u64 {
fn from(x: NonNegativeI64) -> u64 {
u64::try_from(x.0)
.expect("invariant broken: NonNegativeI64 should contain a non-negative i64 value")
}
}
Expand All @@ -328,9 +329,9 @@ impl PositiveI64 {
}
}

impl Into<u64> for PositiveI64 {
fn into(self) -> u64 {
u64::try_from(self.0)
impl From<PositiveI64> for u64 {
fn from(x: PositiveI64) -> u64 {
u64::try_from(x.0)
.expect("invariant broken: PositiveI64 should contain a positive i64 value")
}
}
Expand All @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down