You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/cargo-platform/tests/test_cfg.rs
+62-37Lines changed: 62 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,11 @@
1
-
use cargo_platform::{Cfg,CfgExpr,Ident,Platform};
2
1
use std::fmt;
3
2
use std::str::FromStr;
4
3
4
+
use cargo_platform::{Cfg,CfgExpr,Ident,Platform};
5
+
use snapbox::assert_data_eq;
6
+
use snapbox::prelude::*;
7
+
use snapbox::str;
8
+
5
9
macro_rules! c {
6
10
($a:ident) => {
7
11
Cfg::Name(Ident{
@@ -57,23 +61,18 @@ where
57
61
assert_eq!(c, expected);
58
62
}
59
63
60
-
fnbad<T>(s:&str,err:&str)
64
+
#[track_caller]
65
+
fnbad<T>(input:&str,expected:implIntoData)
61
66
where
62
67
T:FromStr + fmt::Display,
63
68
T::Err: fmt::Display,
64
69
{
65
-
let e = matchT::from_str(s){
66
-
Ok(cfg) => panic!("expected `{}` to not parse but got {}", s, cfg),
70
+
dbg!(input);
71
+
let actual = matchT::from_str(input){
72
+
Ok(cfg) => panic!("expected `{input}` to not parse but got {cfg}"),
67
73
Err(e) => e.to_string(),
68
74
};
69
-
assert!(
70
-
e.contains(err),
71
-
"when parsing `{}`,\n\"{}\" not contained \
72
-
inside: {}",
73
-
s,
74
-
err,
75
-
e
76
-
);
75
+
assert_data_eq!(actual, expected.raw());
77
76
}
78
77
79
78
#[test]
@@ -93,24 +92,38 @@ fn cfg_syntax() {
93
92
94
93
#[test]
95
94
fncfg_syntax_bad(){
96
-
bad::<Cfg>("","but cfg expression ended");
97
-
bad::<Cfg>(" ","but cfg expression ended");
98
-
bad::<Cfg>("\t","unexpected character");
99
-
bad::<Cfg>("7","unexpected character");
100
-
bad::<Cfg>("=","expected identifier");
101
-
bad::<Cfg>(",","expected identifier");
102
-
bad::<Cfg>("(","expected identifier");
103
-
bad::<Cfg>("foo (","unexpected content `(` found after cfg expression");
104
-
bad::<Cfg>("bar =","expected a string");
105
-
bad::<Cfg>("bar = \"","unterminated string");
106
95
bad::<Cfg>(
107
-
"foo, bar",
108
-
"unexpected content `, bar` found after cfg expression",
96
+
"",
97
+
str![
98
+
"failed to parse `` as a cfg expression: expected identifier, but cfg expression ended"
99
+
],
100
+
);
101
+
bad::<Cfg>(" ", str!["failed to parse ` ` as a cfg expression: expected identifier, but cfg expression ended"]);
102
+
bad::<Cfg>("\t", str!["failed to parse ` ` as a cfg expression: unexpected character ` ` in cfg, expected parens, a comma, an identifier, or a string"]);
103
+
bad::<Cfg>("7", str!["failed to parse `7` as a cfg expression: unexpected character `7` in cfg, expected parens, a comma, an identifier, or a string"]);
104
+
bad::<Cfg>(
105
+
"=",
106
+
str!["failed to parse `=` as a cfg expression: expected identifier, found `=`"],
107
+
);
108
+
bad::<Cfg>(
109
+
",",
110
+
str!["failed to parse `,` as a cfg expression: expected identifier, found `,`"],
111
+
);
112
+
bad::<Cfg>(
113
+
"(",
114
+
str!["failed to parse `(` as a cfg expression: expected identifier, found `(`"],
bad::<Cfg>("foo (", str!["failed to parse `foo (` as a cfg expression: unexpected content `(` found after cfg expression"]);
117
+
bad::<Cfg>("bar =", str!["failed to parse `bar =` as a cfg expression: expected a string, but cfg expression ended"]);
118
+
bad::<Cfg>(
119
+
"bar = \"",
120
+
str![[r#"failed to parse `bar = "` as a cfg expression: unterminated string in cfg"#]],
121
+
);
122
+
bad::<Cfg>("foo, bar", str!["failed to parse `foo, bar` as a cfg expression: unexpected content `, bar` found after cfg expression"]);
123
+
bad::<Cfg>("r# foo", str!["failed to parse `r# foo` as a cfg expression: unexpected character ` ` in cfg, expected parens, a comma, an identifier, or a string"]);
124
+
bad::<Cfg>("r #foo", str!["failed to parse `r #foo` as a cfg expression: unexpected content `#foo` found after cfg expression"]);
125
+
bad::<Cfg>("r#\"foo\"", str![[r#"failed to parse `r#"foo"` as a cfg expression: unexpected character `"` in cfg, expected parens, a comma, an identifier, or a string"#]]);
126
+
bad::<Cfg>("foo = r#\"\"", str![[r#"failed to parse `foo = r#""` as a cfg expression: unexpected character `"` in cfg, expected parens, a comma, an identifier, or a string"#]]);
0 commit comments