Skip to content

Commit 489dde1

Browse files
committed
test: Show open-namespaces behavior
1 parent b321285 commit 489dde1

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

tests/testsuite/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ mod net_config;
127127
mod new;
128128
mod offline;
129129
mod old_cargos;
130+
mod open_namespaces;
130131
mod out_dir;
131132
mod owner;
132133
mod package;

tests/testsuite/open_namespaces.rs

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
use cargo_test_support::project;
2+
use cargo_test_support::registry::RegistryBuilder;
3+
4+
#[cargo_test]
5+
fn within_namespace_requires_feature() {
6+
let p = project()
7+
.file(
8+
"Cargo.toml",
9+
r#"
10+
[package]
11+
name = "foo::bar"
12+
version = "0.0.1"
13+
edition = "2015"
14+
"#,
15+
)
16+
.file("src/lib.rs", "")
17+
.build();
18+
19+
p.cargo("read-manifest")
20+
.masquerade_as_nightly_cargo(&["open-namespaces"])
21+
.with_status(101)
22+
.with_stderr(
23+
"\
24+
[ERROR] invalid character `:` in package name: `foo::bar`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
25+
--> Cargo.toml:3:24
26+
|
27+
3 | name = \"foo::bar\"
28+
| ^^^^^^^^^^
29+
|
30+
",
31+
)
32+
.run()
33+
}
34+
35+
#[cargo_test]
36+
fn implicit_lib_within_namespace() {
37+
let p = project()
38+
.file(
39+
"Cargo.toml",
40+
r#"
41+
cargo-features = ["open-namespaces"]
42+
43+
[package]
44+
name = "foo::bar"
45+
version = "0.0.1"
46+
edition = "2015"
47+
"#,
48+
)
49+
.file("src/lib.rs", "")
50+
.build();
51+
52+
p.cargo("read-manifest")
53+
.masquerade_as_nightly_cargo(&["open-namespaces"])
54+
.with_status(101)
55+
.with_stderr(
56+
"\
57+
[ERROR] invalid character `:` in package name: `foo::bar`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
58+
--> Cargo.toml:5:24
59+
|
60+
5 | name = \"foo::bar\"
61+
| ^^^^^^^^^^
62+
|
63+
",
64+
)
65+
.run()
66+
}
67+
68+
#[cargo_test]
69+
fn implicit_bin_within_namespace() {
70+
let p = project()
71+
.file(
72+
"Cargo.toml",
73+
r#"
74+
cargo-features = ["open-namespaces"]
75+
76+
[package]
77+
name = "foo::bar"
78+
version = "0.0.1"
79+
edition = "2015"
80+
"#,
81+
)
82+
.file("src/main.rs", "fn main() {}")
83+
.build();
84+
85+
p.cargo("read-manifest")
86+
.masquerade_as_nightly_cargo(&["open-namespaces"])
87+
.with_status(101)
88+
.with_stderr(
89+
"\
90+
[ERROR] invalid character `:` in package name: `foo::bar`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
91+
--> Cargo.toml:5:24
92+
|
93+
5 | name = \"foo::bar\"
94+
| ^^^^^^^^^^
95+
|
96+
",
97+
)
98+
.run()
99+
}
100+
101+
#[cargo_test]
102+
fn explicit_bin_within_namespace() {
103+
let p = project()
104+
.file(
105+
"Cargo.toml",
106+
r#"
107+
cargo-features = ["open-namespaces"]
108+
109+
[package]
110+
name = "foo::bar"
111+
version = "0.0.1"
112+
edition = "2015"
113+
114+
[[bin]]
115+
name = "foo-bar"
116+
"#,
117+
)
118+
.file("src/lib.rs", "")
119+
.file("src/foo-bar/main.rs", "fn main() {}")
120+
.build();
121+
122+
p.cargo("read-manifest")
123+
.masquerade_as_nightly_cargo(&["open-namespaces"])
124+
.with_status(101)
125+
.with_stderr(
126+
"\
127+
[ERROR] invalid character `:` in package name: `foo::bar`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
128+
--> Cargo.toml:5:24
129+
|
130+
5 | name = \"foo::bar\"
131+
| ^^^^^^^^^^
132+
|
133+
",
134+
)
135+
.run()
136+
}
137+
138+
#[cargo_test]
139+
#[cfg(unix)]
140+
fn namespaced_script_name() {
141+
let p = cargo_test_support::project()
142+
.file(
143+
"foo::bar.rs",
144+
r#"---
145+
cargo-features = ["open-namespaces"]
146+
package.edition = "2021"
147+
---
148+
149+
fn main() {}
150+
"#,
151+
)
152+
.build();
153+
154+
p.cargo("read-manifest -Zscript --manifest-path foo::bar.rs")
155+
.masquerade_as_nightly_cargo(&["script", "open-namespaces"])
156+
.with_json(
157+
r#"{
158+
"authors": [],
159+
"categories": [],
160+
"default_run": null,
161+
"dependencies": [],
162+
"description": null,
163+
"documentation": null,
164+
"edition": "2021",
165+
"features": {},
166+
"homepage": null,
167+
"id": "path+file://[..]#foo--bar@0.0.0",
168+
"keywords": [],
169+
"license": null,
170+
"license_file": null,
171+
"links": null,
172+
"manifest_path": "[CWD]/foo::bar.rs",
173+
"metadata": null,
174+
"name": "foo--bar",
175+
"publish": [],
176+
"readme": null,
177+
"repository": null,
178+
"rust_version": null,
179+
"source": null,
180+
"targets": [
181+
{
182+
"crate_types": [
183+
"bin"
184+
],
185+
"doc": true,
186+
"doctest": false,
187+
"edition": "2021",
188+
"kind": [
189+
"bin"
190+
],
191+
"name": "foo--bar",
192+
"src_path": "[..]/foo::bar.rs",
193+
"test": true
194+
}
195+
],
196+
"version": "0.0.0"
197+
}
198+
"#,
199+
)
200+
.with_stderr(
201+
"\
202+
",
203+
)
204+
.run();
205+
}
206+
207+
#[cargo_test]
208+
fn publish_namespaced() {
209+
let registry = RegistryBuilder::new().http_api().http_index().build();
210+
211+
let p = project()
212+
.file(
213+
"Cargo.toml",
214+
r#"
215+
cargo-features = ["open-namespaces"]
216+
217+
[package]
218+
name = "foo::bar"
219+
version = "0.0.1"
220+
edition = "2015"
221+
authors = []
222+
license = "MIT"
223+
description = "foo"
224+
"#,
225+
)
226+
.file("src/lib.rs", "fn main() {}")
227+
.build();
228+
229+
p.cargo("publish")
230+
.masquerade_as_nightly_cargo(&["script", "open-namespaces"])
231+
.replace_crates_io(registry.index_url())
232+
.with_status(101)
233+
.with_stderr(
234+
"\
235+
[ERROR] invalid character `:` in package name: `foo::bar`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
236+
--> Cargo.toml:5:24
237+
|
238+
5 | name = \"foo::bar\"
239+
| ^^^^^^^^^^
240+
|
241+
",
242+
)
243+
.run();
244+
}

0 commit comments

Comments
 (0)