Skip to content

Commit 4a96a40

Browse files
committed
test: add test to describe the issue#13280
Cargo fails to detect environment variable is newly set and rebuild if the environment variable is set in `config.toml`
1 parent 6f92aaa commit 4a96a40

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed

tests/testsuite/cargo_env_config.rs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,166 @@ MAIN ENV_TEST:from-env
276276
"#]])
277277
.run();
278278
}
279+
280+
#[cargo_test]
281+
fn env_changed_defined_in_config_toml() {
282+
let p = project()
283+
.file("Cargo.toml", &basic_bin_manifest("foo"))
284+
.file(
285+
"src/main.rs",
286+
r#"
287+
use std::env;
288+
fn main() {
289+
println!( "{}", env!("ENV_TEST") );
290+
}
291+
"#,
292+
)
293+
.file(
294+
".cargo/config.toml",
295+
r#"
296+
[env]
297+
ENV_TEST = "from-config"
298+
"#,
299+
)
300+
.build();
301+
302+
p.cargo("run")
303+
.with_stdout_data(str![[r#"
304+
from-config
305+
306+
"#]])
307+
.with_stderr_data(str![[r#"
308+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
309+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
310+
[RUNNING] `target/debug/foo[EXE]`
311+
312+
"#]])
313+
.run();
314+
315+
p.cargo("run")
316+
.env("ENV_TEST", "from-env")
317+
.with_stdout_data(str![[r#"
318+
from-config
319+
320+
"#]])
321+
.with_stderr_data(str![[r#"
322+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
323+
[RUNNING] `target/debug/foo[EXE]`
324+
325+
"#]])
326+
.run();
327+
328+
p.cargo("run")
329+
.env("ENV_TEST", "from-env")
330+
.with_stdout_data(str![[r#"
331+
from-config
332+
333+
"#]])
334+
.with_stderr_data(str![[r#"
335+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
336+
[RUNNING] `target/debug/foo[EXE]`
337+
338+
"#]])
339+
.run();
340+
}
341+
342+
#[cargo_test]
343+
fn forced_env_changed_defined_in_config_toml() {
344+
let p = project()
345+
.file("Cargo.toml", &basic_bin_manifest("foo"))
346+
.file(
347+
"src/main.rs",
348+
r#"
349+
use std::env;
350+
fn main() {
351+
println!( "{}", env!("ENV_TEST") );
352+
}
353+
"#,
354+
)
355+
.file(
356+
".cargo/config.toml",
357+
r#"
358+
[env]
359+
ENV_TEST = {value = "from-config", force = true}
360+
"#,
361+
)
362+
.build();
363+
364+
p.cargo("run")
365+
.with_stdout_data(str![[r#"
366+
from-config
367+
368+
"#]])
369+
.with_stderr_data(str![[r#"
370+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
371+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
372+
[RUNNING] `target/debug/foo[EXE]`
373+
374+
"#]])
375+
.run();
376+
377+
p.cargo("run")
378+
.env("ENV_TEST", "from-env")
379+
.with_stdout_data(str![[r#"
380+
from-config
381+
382+
"#]])
383+
.with_stderr_data(str![[r#"
384+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
385+
[RUNNING] `target/debug/foo[EXE]`
386+
387+
"#]])
388+
.run();
389+
}
390+
391+
#[cargo_test]
392+
fn env_changed_defined_in_config_args() {
393+
let p = project()
394+
.file("Cargo.toml", &basic_bin_manifest("foo"))
395+
.file(
396+
"src/main.rs",
397+
r#"
398+
use std::env;
399+
fn main() {
400+
println!( "{}", env!("ENV_TEST") );
401+
}
402+
"#,
403+
)
404+
.build();
405+
p.cargo(r#"run --config 'env.ENV_TEST="one"'"#)
406+
.with_stdout_data(str![[r#"
407+
one
408+
409+
"#]])
410+
.with_stderr_data(str![[r#"
411+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
412+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
413+
[RUNNING] `target/debug/foo[EXE]`
414+
415+
"#]])
416+
.run();
417+
418+
p.cargo(r#"run --config 'env.ENV_TEST="two"'"#)
419+
.with_stdout_data(str![[r#"
420+
one
421+
422+
"#]])
423+
.with_stderr_data(str![[r#"
424+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
425+
[RUNNING] `target/debug/foo[EXE]`
426+
427+
"#]])
428+
.run();
429+
430+
p.cargo(r#"run --config 'env.ENV_TEST="two"'"#)
431+
.with_stdout_data(str![[r#"
432+
one
433+
434+
"#]])
435+
.with_stderr_data(str![[r#"
436+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
437+
[RUNNING] `target/debug/foo[EXE]`
438+
439+
"#]])
440+
.run();
441+
}

0 commit comments

Comments
 (0)