diff options
author | Julian Sitkevich <1553398+sitkevij@users.noreply.github.com> | 2020-11-09 08:33:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-09 08:33:08 -0800 |
commit | 2e34704eba10e0619d5ddcb5f98cce0d06f53d9e (patch) | |
tree | cf10fde4db1267cabf3895880395a1ceaae8cb10 | |
parent | de4c13e8c3703773a746cff9df7cd02b3e8c7f8b (diff) | |
parent | 0f46232ac1af1c792d4f5b74e80e5fed07d8e4fb (diff) |
Merge pull request #47 from sitkevij/developv0.3.2
develop -> master for 0.3.2
-rw-r--r-- | .github/workflows/ci.yml | 66 | ||||
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | .tarpaulin.toml | 5 | ||||
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Makefile | 23 | ||||
-rw-r--r-- | README.md | 33 | ||||
-rw-r--r-- | src/lib.rs | 18 | ||||
-rw-r--r-- | src/main.rs | 27 |
9 files changed, 165 insertions, 17 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e4cd193 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: CI +on: + pull_request: + push: + branches: + - develop + - main + - master + +env: + RUST_BACKTRACE: full + +jobs: + test: + name: Test Rust ${{ matrix.rust }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.experimental }} + strategy: + fail-fast: false + matrix: + include: + - { rust: stable, os: ubuntu-latest, experimental: false } + - { rust: stable, os: macos-latest, experimental: false } + - { rust: stable, os: windows-latest, experimental: true } + - { rust: stable-i686-msvc, os: windows-latest, experimental: true } + - { rust: beta, os: ubuntu-latest, experimental: true } + - { rust: nightly, os: ubuntu-latest, experimental: true } + steps: + - uses: actions/checkout@v2 + - uses: hecrj/setup-rust-action@v1 + with: + rust-version: ${{ matrix.rust }} + + - run: cargo build --verbose --all + - run: cargo build --release + - run: cargo test --verbose --all -- --nocapture + - run: cargo install hyperfine + - run: echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." | target/release/hx + - run: hyperfine --warmup 20 "echo 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' | target/release/hx" + # - run: cargo test --verbose --all -- --nocapture + # - run: cargo test --verbose --workspace --all-features + # - run: cargo test --verbose --workspace --no-default-features + + clippy: + name: Lint with clippy + runs-on: ubuntu-latest + env: + RUSTFLAGS: -Dwarnings + steps: + - uses: actions/checkout@v2 + - uses: hecrj/setup-rust-action@v1 + with: + components: clippy + - run: cargo clippy --workspace --all-targets --verbose + - run: cargo clippy --workspace --all-targets --verbose --no-default-features + - run: cargo clippy --workspace --all-targets --verbose --all-features + + rustfmt: + name: Verify code formatting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: hecrj/setup-rust-action@v1 + with: + components: rustfmt + - run: cargo fmt --all -- --check @@ -10,3 +10,7 @@ **/*.rs.bk .DS_Store + +# ci code coverage +tarpaulin-report.html +cobertura.xml
\ No newline at end of file diff --git a/.tarpaulin.toml b/.tarpaulin.toml new file mode 100644 index 0000000..d0e55d3 --- /dev/null +++ b/.tarpaulin.toml @@ -0,0 +1,5 @@ +[default] +# Expected one of `Tests`, `Doctests`, `Benchmarks`, `Examples`, `Lib`, `Bins`, `AllTargets` +run-types = ["Tests"] +[report] +out = ["Html", "Xml"] @@ -61,7 +61,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hx" -version = "0.3.1" +version = "0.3.2" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "assert_cmd 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1,13 +1,13 @@ [package] authors = ["sitkevij"] -categories = ["command-line-utilities","debugging"] +categories = ["command-line-utilities","development-tools"] description = "Futuristic take on hexdump, made in Rust." include = ["src/**/*","Cargo.toml","Cargo.lock"] repository = "https://github.com/sitkevij/hex" keywords = ["hexdump", "hexadecimal", "tools", "ascii", "hex"] license = "MIT" name = "hx" -version = "0.3.1" +version = "0.3.2" edition = "2018" # see https://doc.rust-lang.org/cargo/reference/manifest.html @@ -17,6 +17,7 @@ fmt: cargo fmt --verbose debug: + export RUSTFLAGS="" cargo build release: test @@ -25,6 +26,28 @@ release: test test: cargo test --verbose --all -- --nocapture +geiger: + # cargo install cargo-geiger + cargo geiger + +tarpaulin: + # use docker as tarpaulin only supports x86_64 processors running linux + docker run --security-opt seccomp=unconfined -v "${PWD}:/volume" xd009642/tarpaulin + open tarpaulin-report.html + +grcov: + # grcov requires rust nightly for now + rm -rf target/debug/ + # export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off" + export CARGO_INCREMENTAL=0 && \ + export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" && \ + export RUSTDOCFLAGS="-Cpanic=abort" && \ + cargo +nightly build + cargo +nightly test --verbose + grcov ./target/debug/ -s . -t html --llvm --branch --ignore-not-existing -o ./target/debug/coverage/ + open target/debug/coverage/index.html + + install: release debug test cargo install --path . ## cp $(RELEASE_DIR)/$(BINARY) $(INSTALL_DIR)/$(BINARY) @@ -93,9 +93,9 @@ If `<USERDIR>/.cargo/bin` is part of the `PATH` environment variable, `hx` shoul ## features -### output arrays in `rust`, `c` or `golang` +### output arrays in `rust`, `c`, `golang`, `python`, `kotlin`, or `java` -`hx` has a feature which can output the input file bytes as source code arrays. +`hx` has a feature which can output the input file bytes as source code arrays. For example: @@ -126,6 +126,33 @@ a := [3]byte{ } ``` +#### python array: -ap + +```sh +$ hx -ap -c8 tests/files/tiny.txt +a = [ + 0x69, 0x6c, 0x0a +] +``` + +#### kotlin array: -ak + +```sh +$ hx -ak -c8 tests/files/tiny.txt +val a = byteArrayOf( + 0x69, 0x6c, 0x0a +) +``` + +#### java array: -aj + +```sh +$ hx -aj -c8 tests/files/tiny.txt +byte[] a = new byte[]{ + 0x69, 0x6c, 0x0a +}; +``` + ## manual ```txt @@ -141,7 +168,7 @@ FLAGS: -V, --version Prints version information OPTIONS: - -a, --array <array_format> Set source code format output: rust (r), C (c), golang (g) [possible values: r, c, g] + -a, --array <array_format> Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j) [possible values: r, c, g, p, k, j] -t, --color <color> Set color tint terminal output. 0 to disable, 1 to enable [possible values: 0, 1] -c, --cols <columns> Set column length -f, --format <format> Set format of octet: Octal (o), LowerHex (x), UpperHex (X), Binary (b) [possible @@ -335,11 +335,11 @@ pub fn run(matches: ArgMatches) -> Result<(), Box<dyn Error>> { /// # Arguments /// /// * `matches` - argument matches. +#[allow(clippy::absurd_extreme_comparisons)] pub fn is_stdin(matches: ArgMatches) -> Result<bool, Box<dyn Error>> { let mut is_stdin = false; if DBG > 0 { dbg!(env::args().len(), matches.args.len()); - dbg!(env::args().nth(0).unwrap()); } if let Some(file) = matches.value_of(ARG_INP) { if DBG > 0 { @@ -381,6 +381,9 @@ pub fn output_array( "r" => writeln!(locked, "let ARRAY: [u8; {}] = [", page.bytes)?, "c" => writeln!(locked, "unsigned char ARRAY[{}] = {{", page.bytes)?, "g" => writeln!(locked, "a := [{}]byte{{", page.bytes)?, + "p" => writeln!(locked, "a = [")?, + "k" => writeln!(locked, "val a = byteArrayOf(")?, + "j" => writeln!(locked, "byte[] a = new byte[]{{")?, _ => writeln!(locked, "unknown array format")?, } let mut i: u64 = 0x0; @@ -402,8 +405,10 @@ pub fn output_array( "{}", match array_format { "r" => "];", - "c" => "};", + "c" | "j" => "};", "g" => "}", + "p" => "]", + "k" => ")", _ => "unknown array format", } ) @@ -508,6 +513,15 @@ mod tests { assert_eq!(hex_binary(b), "0b11111111"); assert_eq!(hex_binary(b), format!("{:#010b}", b)); } + + #[test] + fn test_line_struct() { + let mut ascii_line: Line = Line::new(); + ascii_line.ascii.push('.'); + assert_eq!(ascii_line.ascii[0], '.'); + assert_eq!(ascii_line.offset, 0x0); + } + use assert_cmd::Command; /// target/debug/hx -ar tests/files/tiny.txt diff --git a/src/main.rs b/src/main.rs index 2c19a30..d4a1063 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ mod lib; use clap::{App, Arg}; use lib::{ARG_ARR, ARG_CLR, ARG_COL, ARG_FMT, ARG_FNC, ARG_INP, ARG_LEN, ARG_PLC}; use std::env; +use std::io::Error; +use std::io::ErrorKind; use std::process; /// Central application entry point. @@ -58,8 +60,8 @@ fn main() { .short("a") .long(ARG_ARR) .value_name("array_format") - .help("Set source code format output: rust (r), C (c), golang (g)") - .possible_values(&["r", "c", "g"]) + .help("Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j)") + .possible_values(&["r", "c", "g", "p", "k", "j"]) .takes_value(true), ) .arg( @@ -84,13 +86,20 @@ fn main() { Ok(_) => { process::exit(0); } - Err(e) => { - eprintln!( - "{} {}", - ansi_term::Colour::Fixed(9).bold().paint("error:"), - e - ); - process::exit(1); + Err(_) => { + let err = &Error::last_os_error(); + let suppress_error = match err.kind() { + ErrorKind::BrokenPipe => process::exit(0), + _ => false, + }; + if !suppress_error { + eprintln!( + "{} {}", + ansi_term::Colour::Fixed(9).bold().paint("error:"), + err + ); + process::exit(1); + } } } } |