1
1
//! Tests for the `cargo read-manifest` command.
2
2
3
- use cargo_test_support:: { basic_bin_manifest, main_file, project} ;
3
+ use cargo_test_support:: { basic_bin_manifest, basic_bin_manifest_with_readme , 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,25 @@ 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
+ }}"# , readme_value
39
+ )
40
+ }
41
+
42
+ fn manifest_output_no_readme ( ) -> String {
43
+ manifest_output ( "null" )
44
+ }
37
45
38
46
#[ cargo_test]
39
47
fn cargo_read_manifest_path_to_cargo_toml_relative ( ) {
@@ -44,7 +52,7 @@ fn cargo_read_manifest_path_to_cargo_toml_relative() {
44
52
45
53
p. cargo ( "read-manifest --manifest-path foo/Cargo.toml" )
46
54
. cwd ( p. root ( ) . parent ( ) . unwrap ( ) )
47
- . with_json ( MANIFEST_OUTPUT )
55
+ . with_json ( & manifest_output_no_readme ( ) )
48
56
. run ( ) ;
49
57
}
50
58
@@ -58,7 +66,7 @@ fn cargo_read_manifest_path_to_cargo_toml_absolute() {
58
66
p. cargo ( "read-manifest --manifest-path" )
59
67
. arg ( p. root ( ) . join ( "Cargo.toml" ) )
60
68
. cwd ( p. root ( ) . parent ( ) . unwrap ( ) )
61
- . with_json ( MANIFEST_OUTPUT )
69
+ . with_json ( & manifest_output_no_readme ( ) )
62
70
. run ( ) ;
63
71
}
64
72
@@ -104,5 +112,32 @@ fn cargo_read_manifest_cwd() {
104
112
. file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
105
113
. build ( ) ;
106
114
107
- p. cargo ( "read-manifest" ) . with_json ( MANIFEST_OUTPUT ) . run ( ) ;
115
+ p. cargo ( "read-manifest" ) . with_json ( & manifest_output_no_readme ( ) ) . run ( ) ;
116
+ }
117
+
118
+ #[ cargo_test]
119
+ fn cargo_read_manifest_default_readme ( ) {
120
+ let readme_filenames = [ "README.md" , "README.txt" , "README" ] ;
121
+
122
+ for readme in readme_filenames. iter ( ) {
123
+ let p = project ( )
124
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
125
+ . file ( readme, "Sample project" )
126
+ . file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
127
+ . build ( ) ;
128
+
129
+ p. cargo ( "read-manifest" ) . with_json ( & manifest_output ( & format ! ( r#""{}""# , readme) ) ) . run ( ) ;
130
+ }
131
+ }
132
+
133
+ #[ cargo_test]
134
+ fn cargo_read_manifest_suppress_default_readme ( ) {
135
+ let p = project ( )
136
+ . file ( "Cargo.toml" , & basic_bin_manifest_with_readme ( "foo" , "false" ) )
137
+ . file ( "README.txt" , "Sample project" )
138
+ . file ( "src/foo.rs" , & main_file ( r#""i am foo""# , & [ ] ) )
139
+ . build ( ) ;
140
+
141
+ p. cargo ( "read-manifest" ) . with_json ( & manifest_output_no_readme ( ) ) . run ( ) ;
108
142
}
143
+
0 commit comments