@@ -6,9 +6,9 @@ use cargo_test_support::{no_such_file_err_msg, project};
6
6
#[ cargo_test]
7
7
fn gated ( ) {
8
8
// Requires -Z flag.
9
- write_config ( "include='other'" ) ;
9
+ write_config ( "include='other.toml '" ) ;
10
10
write_config_at (
11
- ".cargo/other" ,
11
+ ".cargo/other.toml " ,
12
12
"
13
13
othervalue = 1
14
14
" ,
@@ -25,13 +25,13 @@ fn simple() {
25
25
write_config_at (
26
26
".cargo/config" ,
27
27
"
28
- include = 'other'
28
+ include = 'other.toml '
29
29
key1 = 1
30
30
key2 = 2
31
31
" ,
32
32
) ;
33
33
write_config_at (
34
- ".cargo/other" ,
34
+ ".cargo/other.toml " ,
35
35
"
36
36
key2 = 3
37
37
key3 = 4
@@ -84,39 +84,63 @@ fn works_with_cli() {
84
84
}
85
85
86
86
#[ cargo_test]
87
- fn left_to_right ( ) {
88
- // How it merges multiple includes.
87
+ fn left_to_right_bottom_to_top ( ) {
88
+ // How it merges multiple nested includes.
89
89
write_config_at (
90
90
".cargo/config" ,
91
91
"
92
- include = ['one', 'two']
93
- primary = 1
92
+ include = ['left-middle.toml', 'right-middle.toml']
93
+ top = 1
94
+ " ,
95
+ ) ;
96
+ write_config_at (
97
+ ".cargo/right-middle.toml" ,
98
+ "
99
+ include = 'right-bottom.toml'
100
+ top = 0
101
+ right-middle = 0
94
102
" ,
95
103
) ;
96
104
write_config_at (
97
- ".cargo/one " ,
105
+ ".cargo/right-bottom.toml " ,
98
106
"
99
- one = 1
100
- primary = 2
107
+ top = -1
108
+ right-middle = -1
109
+ right-bottom = -1
101
110
" ,
102
111
) ;
103
112
write_config_at (
104
- ".cargo/two " ,
113
+ ".cargo/left-middle.toml " ,
105
114
"
106
- two = 2
107
- primary = 3
115
+ include = 'left-bottom.toml'
116
+ top = -2
117
+ right-middle = -2
118
+ right-bottom = -2
119
+ left-middle = -2
120
+ " ,
121
+ ) ;
122
+ write_config_at (
123
+ ".cargo/left-bottom.toml" ,
124
+ "
125
+ top = -3
126
+ right-middle = -3
127
+ right-bottom = -3
128
+ left-middle = -3
129
+ left-bottom = -3
108
130
" ,
109
131
) ;
110
132
let config = ConfigBuilder :: new ( ) . unstable_flag ( "config-include" ) . build ( ) ;
111
- assert_eq ! ( config. get:: <i32 >( "primary" ) . unwrap( ) , 1 ) ;
112
- assert_eq ! ( config. get:: <i32 >( "one" ) . unwrap( ) , 1 ) ;
113
- assert_eq ! ( config. get:: <i32 >( "two" ) . unwrap( ) , 2 ) ;
133
+ assert_eq ! ( config. get:: <i32 >( "top" ) . unwrap( ) , 1 ) ;
134
+ assert_eq ! ( config. get:: <i32 >( "right-middle" ) . unwrap( ) , 0 ) ;
135
+ assert_eq ! ( config. get:: <i32 >( "right-bottom" ) . unwrap( ) , -1 ) ;
136
+ assert_eq ! ( config. get:: <i32 >( "left-middle" ) . unwrap( ) , -2 ) ;
137
+ assert_eq ! ( config. get:: <i32 >( "left-bottom" ) . unwrap( ) , -3 ) ;
114
138
}
115
139
116
140
#[ cargo_test]
117
141
fn missing_file ( ) {
118
142
// Error when there's a missing file.
119
- write_config ( "include='missing'" ) ;
143
+ write_config ( "include='missing.toml '" ) ;
120
144
let config = ConfigBuilder :: new ( )
121
145
. unstable_flag ( "config-include" )
122
146
. build_err ( ) ;
@@ -127,10 +151,10 @@ fn missing_file() {
127
151
could not load Cargo configuration
128
152
129
153
Caused by:
130
- failed to load config include `missing` from `[..]/.cargo/config`
154
+ failed to load config include `missing.toml ` from `[..]/.cargo/config`
131
155
132
156
Caused by:
133
- failed to read configuration file `[..]/.cargo/missing`
157
+ failed to read configuration file `[..]/.cargo/missing.toml `
134
158
135
159
Caused by:
136
160
{}" ,
@@ -139,12 +163,30 @@ Caused by:
139
163
) ;
140
164
}
141
165
166
+ #[ cargo_test]
167
+ fn wrong_file_extension ( ) {
168
+ // Error when it doesn't end with `.toml`.
169
+ write_config ( "include='config.png'" ) ;
170
+ let config = ConfigBuilder :: new ( )
171
+ . unstable_flag ( "config-include" )
172
+ . build_err ( ) ;
173
+ assert_error (
174
+ config. unwrap_err ( ) ,
175
+ "\
176
+ could not load Cargo configuration
177
+
178
+ Caused by:
179
+ expected a config include path ending with `.toml`, but found `config.png` from `[..]/.cargo/config`
180
+ " ,
181
+ ) ;
182
+ }
183
+
142
184
#[ cargo_test]
143
185
fn cycle ( ) {
144
186
// Detects a cycle.
145
- write_config_at ( ".cargo/config" , "include='one'" ) ;
146
- write_config_at ( ".cargo/one" , "include='two'" ) ;
147
- write_config_at ( ".cargo/two" , "include='config'" ) ;
187
+ write_config_at ( ".cargo/config.toml " , "include='one.toml '" ) ;
188
+ write_config_at ( ".cargo/one.toml " , "include='two.toml '" ) ;
189
+ write_config_at ( ".cargo/two.toml " , "include='config.toml '" ) ;
148
190
let config = ConfigBuilder :: new ( )
149
191
. unstable_flag ( "config-include" )
150
192
. build_err ( ) ;
@@ -154,16 +196,16 @@ fn cycle() {
154
196
could not load Cargo configuration
155
197
156
198
Caused by:
157
- failed to load config include `one` from `[..]/.cargo/config`
199
+ failed to load config include `one.toml ` from `[..]/.cargo/config.toml `
158
200
159
201
Caused by:
160
- failed to load config include `two` from `[..]/.cargo/one`
202
+ failed to load config include `two.toml ` from `[..]/.cargo/one.toml `
161
203
162
204
Caused by:
163
- failed to load config include `config` from `[..]/.cargo/two`
205
+ failed to load config include `config.toml ` from `[..]/.cargo/two.toml `
164
206
165
207
Caused by:
166
- config `include` cycle detected with path `[..]/.cargo/config`" ,
208
+ config `include` cycle detected with path `[..]/.cargo/config.toml `" ,
167
209
) ;
168
210
}
169
211
@@ -178,10 +220,10 @@ fn cli_include() {
178
220
bar = 2
179
221
" ,
180
222
) ;
181
- write_config_at ( ".cargo/config-foo" , "foo = 2" ) ;
223
+ write_config_at ( ".cargo/config-foo.toml " , "foo = 2" ) ;
182
224
let config = ConfigBuilder :: new ( )
183
225
. unstable_flag ( "config-include" )
184
- . config_arg ( "include='.cargo/config-foo'" )
226
+ . config_arg ( "include='.cargo/config-foo.toml '" )
185
227
. build ( ) ;
186
228
assert_eq ! ( config. get:: <i32 >( "foo" ) . unwrap( ) , 2 ) ;
187
229
assert_eq ! ( config. get:: <i32 >( "bar" ) . unwrap( ) , 2 ) ;
@@ -209,7 +251,7 @@ fn cli_include_failed() {
209
251
// Error message when CLI include fails to load.
210
252
let config = ConfigBuilder :: new ( )
211
253
. unstable_flag ( "config-include" )
212
- . config_arg ( "include='foobar'" )
254
+ . config_arg ( "include='foobar.toml '" )
213
255
. build_err ( ) ;
214
256
assert_error (
215
257
config. unwrap_err ( ) ,
@@ -218,10 +260,10 @@ fn cli_include_failed() {
218
260
failed to load --config include
219
261
220
262
Caused by:
221
- failed to load config include `foobar` from `--config cli option`
263
+ failed to load config include `foobar.toml ` from `--config cli option`
222
264
223
265
Caused by:
224
- failed to read configuration file `[..]/foobar`
266
+ failed to read configuration file `[..]/foobar.toml `
225
267
226
268
Caused by:
227
269
{}" ,
@@ -235,14 +277,14 @@ fn cli_merge_failed() {
235
277
// Error message when CLI include merge fails.
236
278
write_config ( "foo = ['a']" ) ;
237
279
write_config_at (
238
- ".cargo/other" ,
280
+ ".cargo/other.toml " ,
239
281
"
240
282
foo = 'b'
241
283
" ,
242
284
) ;
243
285
let config = ConfigBuilder :: new ( )
244
286
. unstable_flag ( "config-include" )
245
- . config_arg ( "include='.cargo/other'" )
287
+ . config_arg ( "include='.cargo/other.toml '" )
246
288
. build_err ( ) ;
247
289
// Maybe this error message should mention it was from an include file?
248
290
assert_error (
@@ -251,7 +293,7 @@ fn cli_merge_failed() {
251
293
failed to merge --config key `foo` into `[..]/.cargo/config`
252
294
253
295
Caused by:
254
- failed to merge config value from `[..]/.cargo/other` into `[..]/.cargo/config`: \
296
+ failed to merge config value from `[..]/.cargo/other.toml ` into `[..]/.cargo/config`: \
255
297
expected array, but found string",
256
298
) ;
257
299
}
0 commit comments