summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Sitkevich <1553398+sitkevij@users.noreply.github.com>2020-11-04 09:02:53 -0800
committerGitHub <noreply@github.com>2020-11-04 09:02:53 -0800
commit4caa73c3db378208c661a2ee125da2c2374f7363 (patch)
tree63684545c1782888989c2afd40de505e90e3df4f
parentf031a489a609a225acba421413e785a0a8cc8aac (diff)
parent89c1d942d1e3d8cde04ebf278aa02053ac56b91a (diff)
Merge pull request #41 from sitkevij/enhance/suppress_pipe
#40 suppress broken pipe reporting, return 0
-rw-r--r--Makefile16
-rw-r--r--src/lib.rs9
-rw-r--r--src/main.rs23
3 files changed, 41 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 69fd7a6..4f1d1df 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@ fmt:
cargo fmt --verbose
debug:
+ export RUSTFLAGS=""
cargo build
release: test
@@ -25,6 +26,21 @@ release: test
test:
cargo test --verbose --all -- --nocapture
+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
+ # generate html report
+ grcov ./target/debug/ -s . -t html --llvm --branch --ignore-not-existing -o ./target/debug/coverage/
+ # open report
+ open target/debug/coverage/index.html
+
+
install: release debug test
cargo install --path .
## cp $(RELEASE_DIR)/$(BINARY) $(INSTALL_DIR)/$(BINARY)
diff --git a/src/lib.rs b/src/lib.rs
index 3504f91..d53be51 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -513,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 81c003c..bb14e61 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.
@@ -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 == false {
+ eprintln!(
+ "{} {}",
+ ansi_term::Colour::Fixed(9).bold().paint("error:"),
+ err
+ );
+ process::exit(1);
+ }
}
}
}