From b0bd5540aab282f779d42b75e38ff6876e9a0ac5 Mon Sep 17 00:00:00 2001 From: Robin Arnold <1297660+RRArny@users.noreply.github.com> Date: Sat, 2 Nov 2024 10:20:56 +0100 Subject: [PATCH] Added unit tests, improved position unit test and added contributing info to README. --- README.md | 8 ++++++++ bacon.toml | 3 ++- src/metar/clouds.rs | 7 +++++++ src/position.rs | 13 +------------ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a1323a8..b59ed3e 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,11 @@ For wxfetch to work you will need a free account on https://avwx.rest/. Once you Wxfetch is written in Rust. In order to build it, run `cargo build` for a debug build, for a production build run `cargo build --release`. This will generate a binary file within the `target` directory in the `debug` and `release` subdirectories respectively. For working on Wxfetch this repository includes a bacon configuration. Run `bacon` to have a variety of jobs at your disposal. `bacon clippy` (or using the 'c' key) will run the clippy linter at a pedantic level. `bacon test` (or 't') will run the unit tests. `bacon tarpaulin` (or 'alt-t') will calculate the code coverage using the `tarpaulin` plugin. You can install bacon using `cargo install bacon`. + +# Contributing + +This project is open source. If you would like to contribute, just fork the project, make your changes and create a pull request with a short description. I will only accept pull requests that satisfy the following criteria: +- all unit tests are passing, +- code coverage is above 50%, +- all pedantic clippy hints that still occur are explained with a comment (if they are impossible or impractical to fix, I will also be pedantic with this!), +- I deem the contribution worthwhile. diff --git a/bacon.toml b/bacon.toml index 21a3578..42f02c1 100644 --- a/bacon.toml +++ b/bacon.toml @@ -25,7 +25,8 @@ command = [ need_stdout = false [jobs.tarpaulin] -command = ["cargo", "tarpaulin", "--color", "always"] +command = ["cargo", "tarpaulin", "--color", "always", +"--", "--color", "always"] need_stdout = true [jobs.clippy-all] diff --git a/src/metar/clouds.rs b/src/metar/clouds.rs index 2c3449c..e3fedf4 100644 --- a/src/metar/clouds.rs +++ b/src/metar/clouds.rs @@ -107,6 +107,7 @@ impl Display for Clouds { mod tests { use std::str::FromStr; + use anyhow::{Error, Result}; use serde_json::Value; use crate::metar::WxField; @@ -134,6 +135,12 @@ mod tests { assert_eq!(Some(expected), actual); } + #[test] + fn test_clouds_from_str_err() { + let actual = clouds_from_str("OCC33"); + assert!(actual.is_none()); + } + #[test] fn test_get_clouds() { let json: Value = Value::from_str( diff --git a/src/position.rs b/src/position.rs index 1e6e27c..0a28979 100644 --- a/src/position.rs +++ b/src/position.rs @@ -66,17 +66,6 @@ mod test { let latlon = LatLong(51.4, 8.5); let expected = "51.4,8.5"; let actual = latlon.to_string(); - // let actual = format!("{latlon}"); - assert!(expected == actual); + assert_eq!(expected, actual); } - - // #[test] - // async fn test_locstr_icao() { - // let icao = Position::Airfield("EDDF".to_string()); - // let expected = "EDDF"; - // let actual = icao.get_location_str().await; - // assert!(expected == actual); - // } - // #[test] - // fn test_locstr_latlon() {} }