Skip to content
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
18 changes: 1 addition & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 11 additions & 25 deletions Cargo.lock

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

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ license = "Apache-2.0 OR MIT"
edition = "2021"
exclude = ["assets/"]

[badges]
maintenance = { status = "actively-developed" }

[features]
integration-test = []

Expand All @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/bin/heliocron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() {
process::exit(match run_heliocron().await {
Ok(_) => 0,
Err(err) => {
eprintln!("{}", err);
eprintln!("{err}");
1
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn parse_date(date: &str) -> Result<NaiveDate, String> {

fn parse_tz(tz: &str) -> Result<chrono::FixedOffset, String> {
// 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}'"
Expand Down Expand Up @@ -170,7 +170,7 @@ pub fn parse_config() -> Result<Config, HeliocronError> {
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
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down Expand Up @@ -447,7 +447,7 @@ mod tests {
];

for val in vals {
assert!(Longitude::parse(*val).is_ok());
assert!(Longitude::parse(val).is_ok());
}
}

Expand All @@ -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());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
}
),
Expand Down
6 changes: 3 additions & 3 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}

Expand Down Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -195,7 +195,7 @@ impl std::fmt::Display for PollReport {
self.azimuth_angle,
);

write!(f, "{}", report)
write!(f, "{report}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn display_report(solar_calculations: calc::SolarCalculations, json: bool) -
} else {
report.to_string()
};
println!("{}", output);
println!("{output}");
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Result<T> = result::Result<T, HeliocronError>;

async fn sleep(time: DateTime<FixedOffset>) -> Result<()> {
if cfg!(feature = "integration-test") {
println!("Fake sleep until {}.", time);
println!("Fake sleep until {time}.");
} else {
tokio_walltime::sleep_until(time).await?;
}
Expand Down
14 changes: 7 additions & 7 deletions tests/test_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions tests/test_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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]
Expand All @@ -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",
Expand All @@ -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]
Expand Down