Skip to content

Commit

Permalink
test: Demonstrate existing empty name errors
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 13, 2023
1 parent 8412d30 commit d415790
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,3 +1546,79 @@ or use environment variable CARGO_REGISTRY_TOKEN",
)
.run();
}

#[cargo_test]
fn config_empty_registry_name() {
let _ = RegistryBuilder::new()
.no_configure_token()
.alternative()
.build();
let p = project()
.file("src/lib.rs", "")
.file(
".cargo/config.toml",
"[registry.'']
",
)
.build();

p.cargo("publish")
.arg("--registry")
.arg("")
.with_status(101)
.with_stderr(
"\
[ERROR] registry index was not found in any configuration: ``",
)
.run();
}

#[cargo_test]
fn empty_registry_flag() {
let p = project().file("src/lib.rs", "").build();

p.cargo("publish")
.arg("--registry")
.arg("")
.with_status(101)
.with_stderr(
"\
[ERROR] registry index was not found in any configuration: ``",
)
.run();
}

#[cargo_test]
fn empty_dependency_registry() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[dependencies]
bar = { version = "0.1.0", registry = "" }
"#,
)
.file(
"src/lib.rs",
"
extern crate bar;
pub fn f() { bar::bar(); }
",
)
.build();

p.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
registry index was not found in any configuration: ``",
)
.run();
}
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/empty_dep_name/in
24 changes: 24 additions & 0 deletions tests/testsuite/cargo_add/empty_dep_name/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::prelude::*;
use cargo_test_support::Project;

use cargo_test_support::curr_dir;

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

snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("@1.2.3")
.current_dir(cwd)
.assert()
.failure()
.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);
}
5 changes: 5 additions & 0 deletions tests/testsuite/cargo_add/empty_dep_name/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
3 changes: 3 additions & 0 deletions tests/testsuite/cargo_add/empty_dep_name/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
thread 'main' panicked at src/cargo/core/dependency.rs:164:9:
assertion failed: !name.is_empty()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Empty file.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod dev;
mod dev_build_conflict;
mod dev_prefer_existing_version;
mod dry_run;
mod empty_dep_name;
mod empty_dep_table;
mod features;
mod features_activated_over_limit;
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions tests/testsuite/cargo_new/empty_name/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::curr_dir;
use cargo_test_support::CargoCommand;
use cargo_test_support::Project;

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

snapbox::cmd::Command::cargo_ui()
.arg("new")
.args(["foo", "--name", ""])
.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);
}
7 changes: 7 additions & 0 deletions tests/testsuite/cargo_new/empty_name/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
warning: compiling this new package may not work due to invalid workspace configuration

failed to parse manifest at `[ROOT]/case/foo/Cargo.toml`

Caused by:
package name cannot be an empty string
Created binary (application) `` package
Empty file.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod add_members_to_workspace_with_absolute_package_path;
mod add_members_to_workspace_with_empty_members;
mod add_members_to_workspace_with_exclude_list;
mod add_members_to_workspace_with_members_glob;
mod empty_name;
mod help;
mod inherit_workspace_lints;
mod inherit_workspace_package_table;
Expand Down
83 changes: 83 additions & 0 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2700,3 +2700,86 @@ perhaps a crate was updated and forgotten to be re-vendored?"#,
)
.run();
}

#[cargo_test]
fn from_config_empty() {
Package::new("bar", "0.1.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
bar = "0.1.0"
"#,
)
.file(
".cargo/config.toml",
r#"
[patch.'']
bar = { path = 'bar' }
"#,
)
.file("src/lib.rs", "")
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
.file("bar/src/lib.rs", r#""#)
.build();

p.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] [patch] entry `` should be a URL or registry name
Caused by:
invalid url ``: relative URL without a base
",
)
.run();
}

#[cargo_test]
fn from_manifest_empty() {
Package::new("bar", "0.1.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
bar = "0.1.0"
[patch.'']
bar = { path = 'bar' }
"#,
)
.file("src/lib.rs", "")
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.1"))
.file("bar/src/lib.rs", r#""#)
.build();

p.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
[patch] entry `` should be a URL or registry name
Caused by:
invalid url ``: relative URL without a base
",
)
.run();
}

0 comments on commit d415790

Please sign in to comment.