@@ -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#bar@0.1.0" )
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#crates-io@0.1.0" )
93
+ . run ( ) ;
94
+
62
95
// Bad URL.
63
96
p. cargo ( "pkgid https://example.com/crates-io" )
64
97
. with_status ( 101 )
@@ -83,6 +116,35 @@ error: package ID specification `crates_io` did not match any packages
83
116
" ,
84
117
)
85
118
. run ( ) ;
119
+ }
120
+
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#two-ver@0.2.0" )
147
+ . run ( ) ;
86
148
87
149
// Ambiguous.
88
150
p. cargo ( "pkgid two-ver" )
@@ -107,34 +169,6 @@ Did you mean one of these?
107
169
108
170
two-ver@0.1.0
109
171
two-ver@0.2.0
110
- " ,
111
- )
112
- . run ( ) ;
113
-
114
- // Bad file URL.
115
- p. cargo ( "pkgid ./Cargo.toml" )
116
- . with_status ( 101 )
117
- . with_stderr (
118
- "\
119
- error: invalid package ID specification: `./Cargo.toml`
120
-
121
- Caused by:
122
- package ID specification `./Cargo.toml` looks like a file path, maybe try file://[..]/Cargo.toml
123
- " ,
124
- )
125
- . run ( ) ;
126
-
127
- // Bad file URL with similar name.
128
- p. cargo ( "pkgid './cratesio'" )
129
- . with_status ( 101 )
130
- . with_stderr (
131
- "\
132
- error: invalid package ID specification: `./cratesio`
133
-
134
- <tab>Did you mean `crates-io`?
135
-
136
- Caused by:
137
- package ID specification `./cratesio` looks like a file path, maybe try file://[..]/cratesio
138
172
" ,
139
173
)
140
174
. run ( ) ;
0 commit comments