Skip to content

Commit 1f4e6be

Browse files
jneemtorhovland
andcommitted
Add publish workspace tests
Co-authored-by: Tor Hovland <[email protected]>
1 parent 4110b84 commit 1f4e6be

File tree

1 file changed

+347
-1
lines changed

1 file changed

+347
-1
lines changed

tests/testsuite/publish.rs

Lines changed: 347 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::fs;
44
use std::sync::{Arc, Mutex};
55

66
use cargo_test_support::git::{self, repo};
7-
use cargo_test_support::paths;
87
use cargo_test_support::prelude::*;
98
use cargo_test_support::registry::{self, Package, RegistryBuilder, Response};
109
use cargo_test_support::{basic_manifest, project, publish, str};
10+
use cargo_test_support::{paths, Project};
1111

1212
const CLEAN_FOO_JSON: &str = r#"
1313
{
@@ -3232,6 +3232,87 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
32323232
.run();
32333233
}
32343234

3235+
#[cargo_test]
3236+
fn timeout_waiting_for_dependency_publish() {
3237+
// Publish doesn't happen within the timeout window.
3238+
let registry = registry::RegistryBuilder::new()
3239+
.http_api()
3240+
.delayed_index_update(20)
3241+
.build();
3242+
3243+
let p = project()
3244+
.file(
3245+
"Cargo.toml",
3246+
r#"
3247+
[workspace]
3248+
members = ["main", "other", "dep"]
3249+
"#,
3250+
)
3251+
.file(
3252+
"main/Cargo.toml",
3253+
r#"
3254+
[package]
3255+
name = "main"
3256+
version = "0.0.1"
3257+
edition = "2015"
3258+
authors = []
3259+
license = "MIT"
3260+
description = "foo"
3261+
3262+
[dependencies]
3263+
dep = { version = "0.0.1", path = "../dep" }
3264+
"#,
3265+
)
3266+
.file("main/src/main.rs", "fn main() {}")
3267+
.file(
3268+
"other/Cargo.toml",
3269+
r#"
3270+
[package]
3271+
name = "other"
3272+
version = "0.0.1"
3273+
edition = "2015"
3274+
authors = []
3275+
license = "MIT"
3276+
description = "foo"
3277+
3278+
[dependencies]
3279+
dep = { version = "0.0.1", path = "../dep" }
3280+
"#,
3281+
)
3282+
.file("other/src/main.rs", "fn main() {}")
3283+
.file(
3284+
"dep/Cargo.toml",
3285+
r#"
3286+
[package]
3287+
name = "dep"
3288+
version = "0.0.1"
3289+
edition = "2015"
3290+
authors = []
3291+
license = "MIT"
3292+
description = "foo"
3293+
"#,
3294+
)
3295+
.file("dep/src/lib.rs", "")
3296+
.file(
3297+
".cargo/config.toml",
3298+
r#"
3299+
[publish]
3300+
timeout = 2
3301+
"#,
3302+
)
3303+
.build();
3304+
3305+
p.cargo("publish --no-verify -Zpublish-timeout -Zpackage-workspace")
3306+
.replace_crates_io(registry.index_url())
3307+
.masquerade_as_nightly_cargo(&["publish-timeout", "package-workspace"])
3308+
.with_status(101)
3309+
.with_stderr_data(str![[r#"
3310+
[ERROR] the `-p` argument must be specified to select a single package to publish
3311+
3312+
"#]])
3313+
.run();
3314+
}
3315+
32353316
#[cargo_test]
32363317
fn wait_for_git_publish() {
32373318
// Slow publish to an index with a git index.
@@ -3417,3 +3498,268 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
34173498

34183499
validate_upload_foo();
34193500
}
3501+
3502+
// A workspace with three projects that depend on one another (level1 -> level2 -> level3).
3503+
// level1 is a binary package, to test lockfile generation.
3504+
fn workspace_with_local_deps_project() -> Project {
3505+
project()
3506+
.file(
3507+
"Cargo.toml",
3508+
r#"
3509+
[workspace]
3510+
members = ["level1", "level2", "level3"]
3511+
3512+
[workspace.dependencies]
3513+
level2 = { path = "level2", version = "0.0.1" }
3514+
"#
3515+
)
3516+
.file(
3517+
"level1/Cargo.toml",
3518+
r#"
3519+
[package]
3520+
name = "level1"
3521+
version = "0.0.1"
3522+
edition = "2015"
3523+
authors = []
3524+
license = "MIT"
3525+
description = "level1"
3526+
repository = "bar"
3527+
3528+
[dependencies]
3529+
# Let one dependency also specify features, for the added test coverage when generating package files.
3530+
level2 = { workspace = true, features = ["foo"] }
3531+
"#,
3532+
)
3533+
.file("level1/src/main.rs", "fn main() {}")
3534+
.file(
3535+
"level2/Cargo.toml",
3536+
r#"
3537+
[package]
3538+
name = "level2"
3539+
version = "0.0.1"
3540+
edition = "2015"
3541+
authors = []
3542+
license = "MIT"
3543+
description = "level2"
3544+
repository = "bar"
3545+
3546+
[features]
3547+
foo = []
3548+
3549+
[dependencies]
3550+
level3 = { path = "../level3", version = "0.0.1" }
3551+
"#
3552+
)
3553+
.file("level2/src/lib.rs", "")
3554+
.file(
3555+
"level3/Cargo.toml",
3556+
r#"
3557+
[package]
3558+
name = "level3"
3559+
version = "0.0.1"
3560+
edition = "2015"
3561+
authors = []
3562+
license = "MIT"
3563+
description = "level3"
3564+
repository = "bar"
3565+
"#,
3566+
)
3567+
.file("level3/src/lib.rs", "")
3568+
.build()
3569+
}
3570+
3571+
#[cargo_test]
3572+
fn workspace_with_local_deps() {
3573+
let crates_io = registry::init();
3574+
let p = workspace_with_local_deps_project();
3575+
3576+
p.cargo("publish")
3577+
.replace_crates_io(crates_io.index_url())
3578+
.with_status(101)
3579+
.with_stderr_data(str![[r#"
3580+
[ERROR] the `-p` argument must be specified to select a single package to publish
3581+
3582+
"#]])
3583+
.run();
3584+
}
3585+
3586+
#[cargo_test]
3587+
fn workspace_with_local_deps_nightly() {
3588+
let registry = RegistryBuilder::new().http_api().http_index().build();
3589+
let p = workspace_with_local_deps_project();
3590+
3591+
p.cargo("publish -Zpackage-workspace")
3592+
.masquerade_as_nightly_cargo(&["package-workspace"])
3593+
.with_status(101)
3594+
.replace_crates_io(registry.index_url())
3595+
.with_stderr_data(str![[r#"
3596+
[ERROR] the `-p` argument must be specified to select a single package to publish
3597+
3598+
"#]])
3599+
.run();
3600+
}
3601+
3602+
#[cargo_test]
3603+
fn workspace_parallel() {
3604+
let registry = RegistryBuilder::new().http_api().http_index().build();
3605+
let p = project()
3606+
.file(
3607+
"Cargo.toml",
3608+
r#"
3609+
[workspace]
3610+
members = ["a", "b", "c"]
3611+
"#,
3612+
)
3613+
.file(
3614+
"a/Cargo.toml",
3615+
r#"
3616+
[package]
3617+
name = "a"
3618+
version = "0.0.1"
3619+
edition = "2015"
3620+
authors = []
3621+
license = "MIT"
3622+
description = "a"
3623+
repository = "bar"
3624+
"#,
3625+
)
3626+
.file("a/src/lib.rs", "")
3627+
.file(
3628+
"b/Cargo.toml",
3629+
r#"
3630+
[package]
3631+
name = "b"
3632+
version = "0.0.1"
3633+
edition = "2015"
3634+
authors = []
3635+
license = "MIT"
3636+
description = "b"
3637+
repository = "bar"
3638+
"#,
3639+
)
3640+
.file("b/src/lib.rs", "")
3641+
.file(
3642+
"c/Cargo.toml",
3643+
r#"
3644+
[package]
3645+
name = "c"
3646+
version = "0.0.1"
3647+
edition = "2015"
3648+
authors = []
3649+
license = "MIT"
3650+
description = "c"
3651+
repository = "bar"
3652+
3653+
[dependencies]
3654+
a = { path = "../a", version = "0.0.1" }
3655+
b = { path = "../b", version = "0.0.1" }
3656+
"#,
3657+
)
3658+
.file("c/src/lib.rs", "")
3659+
.build();
3660+
3661+
p.cargo("publish -Zpackage-workspace")
3662+
.masquerade_as_nightly_cargo(&["package-workspace"])
3663+
.replace_crates_io(registry.index_url())
3664+
.with_status(101)
3665+
.with_stderr_data(
3666+
str![[r#"
3667+
[ERROR] the `-p` argument must be specified to select a single package to publish
3668+
3669+
"#]]
3670+
.unordered(),
3671+
)
3672+
.run();
3673+
}
3674+
3675+
#[cargo_test]
3676+
fn workspace_missing_dependency() {
3677+
let registry = RegistryBuilder::new().http_api().http_index().build();
3678+
let p = project()
3679+
.file(
3680+
"Cargo.toml",
3681+
r#"
3682+
[workspace]
3683+
members = ["a", "b"]
3684+
"#,
3685+
)
3686+
.file(
3687+
"a/Cargo.toml",
3688+
r#"
3689+
[package]
3690+
name = "a"
3691+
version = "0.0.1"
3692+
edition = "2015"
3693+
authors = []
3694+
license = "MIT"
3695+
description = "a"
3696+
repository = "bar"
3697+
"#,
3698+
)
3699+
.file("a/src/lib.rs", "")
3700+
.file(
3701+
"b/Cargo.toml",
3702+
r#"
3703+
[package]
3704+
name = "b"
3705+
version = "0.0.1"
3706+
edition = "2015"
3707+
authors = []
3708+
license = "MIT"
3709+
description = "b"
3710+
repository = "bar"
3711+
3712+
[dependencies]
3713+
a = { path = "../a", version = "0.0.1" }
3714+
"#,
3715+
)
3716+
.file("b/src/lib.rs", "")
3717+
.build();
3718+
3719+
p.cargo("publish -Zpackage-workspace -p b")
3720+
.masquerade_as_nightly_cargo(&["package-workspace"])
3721+
.replace_crates_io(registry.index_url())
3722+
.with_status(101)
3723+
.with_stderr_data(str![[r#"
3724+
[UPDATING] crates.io index
3725+
[PACKAGING] b v0.0.1 ([ROOT]/foo/b)
3726+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3727+
[VERIFYING] b v0.0.1 ([ROOT]/foo/b)
3728+
[UPDATING] crates.io index
3729+
[ERROR] no matching package named `a` found
3730+
location searched: registry `crates-io`
3731+
required by package `b v0.0.1 ([ROOT]/foo/target/package/b-0.0.1)`
3732+
3733+
"#]])
3734+
.run();
3735+
3736+
p.cargo("publish -Zpackage-workspace -p a")
3737+
.masquerade_as_nightly_cargo(&["package-workspace"])
3738+
.replace_crates_io(registry.index_url())
3739+
.with_stderr_data(str![[r#"
3740+
[UPDATING] crates.io index
3741+
[PACKAGING] a v0.0.1 ([ROOT]/foo/a)
3742+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3743+
[VERIFYING] a v0.0.1 ([ROOT]/foo/a)
3744+
[COMPILING] a v0.0.1 ([ROOT]/foo/target/package/a-0.0.1)
3745+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3746+
[UPLOADING] a v0.0.1 ([ROOT]/foo/a)
3747+
[UPLOADED] a v0.0.1 to registry `crates-io`
3748+
[NOTE] waiting for `a v0.0.1` to be available at registry `crates-io`.
3749+
You may press ctrl-c to skip waiting; the crate should be available shortly.
3750+
[PUBLISHED] a v0.0.1 at registry `crates-io`
3751+
3752+
"#]])
3753+
.run();
3754+
3755+
// Publishing the whole workspace now will fail, as `a` is already published.
3756+
p.cargo("publish -Zpackage-workspace")
3757+
.masquerade_as_nightly_cargo(&["package-workspace"])
3758+
.replace_crates_io(registry.index_url())
3759+
.with_status(101)
3760+
.with_stderr_data(str![[r#"
3761+
[ERROR] the `-p` argument must be specified to select a single package to publish
3762+
3763+
"#]])
3764+
.run();
3765+
}

0 commit comments

Comments
 (0)