Skip to content

Commit

Permalink
Run CI tests on linux, macos, and windows. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleury authored Sep 2, 2024
1 parent a75fe8d commit 3594142
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ env:
CARGO_TERM_COLOR: always

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo install cargo-tarpaulin cargo-mutants
- run: cargo tarpaulin --all-features --engine llvm
- run: cargo mutants

lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -28,19 +38,12 @@ jobs:
- run: cargo clippy --all-targets --all-features -- -D clippy::pedantic -D warnings

test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --all-features

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo install cargo-tarpaulin cargo-mutants
- run: cargo tarpaulin --all-features --engine llvm
- run: cargo mutants
16 changes: 1 addition & 15 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Iterator for FileIter {

#[cfg(test)]
mod test {
use super::{from_path, File};
use super::File;

#[test]
fn file_can_be_formatted_as_a_string() {
Expand Down Expand Up @@ -116,18 +116,4 @@ mod test {

assert_eq!(want, files);
}

#[test]
fn from_path_returns_iterator_over_files_in_the_given_path() {
let want = vec![
File::new("./testdata/en/hello.txt", 6),
File::new("./testdata/en/world.txt", 7),
File::new("./testdata/es/hola.txt", 5),
File::new("./testdata/es/mundo.txt", 6),
];
let mut got = from_path("./testdata").unwrap().collect::<Vec<_>>();
// Sort by path for consistent ordering.
got.sort_by_key(|f| f.path.clone());
assert_eq!(want, got);
}
}
15 changes: 14 additions & 1 deletion tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ fn binary_with_no_args_prints_top_5_largest_files_under_working_directory() {

#[test]
fn binary_with_path_arg_prints_the_top_5_largest_files_under_the_given_path() {
#[cfg(windows)]
let want = [
"*** Top 5 largest files ***",
"8 B ./testdata\\en\\world.txt",
"7 B ./testdata\\es\\mundo.txt",
"7 B ./testdata\\en\\hello.txt",
"6 B ./testdata\\es\\hola.txt",
];
#[cfg(not(windows))]
let want = [
"*** Top 5 largest files ***",
"7 B ./testdata/en/world.txt",
Expand Down Expand Up @@ -68,10 +77,14 @@ fn binary_with_the_number_arg_prints_the_top_n_largest_files_under_the_current_w

#[test]
fn binary_with_invalid_path_arg_prints_an_error_message_and_exits_with_failure_code() {
#[cfg(windows)]
let want = "The system cannot find the path specified";
#[cfg(not(windows))]
let want = "No such file or directory";
Command::cargo_bin("spacehog")
.unwrap()
.arg("nonexistent")
.assert()
.failure()
.stderr(predicates::str::contains("No such file or directory"));
.stderr(predicates::str::contains(want));
}

0 comments on commit 3594142

Please sign in to comment.