@@ -79,6 +79,139 @@ fn enable_in_unstable_config() {
79
79
assert_eq ! ( gctx. get:: <i32 >( "key3" ) . ok( ) , None ) ;
80
80
}
81
81
82
+ #[ cargo_test]
83
+ fn mix_of_hierarchy_and_include ( ) {
84
+ write_config_at (
85
+ "foo/.cargo/config.toml" ,
86
+ "
87
+ include = 'other.toml'
88
+ key1 = 1
89
+
90
+ # also make sure unstable flags merge in the correct order
91
+ [unstable]
92
+ features = ['1']
93
+ " ,
94
+ ) ;
95
+ write_config_at (
96
+ "foo/.cargo/other.toml" ,
97
+ "
98
+ key1 = 2
99
+ key2 = 2
100
+
101
+ [unstable]
102
+ features = ['2']
103
+ " ,
104
+ ) ;
105
+ write_config_at (
106
+ ".cargo/config.toml" ,
107
+ "
108
+ include = 'other.toml'
109
+ key1 = 3
110
+ key2 = 3
111
+ key3 = 3
112
+
113
+ [unstable]
114
+ features = ['3']
115
+ " ,
116
+ ) ;
117
+ write_config_at (
118
+ ".cargo/other.toml" ,
119
+ "
120
+ key1 = 4
121
+ key2 = 4
122
+ key3 = 4
123
+ key4 = 4
124
+
125
+ [unstable]
126
+ features = ['4']
127
+ " ,
128
+ ) ;
129
+ let gctx = GlobalContextBuilder :: new ( )
130
+ . unstable_flag ( "config-include" )
131
+ . cwd ( "foo" )
132
+ . nightly_features_allowed ( true )
133
+ . build ( ) ;
134
+ assert_eq ! ( gctx. get:: <i32 >( "key1" ) . unwrap( ) , 1 ) ;
135
+ assert_eq ! ( gctx. get:: <i32 >( "key2" ) . unwrap( ) , 2 ) ;
136
+ assert_eq ! ( gctx. get:: <i32 >( "key3" ) . unwrap( ) , 3 ) ;
137
+ assert_eq ! ( gctx. get:: <i32 >( "key4" ) . unwrap( ) , 4 ) ;
138
+ assert_eq ! (
139
+ gctx. get:: <Vec <String >>( "unstable.features" ) . unwrap( ) ,
140
+ vec![
141
+ "4" . to_string( ) ,
142
+ "3" . to_string( ) ,
143
+ "2" . to_string( ) ,
144
+ "1" . to_string( )
145
+ ]
146
+ ) ;
147
+ }
148
+
149
+ #[ cargo_test]
150
+ fn mix_of_hierarchy_and_include_with_enable_in_unstable_config ( ) {
151
+ // `mix_of_hierarchy_and_include`, but with the config-include
152
+ // feature itself enabled in the unstable config table:
153
+ write_config_at (
154
+ "foo/.cargo/config.toml" ,
155
+ "
156
+ include = 'other.toml'
157
+ key1 = 1
158
+
159
+ # also make sure unstable flags merge in the correct order
160
+ [unstable]
161
+ features = ['1']
162
+ config-include = true
163
+ " ,
164
+ ) ;
165
+ write_config_at (
166
+ "foo/.cargo/other.toml" ,
167
+ "
168
+ key1 = 2
169
+ key2 = 2
170
+
171
+ [unstable]
172
+ features = ['2']
173
+ " ,
174
+ ) ;
175
+ write_config_at (
176
+ ".cargo/config.toml" ,
177
+ "
178
+ include = 'other.toml'
179
+ key1 = 3
180
+ key2 = 3
181
+ key3 = 3
182
+
183
+ [unstable]
184
+ features = ['3']
185
+ " ,
186
+ ) ;
187
+ write_config_at (
188
+ ".cargo/other.toml" ,
189
+ "
190
+ key1 = 4
191
+ key2 = 4
192
+ key3 = 4
193
+ key4 = 4
194
+
195
+ [unstable]
196
+ features = ['4']
197
+ " ,
198
+ ) ;
199
+ let gctx = GlobalContextBuilder :: new ( )
200
+ . cwd ( "foo" )
201
+ . nightly_features_allowed ( true )
202
+ . build ( ) ;
203
+ // On this commit, enabling `config-include` in the top-level
204
+ // configuration does not yet work.
205
+ assert_eq ! ( gctx. get:: <i32 >( "key1" ) . unwrap( ) , 1 ) ;
206
+ assert_eq ! ( gctx. get:: <i32 >( "key2" ) . unwrap( ) , 3 ) ;
207
+ assert_eq ! ( gctx. get:: <i32 >( "key3" ) . unwrap( ) , 3 ) ;
208
+ assert_eq ! ( gctx. get:: <i32 >( "key4" ) . ok( ) , None ) ;
209
+ assert_eq ! (
210
+ gctx. get:: <Vec <String >>( "unstable.features" ) . unwrap( ) ,
211
+ vec![ "3" . to_string( ) , "1" . to_string( ) ]
212
+ ) ;
213
+ }
214
+
82
215
#[ cargo_test]
83
216
fn works_with_cli ( ) {
84
217
write_config_at (
0 commit comments