Skip to content

Commit

Permalink
Add a inherit test for init
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed May 23, 2023
1 parent 0928af4 commit 72205b8
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Check that our file is not overwritten")
}
14 changes: 14 additions & 0 deletions tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
22 changes: 22 additions & 0 deletions tests/testsuite/init/inherit_workspace_package_table/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("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);
}
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Check that our file is not overwritten")
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Created binary (application) package
Empty file.
1 change: 1 addition & 0 deletions tests/testsuite/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 72205b8

Please sign in to comment.