]>
Commit | Line | Data |
---|---|---|
83571aee EH |
1 | //! Tests for public/private dependencies. |
2 | ||
9115b2c3 AC |
3 | use cargo_test_support::registry::Package; |
4 | use cargo_test_support::{is_nightly, project}; | |
87f1a4b2 | 5 | |
0e0d9688 | 6 | #[cargo_test] |
87f1a4b2 AH |
7 | fn exported_priv_warning() { |
8 | if !is_nightly() { | |
9b590d0d | 9 | // exported_private_dependencies lint is unstable |
87f1a4b2 AH |
10 | return; |
11 | } | |
12 | Package::new("priv_dep", "0.1.0") | |
8a45e5c0 | 13 | .file("src/lib.rs", "pub struct FromPriv;") |
87f1a4b2 AH |
14 | .publish(); |
15 | ||
16 | let p = project() | |
17 | .file( | |
18 | "Cargo.toml", | |
19 | r#" | |
6f8c7d5a | 20 | cargo-features = ["public-dependency"] |
87f1a4b2 | 21 | |
6f8c7d5a EH |
22 | [package] |
23 | name = "foo" | |
24 | version = "0.0.1" | |
87f1a4b2 | 25 | |
6f8c7d5a EH |
26 | [dependencies] |
27 | priv_dep = "0.1.0" | |
28 | "#, | |
87f1a4b2 AH |
29 | ) |
30 | .file( | |
31 | "src/lib.rs", | |
32 | " | |
33 | extern crate priv_dep; | |
34 | pub fn use_priv(_: priv_dep::FromPriv) {} | |
35 | ", | |
36 | ) | |
37 | .build(); | |
38 | ||
39 | p.cargo("build --message-format=short") | |
40 | .masquerade_as_nightly_cargo() | |
75e7b418 | 41 | .with_stderr_contains( |
87f1a4b2 | 42 | "\ |
fd257186 EH |
43 | src/lib.rs:3:13: warning: type `[..]FromPriv` from private dependency 'priv_dep' in public interface |
44 | ", | |
87f1a4b2 AH |
45 | ) |
46 | .run() | |
47 | } | |
48 | ||
0e0d9688 | 49 | #[cargo_test] |
87f1a4b2 AH |
50 | fn exported_pub_dep() { |
51 | if !is_nightly() { | |
9b590d0d | 52 | // exported_private_dependencies lint is unstable |
87f1a4b2 AH |
53 | return; |
54 | } | |
55 | Package::new("pub_dep", "0.1.0") | |
8a45e5c0 | 56 | .file("src/lib.rs", "pub struct FromPub;") |
87f1a4b2 AH |
57 | .publish(); |
58 | ||
59 | let p = project() | |
60 | .file( | |
61 | "Cargo.toml", | |
62 | r#" | |
6f8c7d5a | 63 | cargo-features = ["public-dependency"] |
87f1a4b2 | 64 | |
6f8c7d5a EH |
65 | [package] |
66 | name = "foo" | |
67 | version = "0.0.1" | |
87f1a4b2 | 68 | |
6f8c7d5a EH |
69 | [dependencies] |
70 | pub_dep = {version = "0.1.0", public = true} | |
71 | "#, | |
87f1a4b2 AH |
72 | ) |
73 | .file( | |
74 | "src/lib.rs", | |
75 | " | |
76 | extern crate pub_dep; | |
77 | pub fn use_pub(_: pub_dep::FromPub) {} | |
78 | ", | |
79 | ) | |
80 | .build(); | |
81 | ||
82 | p.cargo("build --message-format=short") | |
83 | .masquerade_as_nightly_cargo() | |
84 | .with_stderr( | |
85 | "\ | |
86 | [UPDATING] `[..]` index | |
87 | [DOWNLOADING] crates ... | |
88 | [DOWNLOADED] pub_dep v0.1.0 ([..]) | |
89 | [COMPILING] pub_dep v0.1.0 | |
90 | [COMPILING] foo v0.0.1 ([CWD]) | |
91 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | |
8a45e5c0 | 92 | ", |
87f1a4b2 AH |
93 | ) |
94 | .run() | |
87f1a4b2 AH |
95 | } |
96 | ||
0e0d9688 | 97 | #[cargo_test] |
87f1a4b2 AH |
98 | pub fn requires_nightly_cargo() { |
99 | let p = project() | |
100 | .file( | |
101 | "Cargo.toml", | |
102 | r#" | |
6f8c7d5a EH |
103 | cargo-features = ["public-dependency"] |
104 | "#, | |
87f1a4b2 | 105 | ) |
8a45e5c0 | 106 | .file("src/lib.rs", "") |
87f1a4b2 AH |
107 | .build(); |
108 | ||
109 | p.cargo("build --message-format=short") | |
110 | .with_status(101) | |
111 | .with_stderr( | |
112 | "\ | |
113 | error: failed to parse manifest at `[..]` | |
114 | ||
115 | Caused by: | |
116 | the cargo feature `public-dependency` requires a nightly version of Cargo, but this is the `stable` channel | |
6514c289 | 117 | See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels. |
7bbef3de | 118 | See https://doc.rust-lang.org/[..]cargo/reference/unstable.html#public-dependency for more information about using this feature. |
87f1a4b2 AH |
119 | " |
120 | ) | |
121 | .run() | |
122 | } | |
123 | ||
0e0d9688 | 124 | #[cargo_test] |
87f1a4b2 | 125 | fn requires_feature() { |
87f1a4b2 | 126 | Package::new("pub_dep", "0.1.0") |
8a45e5c0 | 127 | .file("src/lib.rs", "") |
87f1a4b2 AH |
128 | .publish(); |
129 | ||
87f1a4b2 AH |
130 | let p = project() |
131 | .file( | |
132 | "Cargo.toml", | |
133 | r#" | |
6f8c7d5a EH |
134 | [package] |
135 | name = "foo" | |
136 | version = "0.0.1" | |
87f1a4b2 | 137 | |
6f8c7d5a EH |
138 | [dependencies] |
139 | pub_dep = { version = "0.1.0", public = true } | |
140 | "#, | |
87f1a4b2 | 141 | ) |
8a45e5c0 | 142 | .file("src/lib.rs", "") |
87f1a4b2 AH |
143 | .build(); |
144 | ||
145 | p.cargo("build --message-format=short") | |
146 | .masquerade_as_nightly_cargo() | |
147 | .with_status(101) | |
148 | .with_stderr( | |
149 | "\ | |
150 | error: failed to parse manifest at `[..]` | |
151 | ||
152 | Caused by: | |
153 | feature `public-dependency` is required | |
154 | ||
2c99f654 EH |
155 | The package requires the Cargo feature called `public-dependency`, \ |
156 | but that feature is not stabilized in this version of Cargo (1.[..]). | |
157 | Consider adding `cargo-features = [\"public-dependency\"]` to the top of Cargo.toml \ | |
158 | (above the [package] table) to tell Cargo you are opting in to use this unstable feature. | |
159 | See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency \ | |
160 | for more information about the status of this feature. | |
8a45e5c0 | 161 | ", |
87f1a4b2 AH |
162 | ) |
163 | .run() | |
87f1a4b2 | 164 | } |
df4d2095 | 165 | |
0e0d9688 | 166 | #[cargo_test] |
df4d2095 AH |
167 | fn pub_dev_dependency() { |
168 | Package::new("pub_dep", "0.1.0") | |
169 | .file("src/lib.rs", "pub struct FromPub;") | |
170 | .publish(); | |
171 | ||
172 | let p = project() | |
173 | .file( | |
174 | "Cargo.toml", | |
175 | r#" | |
6f8c7d5a | 176 | cargo-features = ["public-dependency"] |
df4d2095 | 177 | |
6f8c7d5a EH |
178 | [package] |
179 | name = "foo" | |
180 | version = "0.0.1" | |
df4d2095 | 181 | |
6f8c7d5a EH |
182 | [dev-dependencies] |
183 | pub_dep = {version = "0.1.0", public = true} | |
184 | "#, | |
df4d2095 AH |
185 | ) |
186 | .file( | |
187 | "src/lib.rs", | |
188 | " | |
189 | extern crate pub_dep; | |
190 | pub fn use_pub(_: pub_dep::FromPub) {} | |
191 | ", | |
192 | ) | |
193 | .build(); | |
194 | ||
195 | p.cargo("build --message-format=short") | |
196 | .masquerade_as_nightly_cargo() | |
197 | .with_status(101) | |
198 | .with_stderr( | |
199 | "\ | |
200 | error: failed to parse manifest at `[..]` | |
201 | ||
202 | Caused by: | |
203 | 'public' specifier can only be used on regular dependencies, not Development dependencies | |
204 | ", | |
205 | ) | |
206 | .run() | |
207 | } |