Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

develop -> master for 0.3.2 #47

Merged
merged 18 commits into from
Nov 9, 2020
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
66 changes: 66 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
**/*.rs.bk

.DS_Store

# ci code coverage
tarpaulin-report.html
cobertura.xml
5 changes: 5 additions & 0 deletions .tarpaulin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[default]
# Expected one of `Tests`, `Doctests`, `Benchmarks`, `Examples`, `Lib`, `Bins`, `AllTargets`
run-types = ["Tests"]
[report]
out = ["Html", "Xml"]
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fmt:
cargo fmt --verbose

debug:
export RUSTFLAGS=""
cargo build

release: test
Expand All @@ -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)
Expand Down
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -402,8 +405,10 @@ pub fn output_array(
"{}",
match array_format {
"r" => "];",
"c" => "};",
"c" | "j" => "};",
"g" => "}",
"p" => "]",
"k" => ")",
_ => "unknown array format",
}
)
Expand Down Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}
}
}
}