Merge pull request #208 from dtolnay/ensuretest
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Update ensure tests to nightly-2021-12-06 and run on nightly only
authored by David Tolnay · committed by GitHub · parents 871be23, 58380ac · Browse files · 2 files·+26 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+26 added−28 removed
- tests:+25 added−27 removed
- other:+1 added−1 removed
Provenance
- Commit
f4956a1- Tree
48d49af- Author
David Tolnay <dtolnay@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
871be23- Parent 2
58380ac
2 files changed+26 added−28 removed
modified:tests/test_ensure.rs+25 added-27 removed
43 unmodified lines44 #[track_caller]45 fn assert_err<T: Debug>(result: impl FnOnce() -> Result<T>, expected: &'static str) {46 let actual = result().unwrap_err().to_string();47 48- let mut accepted_alternatives = expected.split('\n');49- let expected = accepted_alternatives.next_back().unwrap();50- if accepted_alternatives.any(|alternative| actual == alternative) {51- return;48+ // In general different rustc versions will format the interpolated lhs and49+ // rhs $:expr fragment with insignificant differences in whitespace or50+ // punctuation, so we check the message in full against nightly and do just51+ // a cursory test on older toolchains.52+ if rustversion::cfg!(nightly) && !cfg!(miri) {53+ assert_eq!(actual, expected);54+ } else {55+ assert_eq!(actual.contains(" vs "), expected.contains(" vs "));56 }53-54- assert_eq!(actual, expected);57 }58 59 #[test]60 fn test_recursion() {38 unmodified lines99 // But outside the root level, it is fine.100 let test = || Ok(ensure!(while false == true && false {} < ()));101 assert_err(102 test,101- "Condition failed: `while false == true && false { } < ()` (() vs ())",103+ "Condition failed: `while false == true && false {} < ()` (() vs ())",104 );105 }106 107 #[test]38 unmodified lines146 #[test]147 fn test_if() {148 #[rustfmt::skip]149 let test = || Ok(ensure!(if false {}.t(1) == 2));148- assert_err(test, "Condition failed: `if false { }.t(1) == 2` (1 vs 2)");150+ assert_err(test, "Condition failed: `if false {}.t(1) == 2` (1 vs 2)");151 152 #[rustfmt::skip]153 let test = || Ok(ensure!(if false {} else {}.t(1) == 2));154 assert_err(155 test,154- "Condition failed: `if false { } else { }.t(1) == 2` (1 vs 2)",156+ "Condition failed: `if false {} else {}.t(1) == 2` (1 vs 2)",157 );158 159 #[rustfmt::skip]160 let test = || Ok(ensure!(if false {} else if false {}.t(1) == 2));161 assert_err(162 test,161- "Condition failed: `if false { } else if false { }.t(1) == 2` (1 vs 2)",163+ "Condition failed: `if false {} else if false {}.t(1) == 2` (1 vs 2)",164 );165 166 #[rustfmt::skip]167 let test = || Ok(ensure!(if let 1 = 2 {}.t(1) == 2));168 assert_err(169 test,168- "Condition failed: `if let 1 = 2 { }.t(1) == 2` (1 vs 2)",170+ "Condition failed: `if let 1 = 2 {}.t(1) == 2` (1 vs 2)",171 );172 173 #[rustfmt::skip]174 let test = || Ok(ensure!(if let 1 | 2 = 2 {}.t(1) == 2));175 assert_err(176 test,175- "Condition failed: `if let 1 | 2 = 2 { }.t(1) == 2` (1 vs 2)",177+ "Condition failed: `if let 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)",178 );179 180 #[rustfmt::skip]181 let test = || Ok(ensure!(if let | 1 | 2 = 2 {}.t(1) == 2));182 assert_err(183 test,182- "Condition failed: `if let 1 | 2 = 2 { }.t(1) == 2` (1 vs 2)",184+ "Condition failed: `if let 1 | 2 = 2 {}.t(1) == 2` (1 vs 2)",185 );186 }187 188 #[test]1 unmodified line190 #[rustfmt::skip]191 let test = || Ok(ensure!(1 + loop { break 1 } == 1));192 assert_err(193 test,192- // 1.54 puts a double space after loop193- "Condition failed: `1 + loop { break 1 } == 1` (2 vs 1)\n\194- Condition failed: `1 + loop { break 1 } == 1` (2 vs 1)",194+ "Condition failed: `1 + loop { break 1 } == 1` (2 vs 1)",195 );196 197 #[rustfmt::skip]198 let test = || Ok(ensure!(1 + 'a: loop { break 'a 1 } == 1));199 assert_err(200 test,201- // 1.54 puts a double space after loop202- "Condition failed: `1 + 'a: loop { break 'a 1 } == 1` (2 vs 1)\n\203- Condition failed: `1 + 'a: loop { break 'a 1 } == 1` (2 vs 1)",201+ "Condition failed: `1 + 'a: loop { break 'a 1 } == 1` (2 vs 1)",202 );203 204 #[rustfmt::skip]205 let test = || Ok(ensure!(while false {}.t(1) == 2));206 assert_err(207 test,210- "Condition failed: `while false { }.t(1) == 2` (1 vs 2)",208+ "Condition failed: `while false {}.t(1) == 2` (1 vs 2)",209 );210 211 #[rustfmt::skip]212 let test = || Ok(ensure!(while let None = Some(1) {}.t(1) == 2));213 assert_err(214 test,217- "Condition failed: `while let None = Some(1) { }.t(1) == 2` (1 vs 2)",215+ "Condition failed: `while let None = Some(1) {}.t(1) == 2` (1 vs 2)",216 );217 218 #[rustfmt::skip]219 let test = || Ok(ensure!(for _x in iter::once(0) {}.t(1) == 2));220 assert_err(221 test,224- "Condition failed: `for _x in iter::once(0) { }.t(1) == 2` (1 vs 2)",222+ "Condition failed: `for _x in iter::once(0) {}.t(1) == 2` (1 vs 2)",223 );224 225 #[rustfmt::skip]226 let test = || Ok(ensure!(for | _x in iter::once(0) {}.t(1) == 2));227 assert_err(228 test,231- "Condition failed: `for _x in iter::once(0) { }.t(1) == 2` (1 vs 2)",229+ "Condition failed: `for _x in iter::once(0) {}.t(1) == 2` (1 vs 2)",230 );231 232 #[rustfmt::skip]233 let test = || Ok(ensure!(for true | false in iter::empty() {}.t(1) == 2));234 assert_err(235 test,238- "Condition failed: `for true | false in iter::empty() { }.t(1) == 2` (1 vs 2)",236+ "Condition failed: `for true | false in iter::empty() {}.t(1) == 2` (1 vs 2)",237 );238 }239 240 #[test]137 unmodified lines378 379 let test = || Ok(ensure!(stringify! {} != ""));380 assert_err(381 test,384- "Condition failed: `stringify! { } != \"\"` (\"\" vs \"\")",382+ "Condition failed: `stringify! {} != \"\"` (\"\" vs \"\")",383 );384 }385 386 #[test]273 unmodified lines660 661 let test = || Ok(ensure!(if let ::std::marker::PhantomData = p {} != ()));662 assert_err(663 test,666- "Condition failed: `if let ::std::marker::PhantomData = p { } != ()` (() vs ())",664+ "Condition failed: `if let ::std::marker::PhantomData = p {} != ()` (() vs ())",665 );666 667 let test = || Ok(ensure!(if let <S as Trait>::V = 0 { 0 } else { 1 } == 1));668 assert_err(3 unmodified lines672 673 let test = || Ok(ensure!(for _ in iter::once(()) {} != ()));674 assert_err(675 test,678- "Condition failed: `for _ in iter::once(()) { } != ()` (() vs ())",676+ "Condition failed: `for _ in iter::once(()) {} != ()` (() vs ())",677 );678 679 let test = || Ok(ensure!(if let stringify!(x) = "x" { 0 } else { 1 } == 1));680 assert_err(4 unmodified linesmodified:Cargo.toml+1 added-1 removed
18 unmodified lines192021222323242526273 unmodified lines18 unmodified linesbacktrace = { version = "0.3.51", optional = true }
[dev-dependencies]futures = { version = "0.3", default-features = false }rustversion = "1.0"rustversion = "1.0.6"syn = { version = "1.0", features = ["full"] }thiserror = "1.0"trybuild = { version = "1.0.49", features = ["diff"] }
3 unmodified lines