@@ -4,22 +4,31 @@ use cargo_test_support::project;
4
4
use cargo_test_support:: registry:: Package ;
5
5
6
6
#[ cargo_test]
7
- fn simple ( ) {
8
- Package :: new ( "bar" , "0.1.0" ) . publish ( ) ;
7
+ fn local ( ) {
9
8
let p = project ( )
10
9
. file (
11
10
"Cargo.toml" ,
12
11
r#"
12
+ [workspace]
13
+ members = ["bar"]
14
+
13
15
[package]
14
16
name = "foo"
15
17
version = "0.1.0"
16
18
edition = "2018"
17
-
18
- [dependencies]
19
- bar = "0.1.0"
20
19
"# ,
21
20
)
22
21
. file ( "src/main.rs" , "fn main() {}" )
22
+ . file (
23
+ "bar/Cargo.toml" ,
24
+ r#"
25
+ [package]
26
+ name = "bar"
27
+ version = "0.1.0"
28
+ edition = "2018"
29
+ "# ,
30
+ )
31
+ . file ( "bar/src/main.rs" , "fn main() {}" )
23
32
. build ( ) ;
24
33
25
34
p. cargo ( "generate-lockfile" ) . run ( ) ;
@@ -28,16 +37,38 @@ fn simple() {
28
37
. with_stdout ( format ! ( "file://[..]{}#0.1.0" , p. root( ) . to_str( ) . unwrap( ) ) )
29
38
. run ( ) ;
30
39
31
- p. cargo ( "pkgid bar" )
32
- . with_stdout ( "https://github.com/rust-lang/crates.io-index#[email protected] " )
40
+ // Bad file URL.
41
+ p. cargo ( "pkgid ./Cargo.toml" )
42
+ . with_status ( 101 )
43
+ . with_stderr (
44
+ "\
45
+ error: invalid package ID specification: `./Cargo.toml`
46
+
47
+ Caused by:
48
+ package ID specification `./Cargo.toml` looks like a file path, maybe try file://[..]/Cargo.toml
49
+ " ,
50
+ )
51
+ . run ( ) ;
52
+
53
+ // Bad file URL with similar name.
54
+ p. cargo ( "pkgid './bar'" )
55
+ . with_status ( 101 )
56
+ . with_stderr (
57
+ "\
58
+ error: invalid package ID specification: `./bar`
59
+
60
+ <tab>Did you mean `bar`?
61
+
62
+ Caused by:
63
+ package ID specification `./bar` looks like a file path, maybe try file://[..]/bar
64
+ " ,
65
+ )
33
66
. run ( ) ;
34
67
}
35
68
36
69
#[ cargo_test]
37
- fn suggestion_bad_pkgid ( ) {
70
+ fn registry ( ) {
38
71
Package :: new ( "crates-io" , "0.1.0" ) . publish ( ) ;
39
- Package :: new ( "two-ver" , "0.1.0" ) . publish ( ) ;
40
- Package :: new ( "two-ver" , "0.2.0" ) . publish ( ) ;
41
72
let p = project ( )
42
73
. file (
43
74
"Cargo.toml" ,
@@ -49,16 +80,18 @@ fn suggestion_bad_pkgid() {
49
80
50
81
[dependencies]
51
82
crates-io = "0.1.0"
52
- two-ver = "0.1.0"
53
- two-ver2 = { package = "two-ver", version = "0.2.0" }
54
83
"# ,
55
84
)
56
- . file ( "src/lib .rs" , "" )
85
+ . file ( "src/main .rs" , "fn main() {} " )
57
86
. file ( "cratesio" , "" )
58
87
. build ( ) ;
59
88
60
89
p. cargo ( "generate-lockfile" ) . run ( ) ;
61
90
91
+ p. cargo ( "pkgid crates-io" )
92
+ . with_stdout ( "https://github.com/rust-lang/crates.io-index#[email protected] " )
93
+ . run ( ) ;
94
+
62
95
// Bad URL.
63
96
p. cargo ( "pkgid https://example.com/crates-io" )
64
97
. with_status ( 101 )
@@ -83,45 +116,87 @@ error: package ID specification `crates_io` did not match any packages
83
116
" ,
84
117
)
85
118
. run ( ) ;
119
+ }
86
120
87
- // Bad version.
88
- p. cargo ( "pkgid two-ver:0.3.0" )
121
+ #[ cargo_test]
122
+ fn multiple_versions ( ) {
123
+ Package :: new ( "two-ver" , "0.1.0" ) . publish ( ) ;
124
+ Package :: new ( "two-ver" , "0.2.0" ) . publish ( ) ;
125
+ let p = project ( )
126
+ . file (
127
+ "Cargo.toml" ,
128
+ r#"
129
+ [package]
130
+ name = "foo"
131
+ version = "0.1.0"
132
+ edition = "2018"
133
+
134
+ [dependencies]
135
+ two-ver = "0.1.0"
136
+ two-ver2 = { package = "two-ver", version = "0.2.0" }
137
+ "# ,
138
+ )
139
+ . file ( "src/lib.rs" , "" )
140
+ . file ( "cratesio" , "" )
141
+ . build ( ) ;
142
+
143
+ p. cargo ( "generate-lockfile" ) . run ( ) ;
144
+
145
+ p. cargo ( "pkgid two-ver:0.2.0" )
146
+ . with_stdout ( "https://github.com/rust-lang/crates.io-index#[email protected] " )
147
+ . run ( ) ;
148
+
149
+ // Incomplete version.
150
+ p. cargo ( "pkgid two-ver@0" )
89
151
. with_status ( 101 )
90
152
. with_stderr (
91
153
"\
92
- error: package ID specification `[email protected] ` did not match any packages
93
- Did you mean one of these?
154
+ error: invalid package ID specification: `two-ver@0`
94
155
95
-
96
-
156
+ <tab>Did you mean `two-ver`?
157
+
158
+ Caused by:
159
+ cannot parse '0' as a SemVer version
97
160
" ,
98
161
)
99
162
. run ( ) ;
100
163
101
- // Bad file URL .
102
- p. cargo ( "pkgid ./Cargo.toml " )
164
+ // Incomplete version .
165
+ p
. cargo ( "pkgid [email protected] " )
103
166
. with_status ( 101 )
104
167
. with_stderr (
105
168
"\
106
- error: invalid package ID specification: `./Cargo.toml `
169
+ error: invalid package ID specification: `[email protected] `
107
170
108
171
Caused by:
109
- package ID specification `./Cargo.toml` looks like a file path, maybe try file://[..]/Cargo.toml
172
+ cannot parse '0.2' as a SemVer version
110
173
" ,
111
174
)
112
175
. run ( ) ;
113
176
114
- // Bad file URL with similar name .
115
- p. cargo ( "pkgid './cratesio' " )
177
+ // Ambiguous .
178
+ p. cargo ( "pkgid two-ver " )
116
179
. with_status ( 101 )
117
180
. with_stderr (
118
181
"\
119
- error: invalid package ID specification: `./cratesio`
182
+ error: There are multiple `two-ver` packages in your project, and the specification `two-ver` is ambiguous.
183
+ Please re-run this command with `-p <spec>` where `<spec>` is one of the following:
184
+
185
+
186
+ " ,
187
+ )
188
+ . run ( ) ;
120
189
121
- <tab>Did you mean `crates-io`?
190
+ // Bad version.
191
+ p. cargo ( "pkgid two-ver:0.3.0" )
192
+ . with_status ( 101 )
193
+ . with_stderr (
194
+ "\
195
+ error: package ID specification `[email protected] ` did not match any packages
196
+ Did you mean one of these?
122
197
123
- Caused by:
124
- package ID specification `./cratesio` looks like a file path, maybe try file://[..]/cratesio
198
+
199
+
125
200
" ,
126
201
)
127
202
. run ( ) ;
0 commit comments