From 1717205d032ecec3aa0627a952ea0303f4c1ab0d Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 4 May 2023 09:39:22 +0800 Subject: [PATCH] Add a inherit test for init Signed-off-by: hi-rustin --- .../in/Cargo.toml | 21 ++++++++++++++++++ .../in/README.md | 0 .../in/crates/foo/src/main.rs | 3 +++ .../in/src/lib.rs | 14 ++++++++++++ .../inherit_workspace_package_table/mod.rs | 22 +++++++++++++++++++ .../out/Cargo.toml | 21 ++++++++++++++++++ .../out/crates/foo/Cargo.toml | 21 ++++++++++++++++++ .../out/crates/foo/src/main.rs | 3 +++ .../out/src/lib.rs | 14 ++++++++++++ .../stderr.log | 1 + .../stdout.log | 0 tests/testsuite/init/mod.rs | 1 + 12 files changed, 121 insertions(+) create mode 100644 tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml create mode 100644 tests/testsuite/init/inherit_workspace_package_table/in/README.md create mode 100644 tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs create mode 100644 tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs create mode 100644 tests/testsuite/init/inherit_workspace_package_table/mod.rs create mode 100644 tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml create mode 100644 tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml create mode 100644 tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs create mode 100644 tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs create mode 100644 tests/testsuite/init/inherit_workspace_package_table/stderr.log create mode 100644 tests/testsuite/init/inherit_workspace_package_table/stdout.log diff --git a/tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml b/tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml new file mode 100644 index 000000000000..b7a2e90363de --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml @@ -0,0 +1,21 @@ +[workspace] +members = [ + "crates/*", +] + +[workspace.package] +authors = ["Rustaceans"] +description = "foo" +edition = "2018" +homepage = "foo" +keywords = ["foo", "bar"] +readme = "README.md" +rust-version = "1.67.0" +categories = ["algorithms"] +documentation = "foo" +exclude = ["foo"] +include = ["foo"] +license = "MIT OR Apache-2.0" +publish = false +repository = "foo" +version = "1.2.3" diff --git a/tests/testsuite/init/inherit_workspace_package_table/in/README.md b/tests/testsuite/init/inherit_workspace_package_table/in/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs b/tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs new file mode 100644 index 000000000000..43f0dac5e4ad --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Check that our file is not overwritten") +} diff --git a/tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs b/tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs new file mode 100644 index 000000000000..7d12d9af8195 --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/tests/testsuite/init/inherit_workspace_package_table/mod.rs b/tests/testsuite/init/inherit_workspace_package_table/mod.rs new file mode 100644 index 000000000000..4e1dda845cb7 --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/mod.rs @@ -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("init") + .args(["crates/foo"]) + .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); +} diff --git a/tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml b/tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml new file mode 100644 index 000000000000..b7a2e90363de --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml @@ -0,0 +1,21 @@ +[workspace] +members = [ + "crates/*", +] + +[workspace.package] +authors = ["Rustaceans"] +description = "foo" +edition = "2018" +homepage = "foo" +keywords = ["foo", "bar"] +readme = "README.md" +rust-version = "1.67.0" +categories = ["algorithms"] +documentation = "foo" +exclude = ["foo"] +include = ["foo"] +license = "MIT OR Apache-2.0" +publish = false +repository = "foo" +version = "1.2.3" diff --git a/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml b/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml new file mode 100644 index 000000000000..81996cb578e1 --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "foo" +edition.workspace = true +version.workspace = true +publish.workspace = true +authors.workspace = true +description.workspace = true +homepage.workspace = true +keywords.workspace = true +readme.workspace = true +rust-version.workspace = true +categories.workspace = true +documentation.workspace = true +exclude.workspace = true +include.workspace = true +license.workspace = true +repository.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs b/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs new file mode 100644 index 000000000000..43f0dac5e4ad --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Check that our file is not overwritten") +} diff --git a/tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs b/tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs new file mode 100644 index 000000000000..7d12d9af8195 --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/tests/testsuite/init/inherit_workspace_package_table/stderr.log b/tests/testsuite/init/inherit_workspace_package_table/stderr.log new file mode 100644 index 000000000000..3847e4e4a260 --- /dev/null +++ b/tests/testsuite/init/inherit_workspace_package_table/stderr.log @@ -0,0 +1 @@ + Created binary (application) package diff --git a/tests/testsuite/init/inherit_workspace_package_table/stdout.log b/tests/testsuite/init/inherit_workspace_package_table/stdout.log new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/testsuite/init/mod.rs b/tests/testsuite/init/mod.rs index 99df9d39d581..7853a1a0b654 100644 --- a/tests/testsuite/init/mod.rs +++ b/tests/testsuite/init/mod.rs @@ -21,6 +21,7 @@ mod git_ignore_exists_no_conflicting_entries; mod ignores_failure_to_format_source; mod inferred_bin_with_git; mod inferred_lib_with_git; +mod inherit_workspace_package_table; mod invalid_dir_name; mod lib_already_exists_nosrc; mod lib_already_exists_src;