Skip to content

Commit

Permalink
refactor: simplify cov
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Jul 21, 2023
1 parent feccc9d commit 7effe4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
25 changes: 5 additions & 20 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,11 @@ jobs:
- name: Cache Project
uses: Swatinem/rust-cache@v2

- name: Generate Code coverage
env:
CARGO_INCREMENTAL: '0'
LLVM_PROFILE_FILE: "homestar-%p-%m.profraw"
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
# covering nexttest's doc-test issue
run: cargo test --all-features

- name: Install grcov
run: "curl -L https://github.com/mozilla/grcov/releases/download/v0.8.12/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf -"

- name: Run grcov
run: "./grcov . --llvm --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '/*' -o lcov.info"

- name: Install covfix
run: cargo install --force rust-covfix

- name: Run covfix
run: rust-covfix lcov.info -o lcov.info --verbose
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Generate Code Coverage
run: cargo llvm-cov --all-features --workspace --doctests --lcov --output-path lcov.info

- name: Upload to codecov.io
uses: codecov/codecov-action@v3
Expand Down
31 changes: 18 additions & 13 deletions homestar-runtime/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn test_help_serial() -> Result<()> {
.stdout(predicate::str::contains("run"))
.stdout(predicate::str::contains("help"))
.stdout(predicate::str::contains("version"));
let _ = stop_bin();

Ok(())
}
Expand All @@ -71,13 +72,16 @@ fn test_version_serial() -> Result<()> {
crate_name!(),
env!("CARGO_PKG_VERSION")
)));
let _ = stop_bin();

Ok(())
}

#[test]
#[serial]
fn test_server_not_running_serial() -> Result<()> {
let _ = stop_bin();

Command::new(BIN.as_os_str())
.arg("ping")
.assert()
Expand Down Expand Up @@ -111,6 +115,7 @@ fn test_server_not_running_serial() -> Result<()> {
predicate::str::contains("Connection refused")
.or(predicate::str::contains("server was already shutdown")),
);
let _ = stop_bin();

Ok(())
}
Expand Down Expand Up @@ -162,26 +167,25 @@ fn test_server_serial() -> Result<()> {

let _ = Command::new(BIN.as_os_str()).arg("stop").output();

match homestar_proc.try_wait() {
Ok(Some(_)) => Ok(()),
Ok(None) => {
let _status_code = match homestar_proc.wait_timeout(Duration::from_secs(1)).unwrap() {
Some(status) => status.code(),
None => {
homestar_proc.kill().unwrap();
homestar_proc.wait().unwrap().code()
}
};
Ok(())
}
Err(_e) => Ok(()),
if let Ok(None) = homestar_proc.try_wait() {
let _status_code = match homestar_proc.wait_timeout(Duration::from_secs(1)).unwrap() {
Some(status) => status.code(),
None => {
homestar_proc.kill().unwrap();
homestar_proc.wait().unwrap().code()
}
};
}
let _ = stop_bin();

Ok(())
}

#[test]
#[serial]
fn test_daemon_serial() -> Result<()> {
let _ = stop_bin();

Command::new(BIN.as_os_str())
.arg("start")
.arg("-d")
Expand Down Expand Up @@ -215,6 +219,7 @@ fn test_daemon_serial() -> Result<()> {
let _result = signal::kill(Pid::from_raw(pid), Signal::SIGTERM);

Command::new(BIN.as_os_str()).arg("ping").assert().failure();
let _ = stop_bin();

Ok(())
}

0 comments on commit 7effe4f

Please sign in to comment.