Skip to content
Myr

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

2 files+26 added−28 removed

modified:tests/test_ensure.rs+25 added-27 removed
43 unmodified lines
44#[track_caller]45fn assert_err<T: Debug>(result: impl FnOnce() -> Result<T>, expected: &'static str) {46 let actual = result().unwrap_err().to_string();4748 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 }5354 assert_eq!(actual, expected);57}5859#[test]60fn test_recursion() {
38 unmodified lines
99 // 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}106107#[test]
38 unmodified lines
146#[test]147fn 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)");151152 #[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 );158159 #[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 );165166 #[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 );172173 #[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 );179180 #[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}187188#[test]
1 unmodified line
190 #[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 );196197 #[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 );203204 #[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 );210211 #[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 );217218 #[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 );224225 #[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 );231232 #[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}239240#[test]
137 unmodified lines
378379 let test = || Ok(ensure!(stringify! {} != ""));380 assert_err(381 test,384 "Condition failed: `stringify! { } != \"\"` (\"\" vs \"\")",382 "Condition failed: `stringify! {} != \"\"` (\"\" vs \"\")",383 );384}385386#[test]
273 unmodified lines
660661 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 );666667 let test = || Ok(ensure!(if let <S as Trait>::V = 0 { 0 } else { 1 } == 1));668 assert_err(
3 unmodified lines
672673 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 );678679 let test = || Ok(ensure!(if let stringify!(x) = "x" { 0 } else { 1 } == 1));680 assert_err(
4 unmodified lines
modified:Cargo.toml+1 added-1 removed