diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba0e91e..710b2b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,33 +20,17 @@ jobs: run_tests: name: Run Rust tests runs-on: ubuntu-latest - env: - NATIVE_TARGET: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }} strategy: fail-fast: false - matrix: - target: [x86_64-unknown-linux-gnu, armv7-unknown-linux-gnueabihf, arm-unknown-linux-gnueabihf] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - - name: Install cross - run: cargo install cross --git https://github.com/cross-rs/cross - if: env.NATIVE_TARGET == 'false' - - uses: Swatinem/rust-cache@v2 - - name: Set test runner - run: | - if ${NATIVE_TARGET} == true; then - echo "test_runner=cargo" >> $GITHUB_ENV - else - echo "test_runner=cross" >> $GITHUB_ENV - fi - - name: Run tests - run: ${{ env.test_runner }} test --no-fail-fast --verbose --target ${{ matrix.target }} -- --nocapture + run: cargo test --no-fail-fast --verbose --target x86_64-unknown-linux-gnu -- --nocapture lint: name: Check Rust code with rustfmt and clippy diff --git a/Cargo.lock b/Cargo.lock index bec7d46..000cf04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -40,7 +40,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -68,12 +68,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "bytes" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" - [[package]] name = "cc" version = "1.0.73" @@ -297,6 +291,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "indexmap" version = "1.9.1" @@ -398,11 +398,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", ] @@ -662,16 +662,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" -[[package]] -name = "socket2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "strsim" version = "0.10.0" @@ -748,16 +738,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ "autocfg", - "bytes", "libc", - "memchr", "mio", "num_cpus", "once_cell", - "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", "tokio-macros", "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 26e1728..0d39b7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,6 @@ license = "Apache-2.0 OR MIT" edition = "2021" exclude = ["assets/"] -[badges] -maintenance = { status = "actively-developed" } - [features] integration-test = [] @@ -26,7 +23,7 @@ dirs = "4" serde = { version = "1", features = ["derive"] } serde_json = "1" clap = { version = "3", features = ["derive"] } -tokio = { version = "1", features = ["full"] } +tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] } tokio-walltime = "0.1.2" toml = "0.5" diff --git a/src/bin/heliocron.rs b/src/bin/heliocron.rs index 2e17f0d..f5cb028 100644 --- a/src/bin/heliocron.rs +++ b/src/bin/heliocron.rs @@ -24,7 +24,7 @@ async fn main() { process::exit(match run_heliocron().await { Ok(_) => 0, Err(err) => { - eprintln!("{}", err); + eprintln!("{err}"); 1 } }); diff --git a/src/cli.rs b/src/cli.rs index 20c482d..2d98281 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -128,7 +128,7 @@ fn parse_date(date: &str) -> Result { fn parse_tz(tz: &str) -> Result { // Use chrono's own parsing function to validate the provided time zone. - let date = chrono::DateTime::parse_from_str(&format!("2022-01-01T00:00:00{}", tz), "%FT%T%:z") + let date = chrono::DateTime::parse_from_str(&format!("2022-01-01T00:00:00{tz}"), "%FT%T%:z") .map_err(|_| { format!( "Invalid time zone - expected the format '[+|-]HH:MM' between '-23:59' and '+23:59'. Found '{tz}'" @@ -170,7 +170,7 @@ pub fn parse_config() -> Result { match res { Ok(coords) => Some(coords), Err(e) => { - eprintln!("Warning - couldn't parse configuration file due to the following reason: {}\n. Proceeding with default coordinates.", e); + eprintln!("Warning - couldn't parse configuration file due to the following reason: {e}\n. Proceeding with default coordinates."); None } } diff --git a/src/domain.rs b/src/domain.rs index d059d5c..2902c40 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -401,7 +401,7 @@ mod tests { let vals = &["-90.0", "-89.9999999999", "-0.0", "0.0", "90.0"]; for val in vals { - assert!(Latitude::parse(*val).is_ok()); + assert!(Latitude::parse(val).is_ok()); } } @@ -410,7 +410,7 @@ mod tests { let vals = &["-180.0", "-90.00000000001", "90.00000001", "100.0"]; for val in vals { - assert!(Latitude::parse(*val).is_err()); + assert!(Latitude::parse(val).is_err()); } } @@ -447,7 +447,7 @@ mod tests { ]; for val in vals { - assert!(Longitude::parse(*val).is_ok()); + assert!(Longitude::parse(val).is_ok()); } } @@ -456,7 +456,7 @@ mod tests { let vals = &["-180.1", "180.01"]; for val in vals { - assert!(Longitude::parse(*val).is_err()); + assert!(Longitude::parse(val).is_err()); } } diff --git a/src/errors.rs b/src/errors.rs index c8a93a0..a09cd11 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -56,7 +56,7 @@ impl std::fmt::Display for HeliocronError { "Config error: {}", match err { ConfigErrorKind::InvalidCoordindates(msg) => - format!("Invalid coordinates - {}", msg), + format!("Invalid coordinates - {msg}"), ConfigErrorKind::InvalidTomlFile => err.as_str().to_string(), ConfigErrorKind::ParseDate => err.as_str().to_string(), ConfigErrorKind::ParseAltitude => err.as_str().to_string(), @@ -73,7 +73,7 @@ impl std::fmt::Display for HeliocronError { RuntimeErrorKind::PastEvent(when) => { format!("The chosen event occurred in the past: {when}. Cannot wait a negative amount of time.") } - RuntimeErrorKind::EventMissed(by) => format!("Event missed by {}s", by), + RuntimeErrorKind::EventMissed(by) => format!("Event missed by {by}s"), RuntimeErrorKind::SleepError(e) => e.to_string(), } ), diff --git a/src/report.rs b/src/report.rs index 4b73208..154a8dc 100644 --- a/src/report.rs +++ b/src/report.rs @@ -33,7 +33,7 @@ pub struct Report { impl fmt::Display for Report { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let fmt_str = self.format_report(); - write!(f, "{}", fmt_str) + write!(f, "{fmt_str}") } } @@ -150,7 +150,7 @@ impl Report { let minutes = (day_length / 60) % 60; let seconds = day_length % 60; - format!("{}h {}m {}s", hours, minutes, seconds) + format!("{hours}h {minutes}m {seconds}s") } } @@ -195,7 +195,7 @@ impl std::fmt::Display for PollReport { self.azimuth_angle, ); - write!(f, "{}", report) + write!(f, "{report}") } } diff --git a/src/subcommands.rs b/src/subcommands.rs index 122e02d..f354329 100644 --- a/src/subcommands.rs +++ b/src/subcommands.rs @@ -15,7 +15,7 @@ pub fn display_report(solar_calculations: calc::SolarCalculations, json: bool) - } else { report.to_string() }; - println!("{}", output); + println!("{output}"); Ok(()) } diff --git a/src/traits.rs b/src/traits.rs index 62a18d7..2330304 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -50,7 +50,7 @@ mod tests { ]; for (expected, arg) in params.iter() { - let date = NaiveDateTime::parse_from_str(*arg, "%FT%T").unwrap(); + let date = NaiveDateTime::parse_from_str(arg, "%FT%T").unwrap(); assert_eq!(*expected, format!("{:.5}", date.to_julian_date())); } } diff --git a/src/utils.rs b/src/utils.rs index 8879171..a1955c0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,7 +9,7 @@ type Result = result::Result; async fn sleep(time: DateTime) -> Result<()> { if cfg!(feature = "integration-test") { - println!("Fake sleep until {}.", time); + println!("Fake sleep until {time}."); } else { tokio_walltime::sleep_until(time).await?; } diff --git a/tests/test_report.rs b/tests/test_report.rs index 14adf36..2ef3c63 100644 --- a/tests/test_report.rs +++ b/tests/test_report.rs @@ -63,13 +63,13 @@ fn test_report_custom_location() { // assert that a report is successfully generated when an arbitrary location is given let mut cmd = get_base_command(); let report_long = cmd - .args(&["--latitude", "51.0", "--longitude", "4.36", "report"]) + .args(["--latitude", "51.0", "--longitude", "4.36", "report"]) .assert(); assert_report(report_long); let mut cmd = get_base_command(); - let report_short = cmd.args(&["-l", "51.0", "-o", "4.36", "report"]).assert(); + let report_short = cmd.args(["-l", "51.0", "-o", "4.36", "report"]).assert(); assert_report(report_short) } @@ -79,7 +79,7 @@ fn test_report_custom_timezone() { // assert that a report is successfully generated when an arbitrary time zone is given let mut cmd = get_base_command(); let report_long = cmd - .args(&[ + .args([ "--latitude", "51.0", "--longitude", @@ -94,7 +94,7 @@ fn test_report_custom_timezone() { let mut cmd = get_base_command(); let report_short = cmd - .args(&[ + .args([ "--latitude", "51.0", "--longitude", @@ -114,7 +114,7 @@ fn test_report_json_output() { // parse the output into a Json Value let json: serde_json::Value = serde_json::from_slice( - &cmd.args(&[ + &cmd.args([ "--date", "2022-06-11", "--time-zone", @@ -151,7 +151,7 @@ fn test_report_json_output() { #[test] fn test_correct_output_small_offset() { let output = get_base_command() - .args(&[ + .args([ "--date", "2022-07-29", "--time-zone", @@ -188,7 +188,7 @@ fn test_correct_output_small_offset() { #[test] fn test_correct_output_large_pos_offset() { let output = get_base_command() - .args(&[ + .args([ "--date", "2022-07-29", "--time-zone", diff --git a/tests/test_wait.rs b/tests/test_wait.rs index da1bc4e..166e171 100644 --- a/tests/test_wait.rs +++ b/tests/test_wait.rs @@ -139,9 +139,9 @@ fn test_altitude_ignored_for_non_custom_events() { cmd.args(&[ "-l", - "51.4769N", + "51.4769", "-o", - "0.0005W", + "0.0005", "--date", "2099-12-30", "wait", @@ -164,9 +164,9 @@ fn test_custom_am_event_correctness() { cmd.args(&[ "-l", - "51.4769N", + "51.4769", "-o", - "0.0005W", + "0.0005", "--date", "2099-12-30", "wait", @@ -179,7 +179,7 @@ fn test_custom_am_event_correctness() { .success() .stdout(predicates::str::contains("going to sleep for")) .stdout(predicates::str::contains("until 2099-12-30")) - .stdout(predicates::str::contains(":07:05")); + .stdout(predicates::str::contains("08:07:")); } #[test] @@ -189,9 +189,9 @@ fn test_custom_pm_event_correctness() { cmd.args(&[ "-l", - "51.4769N", + "51.4769", "-o", - "0.0005W", + "0.0005", "--date", "2099-12-30", "wait", @@ -204,7 +204,7 @@ fn test_custom_pm_event_correctness() { .success() .stdout(predicates::str::contains("going to sleep for")) .stdout(predicates::str::contains("until 2099-12-30")) - .stdout(predicates::str::contains("57:51")); + .stdout(predicates::str::contains("17:57:")); } #[test]