Skip to content

Commit

Permalink
More tests for create command
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Dec 21, 2023
1 parent a13439f commit c52c26d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 26 deletions.
56 changes: 43 additions & 13 deletions cargo-workspaces/tests/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ fn test_create_bin_2015() {
let package_name = "mynewcrate-bin-2015";
let dir = "../fixtures/create";
let package_path = Path::new(dir).join(package_name);
let workspace_manifest_path = Path::new(dir).join("Cargo.toml");
let manifest_path = package_path.join("Cargo.toml");

let backup = read_to_string(Path::new(dir).join("Cargo.toml")).unwrap();
let backup = read_to_string(&workspace_manifest_path).unwrap();
clean_package_dir(&package_path, "bin");

let _err = utils::run_err(
Expand All @@ -86,11 +87,13 @@ fn test_create_bin_2015() {
);

let manifest = read_to_string(manifest_path).unwrap();
let workspace_manifest = read_to_string(&workspace_manifest_path).unwrap();

assert_snapshot!(&manifest);
assert_snapshot!(&workspace_manifest);

clean_package_dir(&package_path, "bin");
write(Path::new(dir).join("Cargo.toml"), backup).unwrap();
write(workspace_manifest_path, backup).unwrap();
}

/// Test creating a 2015 lib package
Expand Down Expand Up @@ -230,6 +233,42 @@ fn test_create_lib_and_bin_fails() {
clean_package_dir(&package_path, "bin");
}

#[test]
#[serial]
fn test_member_glob() {
let package_name = "dep3";
let dir = "../fixtures/create";
let package_path = Path::new(dir).join(package_name);
let workspace_manifest_path = Path::new(dir).join("Cargo.toml");
let manifest_path = package_path.join("Cargo.toml");

let backup = read_to_string(&workspace_manifest_path).unwrap();
clean_package_dir(&package_path, "lib");

let _err = utils::run_err(
dir,
&[
"ws",
"create",
package_name,
"--edition",
"2018",
"--lib",
"--name",
package_name,
],
);

let manifest = read_to_string(manifest_path).unwrap();
let workspace_manifest = read_to_string(&workspace_manifest_path).unwrap();

assert_snapshot!(&manifest);
assert_snapshot!(&workspace_manifest);

clean_package_dir(&package_path, "lib");
write(workspace_manifest_path, backup).unwrap();
}

#[test]
#[serial]
fn test_exclude_fails() {
Expand Down Expand Up @@ -266,7 +305,6 @@ fn test_exclude_fails() {
fn test_already_exists() {
let package_name = "dep1";
let dir = "../fixtures/create";
let package_path = Path::new(dir).join(package_name);

let err = utils::run_err(
dir,
Expand All @@ -283,19 +321,13 @@ fn test_already_exists() {
);

assert_snapshot!(err);

let exists = package_path.exists();
assert!(exists);
}

#[test]
#[serial]
fn test_duplicate_package_name() {
let package_name = "dep1";
let dir = "../fixtures/create";
let package_path = Path::new(dir).join("dep3");

clean_package_dir(&package_path, "lib");

let err = utils::run_err(
dir,
Expand All @@ -311,10 +343,8 @@ fn test_duplicate_package_name() {
],
);

assert_snapshot!(err);
assert!(err.contains("error: the workspace already contains a package with this name"));

let exists = package_path.exists();
let exists = Path::new(dir).join("dep3").exists();
assert!(!exists);

clean_package_dir(&package_path, "lib");
}
14 changes: 14 additions & 0 deletions cargo-workspaces/tests/snapshots/create__create_bin_2015-2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: tests/create.rs
assertion_line: 93
expression: "&workspace_manifest"
---
[workspace]
members = [
"dep*",
"mynewcrate-bin-2015",
]
exclude = [
"tmp*",
]

This file was deleted.

13 changes: 13 additions & 0 deletions cargo-workspaces/tests/snapshots/create__member_glob-2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: tests/create.rs
assertion_line: 266
expression: "&workspace_manifest"
---
[workspace]
members = [
"dep*",
]
exclude = [
"tmp*",
]

13 changes: 13 additions & 0 deletions cargo-workspaces/tests/snapshots/create__member_glob.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: tests/create.rs
assertion_line: 265
expression: "&manifest"
---
[package]
name = "dep3"
version = "0.0.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

0 comments on commit c52c26d

Please sign in to comment.