|
| 1 | +// When native libraries are passed to the linker, there used to be an annoyance |
| 2 | +// where multiple instances of the same library in a row would cause duplication in |
| 3 | +// outputs. This has been fixed, and this test checks that it stays fixed. |
| 4 | +// With the --cfg flag, -ltestb gets added to the output, breaking up the chain of -ltesta. |
| 5 | +// Without the --cfg flag, there should be a single -ltesta, no more, no less. |
| 6 | +// See https://github.com/rust-lang/rust/pull/84794 |
| 7 | + |
| 8 | +//@ ignore-msvc |
| 9 | + |
| 10 | +fn main() { |
| 11 | + rustc().input("depa.rs").run(); |
| 12 | + rustc().input("depb.rs").run(); |
| 13 | + rustc().input("depc.rs").run(); |
| 14 | + let output = |
| 15 | + String::from_utf8(rustc().input("empty.rs").cfg("bar").command_output().stderr).unwrap(); |
| 16 | + let pos_a1 = |
| 17 | + output.find("-ltesta").expect("empty.rs, compiled with --cfg, should contain -ltesta"); |
| 18 | + let pos_b = output[pos_a1..] |
| 19 | + .find("-ltestb") |
| 20 | + .map(|pos| pos + pos_a1) |
| 21 | + .expect("empty.rs, compiled with --cfg, should contain -ltestb"); |
| 22 | + let _ = output[pos_b..] |
| 23 | + .find("-ltesta") |
| 24 | + .map(|pos| pos + pos_b) |
| 25 | + .expect("empty.rs, compiled with --cfg, should contain a second -ltesta"); |
| 26 | + let output = String::from_utf8(rustc().input("empty.rs").command_output().stderr).unwrap(); |
| 27 | + assert!(output.contains("-ltesta")); |
| 28 | + let output = String::from_utf8(rustc().input("empty.rs").command_output().stderr).unwrap(); |
| 29 | + assert!(!output.contains("-ltestb")); |
| 30 | + let output = String::from_utf8(rustc().input("empty.rs").command_output().stderr).unwrap(); |
| 31 | + assert_eq!(output.matches("-ltesta").count, 1); |
| 32 | +} |
0 commit comments