test(new): Verify ../path behavior with workspaces

This commit is contained in:
Ed Page 2024-09-06 09:30:53 -05:00
parent d0cb869167
commit c015a0061a
9 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,8 @@
[workspace]
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1 @@
fn main() {}

View File

@ -0,0 +1,25 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::CargoCommandExt;
use cargo_test_support::Project;
#[cargo_test]
fn case() {
let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root.join("workspace");
snapbox::cmd::Command::cargo_ui()
.arg("new")
.args(["../out-of-workspace", "--lib"])
.current_dir(cwd)
.assert()
.success()
.stdout_eq(str![""])
.stderr_eq(file!["stderr.term.svg"]);
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}

View File

@ -0,0 +1,6 @@
[package]
name = "out-of-workspace"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View File

@ -0,0 +1,9 @@
[workspace]
members = ["../out-of-workspace"]
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,39 @@
<svg width="1902px" height="146px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
.fg-cyan { fill: #00AAAA }
.fg-green { fill: #00AA00 }
.fg-yellow { fill: #AA5500 }
.container {
padding: 0 10px;
line-height: 18px;
}
.bold { font-weight: bold; }
tspan {
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
white-space: pre;
line-height: 18px;
}
</style>
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Creating</tspan><tspan> library `out-of-workspace` package</tspan>
</tspan>
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Adding</tspan><tspan> `out-of-workspace` as member of workspace at `[ROOT]/case/workspace`</tspan>
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-yellow bold">warning</tspan><tspan class="bold">:</tspan><tspan> compiling this new package may not work due to invalid workspace configuration</tspan>
</tspan>
<tspan x="10px" y="82px">
</tspan>
<tspan x="10px" y="100px"><tspan>workspace member `[ROOT]/case/out-of-workspace/Cargo.toml` is not hierarchically below the workspace root `[ROOT]/case/workspace/Cargo.toml`</tspan>
</tspan>
<tspan x="10px" y="118px"><tspan class="fg-cyan bold">note</tspan><tspan class="bold">:</tspan><tspan> see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html</tspan>
</tspan>
<tspan x="10px" y="136px">
</tspan>
</text>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -8,6 +8,7 @@ mod add_members_to_workspace_with_members_glob;
mod add_members_to_workspace_without_members;
mod empty_name;
mod help;
mod ignore_current_dir_workspace;
mod inherit_workspace_lints;
mod inherit_workspace_package_table;
mod inherit_workspace_package_table_with_edition;