Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(upgrade): Switch to cargo-test-support' #754

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
toolchain: [stable, beta, nightly]
Expand Down
158 changes: 154 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ predicates = { version = "2.0.3", features = ["color-auto"] }
assert_cmd = { version = "2.0.2", features = ["color-auto"] }
assert_fs = { version = "1.0.6", features = ["color-auto"] }
trycmd = "0.13.1"
snapbox = { version = "0.2.10", features = ["cmd", "path"] }
cargo-test-macro.git = "https://github.com/rust-lang/cargo"
cargo-test-support.git = "https://github.com/rust-lang/cargo"
url = "2.2.2"

[features]
default = [
Expand Down
4 changes: 2 additions & 2 deletions src/bin/upgrade/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
deprecated_message("The flag `--all` has been deprecated in favor of `--workspace`")?;
}

if !args.offline && !args.to_lockfile && std::env::var("CARGO_IS_TEST").is_err() {
if !args.offline && !args.to_lockfile {
let url = registry_url(&find(args.manifest_path.as_deref())?, None)?;
update_registry_index(&url, false)?;
}
Expand Down Expand Up @@ -281,7 +281,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
.registry()
.map(|registry| registry_url(&manifest_path, Some(registry)))
.transpose()?;
if !args.offline && std::env::var("CARGO_IS_TEST").is_err() {
if !args.offline {
if let Some(registry_url) = &registry_url {
if updated_registries.insert(registry_url.to_owned()) {
update_registry_index(registry_url, false)?;
Expand Down
4 changes: 0 additions & 4 deletions tests/cargo-upgrade.rs

This file was deleted.

13 changes: 13 additions & 0 deletions tests/cargo-upgrade/alt_registry/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "none"
version = "0.0.0"

[lib]
path = "dummy.rs"

[dependencies]
my-package1 = {version = "0.1.1", registry = "alternative" }

[dependencies.my-package2]
version = "0.2"
registry = "alternative"
Empty file.
24 changes: 24 additions & 0 deletions tests/cargo-upgrade/alt_registry/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::Project;

use crate::init_alt_registry;
use crate::CargoCommand;
use cargo_test_support::curr_dir;

#[cargo_test]
fn case() {
init_alt_registry();
let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("upgrade")
.current_dir(cwd)
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
13 changes: 13 additions & 0 deletions tests/cargo-upgrade/alt_registry/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "none"
version = "0.0.0"

[lib]
path = "dummy.rs"

[dependencies]
my-package1 = {version = "99999.0.0", registry = "alternative" }

[dependencies.my-package2]
version = "99999.0"
registry = "alternative"
Empty file.
5 changes: 5 additions & 0 deletions tests/cargo-upgrade/alt_registry/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Updating '[ROOTURL]/registry' index
Checking none's dependencies
Updating '[ROOTURL]/alternative-registry' index
Upgrading my-package1: v0.1.1 -> v99999.0.0
Upgrading my-package2: v0.2 -> v99999.0
Empty file.
6 changes: 6 additions & 0 deletions tests/cargo-upgrade/dry_run/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "cargo-list-test-fixture"
version = "0.0.0"

[dependencies]
my-package = "0.1.1"
Empty file.
25 changes: 25 additions & 0 deletions tests/cargo-upgrade/dry_run/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::Project;

use crate::init_registry;
use crate::CargoCommand;
use cargo_test_support::curr_dir;

#[cargo_test]
fn case() {
init_registry();
let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("upgrade")
.args(["--dry-run"])
.current_dir(cwd)
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
Loading