From fb81380955efd3ad27280e427ffb6b657e65eee9 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 17 Sep 2020 01:48:27 +0200 Subject: [PATCH] fix tests run with `cargo test --target=x86_64-unknown-linux-gnu` --- src/command_parser.rs | 9 ++++----- src/main.rs | 9 +++++---- src/pid.rs | 3 +-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/command_parser.rs b/src/command_parser.rs index 17a4077..dbb6ab4 100644 --- a/src/command_parser.rs +++ b/src/command_parser.rs @@ -461,7 +461,7 @@ mod test { assert_eq!(command, Ok(Command::Pwm { channel: 1, pin: PwmPin::ISet, - value: 16383, + value: 16383.0, })); } @@ -470,7 +470,6 @@ mod test { let command = Command::parse(b"pwm 0 pid"); assert_eq!(command, Ok(Command::PwmPid { channel: 0, - pin: PwmPin::ISet, })); } @@ -480,7 +479,7 @@ mod test { assert_eq!(command, Ok(Command::Pwm { channel: 0, pin: PwmPin::MaxIPos, - value: 7, + value: 7.0, })); } @@ -490,7 +489,7 @@ mod test { assert_eq!(command, Ok(Command::Pwm { channel: 0, pin: PwmPin::MaxINeg, - value: 128, + value: 128.0, })); } @@ -500,7 +499,7 @@ mod test { assert_eq!(command, Ok(Command::Pwm { channel: 0, pin: PwmPin::MaxV, - value: 32768, + value: 32768.0, })); } diff --git a/src/main.rs b/src/main.rs index 0e915d9..e97136e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,11 @@ -#![no_std] -#![no_main] +#![cfg_attr(not(test), no_std)] +#![cfg_attr(not(test), no_main)] #![feature(maybe_uninit_extra, maybe_uninit_ref)] // TODO: #![deny(warnings, unused)] -#[cfg(not(feature = "semihosting"))] +#[cfg(not(any(feature = "semihosting", test)))] use panic_abort as _; -#[cfg(feature = "semihosting")] +#[cfg(any(feature = "semihosting", not(test)))] use panic_semihosting as _; use log::{info, warn}; @@ -80,6 +80,7 @@ const TCP_PORT: u16 = 23; /// Initialization and main loop +#[cfg(not(test))] #[entry] fn main() -> ! { init_log(); diff --git a/src/pid.rs b/src/pid.rs index dbf70fa..b17dfff 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -103,7 +103,7 @@ mod test { const DELAY: usize = 10; let mut pid = Controller::new(PARAMETERS.clone()); - pid.set_target(TARGET); + pid.target = TARGET; let mut values = [DEFAULT; DELAY]; let mut t = 0; @@ -118,6 +118,5 @@ mod test { t = next_t; total_t += 1; } - dbg!(values[t], total_t); } }