Skip to content

Commit

Permalink
ci: add coveralls coverage reporting
Browse files Browse the repository at this point in the history
- increase test coverage
  • Loading branch information
cecilia-sanare committed Mar 13, 2024
1 parent 7c6a4b6 commit 841bcbb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ jobs:
uses: swatinem/rust-cache@v2

- name: Run Tests
run: cargo test --locked
run: cargo llvm-cov --locked

- name: Generate Coverage File
run: cargo llvm-cov report --lcov --output-path lcov.info --locked

- name: Coveralls
uses: coverallsapp/github-action@v2

- name: Build
run: cargo build -r --target ${{ matrix.target }} --locked
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/result
*.vdf
lcov.info
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ let
nixpkgs-fmt
rustc
cargo
rustc.llvmPackages.llvm
cargo-llvm-cov
gcc
rustfmt
clippy
Expand Down Expand Up @@ -38,5 +40,7 @@ pkgs.mkShell {
inherit buildInputs;

RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
LLVM_COV = "${pkgs.rustc.llvmPackages.llvm}/bin/llvm-cov";
LLVM_PROFDATA = "${pkgs.rustc.llvmPackages.llvm}/bin/llvm-profdata";
RUST_LOG = "trace";
}
35 changes: 35 additions & 0 deletions src/utils/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,38 @@ pub fn split(command: &str) -> Result<Vec<String>, String> {

Ok(command_args)
}

#[cfg(test)]
mod tests {
use crate::utils::command::{join, split};

fn as_strings(values: Vec<&str>) -> Vec<String> {
values.iter().map(|v| v.to_string()).collect()
}

#[test]
fn join_tests() {
assert_eq!(join(vec!["echo 'hello'"]), Ok("echo 'hello'".to_string()));
assert_eq!(
join(vec!["echo", "\"this\"", "is", "a", "test"]),
Ok("echo '\"this\"' is a test".to_string())
);
assert_eq!(
join(vec!["\0", "\0"]),
Err("Failed to parse command!".to_string())
);
}

#[test]
fn split_tests() {
assert_eq!(split("echo 'hello'"), Ok(as_strings(vec!["echo", "hello"])));
assert_eq!(
split("echo '\"this\"' is a test"),
Ok(as_strings(vec!["echo", "\"this\"", "is", "a", "test"]))
);
assert_eq!(
split("echo 'hello"),
Err("Failed to parse command!".to_string())
);
}
}
24 changes: 20 additions & 4 deletions src/utils/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ pub fn convert_bool(value: bool) -> String {
}

pub fn convert_bool_as(value: bool, false_value: &'static str, true_value: &'static str) -> String {
if value {
false_value.to_string()
} else {
true_value.to_string()
match value {
true => true_value.to_string(),
false => false_value.to_string(),
}
}

#[cfg(test)]
mod tests {
use crate::utils::env::{convert_bool, convert_bool_as};

#[test]
fn convert_bool_should_map_to_0_or_1() {
assert_eq!(convert_bool(false), "0");
assert_eq!(convert_bool(true), "1");
}

#[test]
fn convert_bool_as_should_support_custom_values() {
assert_eq!(convert_bool_as(false, "false", "true"), "false");
assert_eq!(convert_bool_as(true, "false", "true"), "true");
}
}

0 comments on commit 841bcbb

Please sign in to comment.