Skip to content
Myr

test_macros.rs

This file

Path

tests/test_macros.rs

97 lines · 2.2 KiB · Rust

Last changed by

Merge pull request #436 from dtolnay/upDavid Tolnaybefore adoption67df012

History of this file

Take it

The walk stopped after 200 commits: lines older than 553ed38 point at it.

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 1–3why, one step back
1#![allow(
2 clippy::assertions_on_result_states,3 clippy::eq_op,

Ignore incompatible_msrv clippy false positives in testDavid Tolnaybefore adoptionf885a13

line 4why, one step back
4 clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

line 5why, one step back
5 clippy::items_after_statements,

Merge pull request #365 from dtolnay/ensuretypeDavid Tolnaybefore adoption52a46eb

line 6why, one step back
6 clippy::match_single_binding,

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 7–8why, one step back
7 clippy::needless_pass_by_value,
8 clippy::shadow_unrelated,

Merge pull request #436 from dtolnay/upDavid Tolnaybefore adoption67df012

line 9why, one step back
9 clippy::uninlined_format_args,

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 10–15why, one step back
10 clippy::wildcard_imports
11)]1213mod common;1415use self::common::*;

Merge pull request #365 from dtolnay/ensuretypeDavid Tolnaybefore adoption52a46eb

line 16why, one step back
16use anyhow::{anyhow, ensure, Result};

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 17–55why, one step back
17use std::cell::Cell;
18use std::future;1920#[test]21fn test_messages() {22 assert_eq!("oh no!", bail_literal().unwrap_err().to_string());23 assert_eq!("oh no!", bail_fmt().unwrap_err().to_string());24 assert_eq!("oh no!", bail_error().unwrap_err().to_string());25}2627#[test]28fn test_ensure() {29 let f = || {30 ensure!(1 + 1 == 2, "This is correct");31 Ok(())32 };33 assert!(f().is_ok());3435 let v = 1;36 let f = || {37 ensure!(v + v == 2, "This is correct, v: {}", v);38 Ok(())39 };40 assert!(f().is_ok());4142 let f = || {43 ensure!(v + v == 1, "This is not correct, v: {}", v);44 Ok(())45 };46 assert!(f().is_err());4748 let f = || {49 ensure!(v + v == 1);50 Ok(())51 };52 assert_eq!(53 f().unwrap_err().to_string(),54 "Condition failed: `v + v == 1` (2 vs 1)",55 );

Merge pull request #365 from dtolnay/ensuretypeDavid Tolnaybefore adoption52a46eb

lines 56–58why, one step back
56}
5758#[test]

Simplify nonbool ensure testDavid Tolnaybefore adoption2b42f62

line 59why, one step back
59fn test_ensure_nonbool() -> Result<()> {

Merge pull request #365 from dtolnay/ensuretypeDavid Tolnaybefore adoption52a46eb

lines 60–63why, one step back
60 struct Struct {
61 condition: bool,62 }63

Simplify nonbool ensure testDavid Tolnaybefore adoption2b42f62

lines 64–66why, one step back
64 let s = Struct { condition: true };
65 match &s {66 Struct { condition } => ensure!(condition), // &bool

Merge pull request #365 from dtolnay/ensuretypeDavid Tolnaybefore adoption52a46eb

lines 67–68why, one step back
67 }
68

Simplify nonbool ensure testDavid Tolnaybefore adoption2b42f62

line 69why, one step back
69 Ok(())

Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38

lines 70–97why, one step back
70}
7172#[test]73fn test_temporaries() {74 fn require_send_sync(_: impl Send + Sync) {}7576 require_send_sync(async {77 // If anyhow hasn't dropped any temporary format_args it creates by the78 // time it's done evaluating, those will stick around until the79 // semicolon, which is on the other side of the await point, making the80 // enclosing future non-Send.81 future::ready(anyhow!("...")).await;82 });8384 fn message(cell: Cell<&str>) -> &str {85 cell.get()86 }8788 require_send_sync(async {89 future::ready(anyhow!(message(Cell::new("...")))).await;90 });91}9293#[test]94fn test_brace_escape() {95 let err = anyhow!("unterminated ${{..}} expression");96 assert_eq!("unterminated ${..} expression", err.to_string());97}