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

Add tests #4

Merged
merged 14 commits into from
Nov 13, 2024
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
21 changes: 18 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,29 @@ jobs:
- name: Check
run: cargo check --all

- name: Format
run: cargo fmt --all --check

- name: Build
run: cargo build --all --verbose

- name: Format
run: cargo fmt --all --check
- name: Docs
run: cargo doc --all --verbose

- name: Lint
run: cargo clippy --all -- -D warnings

- name: Tests
run: cargo test --all --verbose
run: |
# Full tests for Linux only, due to requirement of running local API hosted through docker
if [ "$RUNNER_OS" == "Linux" ]; then
docker compose up -d --wait
# Wait for Frankfurter container to fetch data
sleep 60
cargo test --all --verbose
docker compose down
else
cargo test --package lib_frankfurter --lib
cargo test --package frankfurter_cli --bin frs
fi
shell: bash
30 changes: 30 additions & 0 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
branches: ["main"]

name: MSRV check

jobs:
msrv_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install stable toolchain
run: rustup toolchain install stable

- name: Install Cargo MSRV
uses: actions-rs/[email protected]
with:
crate: cargo-msrv
version: latest
use-tool-cache: true

- name: Verify minimum Rust version for the library and CLI
run: |
cargo msrv verify --path ./lib
cargo msrv verify --path ./cli
162 changes: 162 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ termcolor = { version = "1.4.1" }
is-terminal = { version = "0.4.13" }
comfy-table = "7.1.1"
anyhow = "1.0.91"

[dev-dependencies]
assert_cmd = "2.0.16"
predicates = "3.1.2"
3 changes: 2 additions & 1 deletion cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env::var, io::Write};
use std::{env::var, io::Write, process::exit};

use clap::{Parser, Subcommand};
use enum_dispatch::enum_dispatch;
Expand Down Expand Up @@ -110,6 +110,7 @@ impl Cli {
}

writeln!(&mut stderr, "Error: {e}").expect("Failed to write to stderr");
exit(1);
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions cli/src/cli/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,41 @@ pub fn if_supports_colour(
comfy_table::Color::Reset
}
}

#[cfg(test)]
mod tests {
use comfy_table::Color;
use termcolor::{ColorChoice, StandardStream};

use super::*;

#[test]
fn test_if_supports_colour() {
let get_stream = StandardStream::stdout;

assert_eq!(
comfy_table::Color::Reset,
if_supports_colour(&get_stream(ColorChoice::Never), Color::Red)
);
assert_eq!(
comfy_table::Color::Reset,
if_supports_colour(&get_stream(ColorChoice::Never), Color::Cyan)
);

assert_eq!(
comfy_table::Color::Green,
if_supports_colour(&get_stream(ColorChoice::Always), Color::Green)
);
assert_eq!(
comfy_table::Color::Black,
if_supports_colour(&get_stream(ColorChoice::AlwaysAnsi), Color::Black)
);

assert_eq!(
comfy_table::Color::Reset,
if_supports_colour(&get_stream(ColorChoice::Always), Color::Reset)
);

// NOTE: No test for `ColorChoice::Auto` - not sure how that would react in a CI environment
}
}
Loading
Loading