1
1
//! Tests for the `cargo run` command.
2
2
3
+ use cargo_test_support:: registry:: Package ;
3
4
use cargo_test_support:: { basic_bin_manifest, basic_lib_manifest, project, Project } ;
4
5
use cargo_util:: paths:: dylib_path_envvar;
5
6
@@ -1157,7 +1158,7 @@ fn run_multiple_packages() {
1157
1158
. file ( "foo/d2/Cargo.toml" , & basic_bin_manifest ( "d2" ) )
1158
1159
. file ( "foo/d2/src/main.rs" , "fn main() { println!(\" d2\" ); }" )
1159
1160
. file ( "d3/Cargo.toml" , & basic_bin_manifest ( "d3" ) )
1160
- . file ( "d3/src/main.rs" , "fn main() { println!(\" d2 \" ); }" )
1161
+ . file ( "d3/src/main.rs" , "fn main() { println!(\" d3 \" ); }" )
1161
1162
. build ( ) ;
1162
1163
1163
1164
let cargo = || {
@@ -1182,12 +1183,7 @@ fn run_multiple_packages() {
1182
1183
. with_status ( 1 )
1183
1184
. with_stderr_contains ( "error: The argument '--package <SPEC>' was provided more than once, but cannot be used multiple times" ) . run ( ) ;
1184
1185
1185
- cargo ( )
1186
- . arg ( "-p" )
1187
- . arg ( "d3" )
1188
- . with_status ( 101 )
1189
- . with_stderr_contains ( "[ERROR] package(s) `d3` not found in workspace [..]" )
1190
- . run ( ) ;
1186
+ cargo ( ) . arg ( "-p" ) . arg ( "d3" ) . with_stdout ( "d3" ) . run ( ) ;
1191
1187
1192
1188
cargo ( )
1193
1189
. arg ( "-p" )
@@ -1199,6 +1195,111 @@ fn run_multiple_packages() {
1199
1195
. run ( ) ;
1200
1196
}
1201
1197
1198
+ #[ cargo_test]
1199
+ fn run_dependency_package ( ) {
1200
+ Package :: new ( "bdep" , "0.1.0" )
1201
+ . file (
1202
+ "Cargo.toml" ,
1203
+ r#"
1204
+ [package]
1205
+ name = "bdep"
1206
+ version = "0.1.0"
1207
+ authors = ["wycats@example.com"]
1208
+
1209
+ [[bin]]
1210
+ name = "bdep"
1211
+ "# ,
1212
+ )
1213
+ . file ( "src/main.rs" , "fn main() { println!(\" bdep 0.1.0\" ); }" )
1214
+ . publish ( ) ;
1215
+ Package :: new ( "bdep" , "0.1.1" )
1216
+ . file (
1217
+ "Cargo.toml" ,
1218
+ r#"
1219
+ [package]
1220
+ name = "bdep"
1221
+ version = "0.1.1"
1222
+ authors = ["wycats@example.com"]
1223
+
1224
+ [[bin]]
1225
+ name = "bdep"
1226
+ "# ,
1227
+ )
1228
+ . file ( "src/main.rs" , "fn main() { println!(\" bdep 0.1.1\" ); }" )
1229
+ . publish ( ) ;
1230
+ Package :: new ( "libdep" , "0.1.0" )
1231
+ . file (
1232
+ "Cargo.toml" ,
1233
+ r#"
1234
+ [package]
1235
+ name = "libdep"
1236
+ version = "0.1.0"
1237
+ authors = ["wycats@example.com"]
1238
+
1239
+ [lib]
1240
+ "# ,
1241
+ )
1242
+ . file ( "src/lib.rs" , "pub fn f() {}" )
1243
+ . publish ( ) ;
1244
+
1245
+ let p = project ( )
1246
+ . file (
1247
+ "Cargo.toml" ,
1248
+ r#"
1249
+ [package]
1250
+ name = "foo"
1251
+ version = "0.1.0"
1252
+ edition = "2018"
1253
+
1254
+ [build-dependencies]
1255
+ bdep = "0.1"
1256
+ libdep = "0.1"
1257
+ "# ,
1258
+ )
1259
+ . file ( "src/main.rs" , "fn main() { println!(\" foo\" ); }" )
1260
+ . build ( ) ;
1261
+
1262
+ let testcases = [
1263
+ ( "bdep" , "bdep 0.1.1" ) ,
1264
+ ( "bdep:0.1.1" , "bdep 0.1.1" ) ,
1265
+ (
1266
+ "https://github.com/rust-lang/crates.io-index#bdep" ,
1267
+ "bdep 0.1.1" ,
1268
+ ) ,
1269
+ ] ;
1270
+ for ( pkgid, expected_output) in testcases {
1271
+ p. cargo ( "run" )
1272
+ . arg ( "-p" )
1273
+ . arg ( pkgid)
1274
+ . with_stdout ( expected_output)
1275
+ . run ( ) ;
1276
+ }
1277
+
1278
+ p. cargo ( "run" )
1279
+ . arg ( "-p" )
1280
+ . arg ( "libdep" )
1281
+ . with_status ( 101 )
1282
+ . with_stderr_contains ( "[ERROR] a bin target must be available for `cargo run`" )
1283
+ . run ( ) ;
1284
+
1285
+ let invalid_pkgids = [
1286
+ "bdep:0.1.0" ,
1287
+ "https://github.com/rust-lang/crates.io-index#bdep:0.1.0" ,
1288
+ "bdep:0.2.0" ,
1289
+ "https://github.com/rust-lang/crates.io-index#bdep:0.2.0" ,
1290
+ ] ;
1291
+ for pkgid in invalid_pkgids {
1292
+ p. cargo ( "run" )
1293
+ . arg ( "-p" )
1294
+ . arg ( pkgid)
1295
+ . with_status ( 101 )
1296
+ . with_stderr_contains (
1297
+ "[ERROR] `cargo run` cannot find pkgid either in the workspace or among the workspace dependencies" ,
1298
+ )
1299
+ . run ( ) ;
1300
+ }
1301
+ }
1302
+
1202
1303
#[ cargo_test]
1203
1304
fn explicit_bin_with_args ( ) {
1204
1305
let p = project ( )
0 commit comments