Skip to content

Commit e70c733

Browse files
committed
Auto merge of #30211 - pnkfelix:fix-getopts-for-issue-30204, r=alexcrichton
Fix internal `getopts` so `--a=b=c` acts like `--a b=c` rather than `--a b`. Fix #30204
2 parents 3e2ebaa + 288034b commit e70c733

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/libgetopts/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
598598
let mut i_arg = None;
599599
if cur.as_bytes()[1] == b'-' {
600600
let tail = &cur[2..curlen];
601-
let tail_eq: Vec<&str> = tail.split('=').collect();
601+
let tail_eq: Vec<&str> = tail.splitn(2, '=').collect();
602602
if tail_eq.len() <= 1 {
603603
names = vec![Long(tail.to_owned())];
604604
} else {
@@ -1626,4 +1626,18 @@ Options:
16261626
debug!("generated: <<{}>>", generated_usage);
16271627
assert_eq!(generated_usage, expected);
16281628
}
1629+
1630+
#[test]
1631+
fn test_args_with_equals() {
1632+
let args = vec!("--one".to_string(), "A=B".to_string(),
1633+
"--two=C=D".to_string());
1634+
let opts = vec![optopt("o", "one", "One", "INFO"),
1635+
optopt("t", "two", "Two", "INFO")];
1636+
let matches = &match getopts(&args, &opts) {
1637+
result::Result::Ok(m) => m,
1638+
result::Result::Err(e) => panic!("{}", e)
1639+
};
1640+
assert_eq!(matches.opts_str(&["o".to_string()]).unwrap(), "A=B");
1641+
assert_eq!(matches.opts_str(&["t".to_string()]).unwrap(), "C=D");
1642+
}
16291643
}

src/test/run-make/output-type-permutations/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,56 +27,74 @@ all:
2727
rm $(TMPDIR)/foo
2828
$(RUSTC) foo.rs --emit asm=$(TMPDIR)/foo
2929
rm $(TMPDIR)/foo
30+
$(RUSTC) foo.rs --emit=asm=$(TMPDIR)/foo
31+
rm $(TMPDIR)/foo
3032
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
3133

3234
$(RUSTC) foo.rs --emit llvm-bc -o $(TMPDIR)/foo
3335
rm $(TMPDIR)/foo
3436
$(RUSTC) foo.rs --emit llvm-bc=$(TMPDIR)/foo
3537
rm $(TMPDIR)/foo
38+
$(RUSTC) foo.rs --emit=llvm-bc=$(TMPDIR)/foo
39+
rm $(TMPDIR)/foo
3640
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
3741

3842
$(RUSTC) foo.rs --emit llvm-ir -o $(TMPDIR)/foo
3943
rm $(TMPDIR)/foo
4044
$(RUSTC) foo.rs --emit llvm-ir=$(TMPDIR)/foo
4145
rm $(TMPDIR)/foo
46+
$(RUSTC) foo.rs --emit=llvm-ir=$(TMPDIR)/foo
47+
rm $(TMPDIR)/foo
4248
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
4349

4450
$(RUSTC) foo.rs --emit obj -o $(TMPDIR)/foo
4551
rm $(TMPDIR)/foo
4652
$(RUSTC) foo.rs --emit obj=$(TMPDIR)/foo
4753
rm $(TMPDIR)/foo
54+
$(RUSTC) foo.rs --emit=obj=$(TMPDIR)/foo
55+
rm $(TMPDIR)/foo
4856
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
4957

5058
$(RUSTC) foo.rs --emit link -o $(TMPDIR)/$(call BIN,foo)
5159
rm $(TMPDIR)/$(call BIN,foo)
5260
$(RUSTC) foo.rs --emit link=$(TMPDIR)/$(call BIN,foo)
5361
rm $(TMPDIR)/$(call BIN,foo)
62+
$(RUSTC) foo.rs --emit=link=$(TMPDIR)/$(call BIN,foo)
63+
rm $(TMPDIR)/$(call BIN,foo)
5464
rm -f $(TMPDIR)/foo.pdb
5565
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
5666

5767
$(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo
5868
rm $(TMPDIR)/foo
5969
$(RUSTC) foo.rs --crate-type=rlib --emit link=$(TMPDIR)/foo
6070
rm $(TMPDIR)/foo
71+
$(RUSTC) foo.rs --crate-type=rlib --emit=link=$(TMPDIR)/foo
72+
rm $(TMPDIR)/foo
6173
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
6274

6375
$(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/$(call BIN,foo)
6476
rm $(TMPDIR)/$(call BIN,foo)
6577
$(RUSTC) foo.rs --crate-type=dylib --emit link=$(TMPDIR)/$(call BIN,foo)
6678
rm $(TMPDIR)/$(call BIN,foo)
79+
$(RUSTC) foo.rs --crate-type=dylib --emit=link=$(TMPDIR)/$(call BIN,foo)
80+
rm $(TMPDIR)/$(call BIN,foo)
6781
rm -f $(TMPDIR)/foo.{exp,lib,pdb}
6882
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
6983

7084
$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
7185
rm $(TMPDIR)/foo
7286
$(RUSTC) foo.rs --crate-type=staticlib --emit link=$(TMPDIR)/foo
7387
rm $(TMPDIR)/foo
88+
$(RUSTC) foo.rs --crate-type=staticlib --emit=link=$(TMPDIR)/foo
89+
rm $(TMPDIR)/foo
7490
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
7591

7692
$(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/$(call BIN,foo)
7793
rm $(TMPDIR)/$(call BIN,foo)
7894
$(RUSTC) foo.rs --crate-type=bin --emit link=$(TMPDIR)/$(call BIN,foo)
7995
rm $(TMPDIR)/$(call BIN,foo)
96+
$(RUSTC) foo.rs --crate-type=bin --emit=link=$(TMPDIR)/$(call BIN,foo)
97+
rm $(TMPDIR)/$(call BIN,foo)
8098
rm -f $(TMPDIR)/foo.pdb
8199
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
82100

@@ -98,6 +116,17 @@ all:
98116
rm $(TMPDIR)/bc
99117
rm $(TMPDIR)/obj
100118
rm $(TMPDIR)/link
119+
$(RUSTC) foo.rs --emit=asm=$(TMPDIR)/asm \
120+
--emit llvm-ir=$(TMPDIR)/ir \
121+
--emit=llvm-bc=$(TMPDIR)/bc \
122+
--emit obj=$(TMPDIR)/obj \
123+
--emit=link=$(TMPDIR)/link \
124+
--crate-type=staticlib
125+
rm $(TMPDIR)/asm
126+
rm $(TMPDIR)/ir
127+
rm $(TMPDIR)/bc
128+
rm $(TMPDIR)/obj
129+
rm $(TMPDIR)/link
101130
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
102131

103132
$(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link --crate-type=staticlib

0 commit comments

Comments
 (0)