Browse Source

Playing with Results in tests

master
Julio Biason 4 months ago
parent
commit
da277eaccc
  1. 7
      resultteststest/Cargo.lock
  2. 6
      resultteststest/Cargo.toml
  3. 3
      resultteststest/README.md
  4. 46
      resultteststest/src/lib.rs

7
resultteststest/Cargo.lock generated

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

6
resultteststest/Cargo.toml

@ -0,0 +1,6 @@
[package]
name = "resultteststest"
version = "0.1.0"
edition = "2021"
[dependencies]

3
resultteststest/README.md

@ -0,0 +1,3 @@
# ResultTestsTest
Checking how Cargo deals with Results in tests

46
resultteststest/src/lib.rs

@ -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…
Cancel
Save