Skip to content

Commit ee286bc

Browse files
author
Jon Gjengset
committed
Add tests for fixed metadata download behavior
1 parent 7367e43 commit ee286bc

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ fn build_resolve_graph(
142142
)?;
143143

144144
// Download all Packages. This is needed to serialize the information for every package.
145+
// Note that even with --filter-platform we end up downloading host dependencies as well,
146+
// as that is the behavior of download_accessible.
145147
let package_map: BTreeMap<PackageId, Package> = ws_resolve
146148
.pkg_set
147149
.download_accessible(

tests/testsuite/metadata.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tests for the `cargo metadata` command.
22
3+
use cargo_test_support::install::cargo_home;
4+
use cargo_test_support::paths::CargoPathExt;
35
use cargo_test_support::registry::Package;
46
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, main_file, project, rustc_host};
57

@@ -2343,8 +2345,27 @@ fn filter_platform() {
23432345
.replace("$ALT_TRIPLE", alt_target)
23442346
.replace("$HOST_TRIPLE", &rustc_host());
23452347

2348+
// We're going to be checking that we don't download excessively,
2349+
// so we need to ensure that downloads will happen.
2350+
let clear = || {
2351+
cargo_home().join("registry/cache").rm_rf();
2352+
cargo_home().join("registry/src").rm_rf();
2353+
p.build_dir().rm_rf();
2354+
};
2355+
23462356
// Normal metadata, no filtering, returns *everything*.
23472357
p.cargo("metadata")
2358+
.with_stderr_unordered(
2359+
"\
2360+
[UPDATING] [..]
2361+
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2362+
[DOWNLOADING] crates ...
2363+
[DOWNLOADED] normal-dep v0.0.1 [..]
2364+
[DOWNLOADED] host-dep v0.0.1 [..]
2365+
[DOWNLOADED] alt-dep v0.0.1 [..]
2366+
[DOWNLOADED] cfg-dep v0.0.1 [..]
2367+
",
2368+
)
23482369
.with_json(
23492370
&r#"
23502371
{
@@ -2454,10 +2475,20 @@ fn filter_platform() {
24542475
.replace("$FOO", &foo),
24552476
)
24562477
.run();
2478+
clear();
24572479

24582480
// Filter on alternate, removes cfg and host.
24592481
p.cargo("metadata --filter-platform")
24602482
.arg(alt_target)
2483+
.with_stderr_unordered(
2484+
"\
2485+
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2486+
[DOWNLOADING] crates ...
2487+
[DOWNLOADED] normal-dep v0.0.1 [..]
2488+
[DOWNLOADED] host-dep v0.0.1 [..]
2489+
[DOWNLOADED] alt-dep v0.0.1 [..]
2490+
",
2491+
)
24612492
.with_json(
24622493
&r#"
24632494
{
@@ -2526,10 +2557,19 @@ fn filter_platform() {
25262557
.replace("$FOO", &foo),
25272558
)
25282559
.run();
2560+
clear();
25292561

25302562
// Filter on host, removes alt and cfg.
25312563
p.cargo("metadata --filter-platform")
25322564
.arg(rustc_host())
2565+
.with_stderr_unordered(
2566+
"\
2567+
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2568+
[DOWNLOADING] crates ...
2569+
[DOWNLOADED] normal-dep v0.0.1 [..]
2570+
[DOWNLOADED] host-dep v0.0.1 [..]
2571+
",
2572+
)
25332573
.with_json(
25342574
&r#"
25352575
{
@@ -2598,11 +2638,21 @@ fn filter_platform() {
25982638
.replace("$FOO", &foo),
25992639
)
26002640
.run();
2641+
clear();
26012642

26022643
// Filter host with cfg, removes alt only
26032644
p.cargo("metadata --filter-platform")
26042645
.arg(rustc_host())
26052646
.env("RUSTFLAGS", "--cfg=foobar")
2647+
.with_stderr_unordered(
2648+
"\
2649+
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
2650+
[DOWNLOADING] crates ...
2651+
[DOWNLOADED] normal-dep v0.0.1 [..]
2652+
[DOWNLOADED] host-dep v0.0.1 [..]
2653+
[DOWNLOADED] cfg-dep v0.0.1 [..]
2654+
",
2655+
)
26062656
.with_json(
26072657
&r#"
26082658
{

0 commit comments

Comments
 (0)