Julio Biason
5 months ago
4 changed files with 62 additions and 0 deletions
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
version = 3 |
||||
|
||||
[[package]] |
||||
name = "resultteststest" |
||||
version = "0.1.0" |
@ -0,0 +1,6 @@
|
||||
[package] |
||||
name = "resultteststest" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
[dependencies] |
@ -0,0 +1,3 @@
|
||||
# ResultTestsTest |
||||
|
||||
Checking how Cargo deals with Results in tests |
@ -0,0 +1,46 @@
|
||||
fn not_zero(num: usize) -> Result<(), ()> { |
||||
if num == 0 { |
||||
Err(()) |
||||
} else { |
||||
Ok(()) |
||||
} |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn with_result_ok() -> Result<(), ()> { |
||||
Ok(()) |
||||
} |
||||
|
||||
#[test] |
||||
fn with_result_err() -> Result<(), ()> { |
||||
Err(()) |
||||
} |
||||
|
||||
#[test] |
||||
fn nested() -> Result<(), ()> { |
||||
not_zero(1)?; |
||||
Ok(()) |
||||
} |
||||
|
||||
#[test] |
||||
fn nested2() -> Result<(), ()> { |
||||
not_zero(0)?; |
||||
Ok(()) |
||||
} |
||||
|
||||
#[test] |
||||
fn nested3() -> Result<(), ()> { |
||||
let result = (|| { |
||||
not_zero(2)?; |
||||
Ok(()) |
||||
})(); |
||||
|
||||
// do something else, like cleaning up the testing workspace
|
||||
|
||||
result |
||||
} |
||||
} |
Loading…
Reference in new issue