2
2
3
3
use cargo_test_support:: { basic_bin_manifest, main_file, project} ;
4
4
5
- static MANIFEST_OUTPUT : & str = r#"
6
- {
5
+ fn manifest_output ( readme_value : & str ) -> String {
6
+ format ! (
7
+ r#"
8
+ {{
7
9
"authors": [
8
10
"wycats@example.com"
9
11
],
10
12
"categories": [],
11
13
"name":"foo",
12
- "readme": null ,
14
+ "readme": {} ,
13
15
"repository": null,
14
16
"version":"0.5.0",
15
17
"id":"foo[..]0.5.0[..](path+file://[..]/foo)",
@@ -21,19 +23,44 @@ static MANIFEST_OUTPUT: &str = r#"
21
23
"edition": "2015",
22
24
"source":null,
23
25
"dependencies":[],
24
- "targets":[{
26
+ "targets":[{{
25
27
"kind":["bin"],
26
28
"crate_types":["bin"],
27
29
"doctest": false,
28
30
"edition": "2015",
29
31
"name":"foo",
30
32
"src_path":"[..]/foo/src/foo.rs"
31
- }],
32
- "features":{},
33
+ }} ],
34
+ "features":{{} },
33
35
"manifest_path":"[..]Cargo.toml",
34
36
"metadata": null,
35
37
"publish": null
36
- }"# ;
38
+ }}"# ,
39
+ readme_value
40
+ )
41
+ }
42
+
43
+ fn manifest_output_no_readme ( ) -> String {
44
+ manifest_output ( "null" )
45
+ }
46
+
47
+ pub fn basic_bin_manifest_with_readme ( name : & str , readme_filename : & str ) -> String {
48
+ format ! (
49
+ r#"
50
+ [package]
51
+
52
+ name = "{}"
53
+ version = "0.5.0"
54
+ authors = ["wycats@example.com"]
55
+ readme = {}
56
+
57
+ [[bin]]
58
+
59
+ name = "{}"
60
+ "# ,
61
+ name, readme_filename, name
62
+ )
63
+ }
37
64
38
65
#[ cargo_test]
39
66
fn cargo_read_manifest_path_to_cargo_toml_relative ( ) {
@@ -44,7 +71,7 @@ fn cargo_read_manifest_path_to_cargo_toml_relative() {
44
71
45
72
p. cargo ( "read-manifest --manifest-path foo/Cargo.toml" )
46
73
. cwd ( p. root ( ) . parent ( ) . unwrap ( ) )
47
- . with_json ( MANIFEST_OUTPUT )
74
+ . with_json ( & manifest_output_no_readme ( ) )
48
75
. run ( ) ;
49
76
}
50
77
@@ -58,7 +85,7 @@ fn cargo_read_manifest_path_to_cargo_toml_absolute() {
58
85
p. cargo ( "read-manifest --manifest-path" )
59
86
. arg ( p. root ( ) . join ( "Cargo.toml" ) )
60
87
. cwd ( p. root ( ) . parent ( ) . unwrap ( ) )
61
- . with_json ( MANIFEST_OUTPUT )
88
+ . with_json ( & manifest_output_no_readme ( ) )
62
89
. run ( ) ;
63
90
}
64
91
@@ -104,5 +131,83 @@ fn cargo_read_manifest_cwd() {
104
131
. file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
105
132
. build ( ) ;
106
133
107
- p. cargo ( "read-manifest" ) . with_json ( MANIFEST_OUTPUT ) . run ( ) ;
134
+ p. cargo ( "read-manifest" )
135
+ . with_json ( & manifest_output_no_readme ( ) )
136
+ . run ( ) ;
137
+ }
138
+
139
+ #[ cargo_test]
140
+ fn cargo_read_manifest_with_specified_readme ( ) {
141
+ let p = project ( )
142
+ . file (
143
+ "Cargo.toml" ,
144
+ & basic_bin_manifest_with_readme ( "foo" , r#""SomeReadme.txt""# ) ,
145
+ )
146
+ . file ( "SomeReadme.txt" , "Sample Project" )
147
+ . file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
148
+ . build ( ) ;
149
+
150
+ p. cargo ( "read-manifest" )
151
+ . with_json ( & manifest_output ( & format ! ( r#""{}""# , "SomeReadme.txt" ) ) )
152
+ . run ( ) ;
153
+ }
154
+
155
+ #[ cargo_test]
156
+ fn cargo_read_manifest_default_readme ( ) {
157
+ let readme_filenames = [ "README.md" , "README.txt" , "README" ] ;
158
+
159
+ for readme in readme_filenames. iter ( ) {
160
+ let p = project ( )
161
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
162
+ . file ( readme, "Sample project" )
163
+ . file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
164
+ . build ( ) ;
165
+
166
+ p. cargo ( "read-manifest" )
167
+ . with_json ( & manifest_output ( & format ! ( r#""{}""# , readme) ) )
168
+ . run ( ) ;
169
+ }
170
+ }
171
+
172
+ #[ cargo_test]
173
+ fn cargo_read_manifest_suppress_default_readme ( ) {
174
+ let p = project ( )
175
+ . file (
176
+ "Cargo.toml" ,
177
+ & basic_bin_manifest_with_readme ( "foo" , "false" ) ,
178
+ )
179
+ . file ( "README.txt" , "Sample project" )
180
+ . file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
181
+ . build ( ) ;
182
+
183
+ p. cargo ( "read-manifest" )
184
+ . with_json ( & manifest_output_no_readme ( ) )
185
+ . run ( ) ;
186
+ }
187
+
188
+ // If a file named README.md exists, and `readme = true`, the value `README.md` should be defaulted in.
189
+ #[ cargo_test]
190
+ fn cargo_read_manifest_defaults_readme_if_true ( ) {
191
+ let p = project ( )
192
+ . file ( "Cargo.toml" , & basic_bin_manifest_with_readme ( "foo" , "true" ) )
193
+ . file ( "README.md" , "Sample project" )
194
+ . file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
195
+ . build ( ) ;
196
+
197
+ p. cargo ( "read-manifest" )
198
+ . with_json ( & manifest_output ( & format ! ( r#""{}""# , "README.md" ) ) )
199
+ . run ( ) ;
200
+ }
201
+
202
+ // If a file named README.md does not exist, and `readme = true`, it should panic.
203
+ #[ cargo_test]
204
+ #[ should_panic]
205
+ fn cargo_read_manifest_panics_if_default_readme_not_found ( ) {
206
+ let p = project ( )
207
+ . file ( "Cargo.toml" , & basic_bin_manifest_with_readme ( "foo" , "true" ) )
208
+ . file ( "README.txt" , "Sample project" )
209
+ . file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
210
+ . build ( ) ;
211
+
212
+ p. cargo ( "read-manifest" ) . run ( ) ;
108
213
}
0 commit comments