Conditional Returns in test build

No my question isn’t like Conditional compilation for debug/release

what i want is completely different

i want a function to do something completely different when i run cargo test

fn returns_3 () {
   test! {
     // should return this in test enviroments
    // and exit the function early.
     return 5 
  };

 return 3
}
fn returns_3() -> usize {
    if cfg!(test) {
        return 5;
    }

    return 3
}

Using the compile-time cfg! macro

3 Likes

thanks for this