diff --git a/Cargo.toml b/Cargo.toml index 8df0fc5..09b343a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,6 @@ anyhow = "1.0" clap = { version = "3.1", features = ["derive"]} crossterm = "0.23" rand = "0.8" + +[dev-dependencies] mockall = "0.11" \ No newline at end of file diff --git a/src/animation/mod.rs b/src/animation/mod.rs index f8aedba..96d570f 100644 --- a/src/animation/mod.rs +++ b/src/animation/mod.rs @@ -4,9 +4,10 @@ pub mod rhombus; use crate::vec::Vector; +#[cfg(test)] use mockall::automock; -#[automock] +#[cfg_attr(test, automock)] pub trait Animation { fn sample(&self, step: f32, pos: Vector) -> f32; } \ No newline at end of file diff --git a/src/char.rs b/src/char.rs index aa35c21..3cb54b4 100644 --- a/src/char.rs +++ b/src/char.rs @@ -1,7 +1,8 @@ +#[cfg(test)] use mockall::automock; /// Used to get a character with a given brightness. -#[automock] +#[cfg_attr(test, automock)] pub trait CharSampler { /// Gets a character with the given brightness. /// # Arguments diff --git a/src/color.rs b/src/color.rs index 5fa4b19..3c15fbf 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,8 +1,10 @@ use crossterm::style::Color; + +#[cfg(test)] use mockall::automock; /// A collection of colors. -#[automock] +#[cfg_attr(test, automock)] pub trait ColorSampler { /// Gets a color for the given fill. /// # Arguments diff --git a/src/fill/mod.rs b/src/fill/mod.rs index d4f73b6..dc8b7bd 100644 --- a/src/fill/mod.rs +++ b/src/fill/mod.rs @@ -4,10 +4,11 @@ pub mod stripes; use crate::vec::Vector; +#[cfg(test)] use mockall::automock; /// Used to choose the colors of characters. -#[automock] +#[cfg_attr(test, automock)] pub trait FillMode { /// Gets the color for this character. fn sample(&self, level: f32, pos: Vector) -> f32; diff --git a/src/render.rs b/src/render.rs index 944d8d5..bc05224 100644 --- a/src/render.rs +++ b/src/render.rs @@ -3,9 +3,10 @@ use crate::sampler::{Sample, Sampler}; use crate::surface::Surface; use crate::Vector; +#[cfg(test)] use mockall::automock; -#[automock] +#[cfg_attr(test, automock)] pub trait Renderer { fn render(&mut self, step: f32); fn present(&mut self) -> Result<(), Error>; diff --git a/src/sampler.rs b/src/sampler.rs index 806065d..20efaac 100644 --- a/src/sampler.rs +++ b/src/sampler.rs @@ -1,18 +1,20 @@ use crossterm::style::Color; -use mockall::automock; use crate::animation::Animation; use crate::char::CharSampler; use crate::color::ColorSampler; use crate::fill::FillMode; use crate::vec::Vector; +#[cfg(test)] +use mockall::automock; + pub enum Sample { Keep, Draw { char: char, color: Color }, Clear, } -#[automock] +#[cfg_attr(test, automock)] pub trait Sampler { fn sample(&self, step: f32, pos: Vector) -> Sample; } diff --git a/src/surface.rs b/src/surface.rs index 0f99459..aa719ba 100644 --- a/src/surface.rs +++ b/src/surface.rs @@ -3,11 +3,13 @@ use crossterm::cursor::MoveTo; use crossterm::{ExecutableCommand, QueueableCommand}; use crossterm::style::{Color, Print, SetForegroundColor}; use crossterm::terminal::{Clear, ClearType}; -use mockall::automock; use std::io::Write; use crate::array::Array2D; -#[automock] +#[cfg(test)] +use mockall::automock; + +#[cfg_attr(test, automock)] pub trait Surface { fn width(&self) -> usize; fn height(&self) -> usize; diff --git a/src/timer.rs b/src/timer.rs index 2c39454..fba3903 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,8 +1,10 @@ use std::thread::sleep; use std::time::{Duration, Instant}; + +#[cfg(test)] use mockall::automock; -#[automock] +#[cfg_attr(test, automock)] pub trait Timer { fn sleep(&mut self);