Skip to content

Commit 7cb2548

Browse files
committed
Add a cargo-fmt test case for issue 6517
The test case loads package targets from the root of a workspace.
1 parent 13b9b5f commit 7cb2548

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

src/cargo-fmt/test/targets.rs

+28
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,32 @@ mod all_targets {
134134
assert_correct_targets_loaded("ws/a/d/f/Cargo.toml");
135135
}
136136
}
137+
138+
mod cargo_fmt_strategy_root {
139+
use super::*;
140+
141+
#[test]
142+
fn assert_correct_targets_loaded_from_root() {
143+
let exp_targets = &[
144+
ExpTarget {
145+
path: "inner_bin/src/main.rs",
146+
edition: Edition::E2021,
147+
kind: "bin",
148+
},
149+
ExpTarget {
150+
path: "inner_lib/src/lib.rs",
151+
edition: Edition::E2021,
152+
kind: "lib",
153+
},
154+
];
155+
156+
super::assert_correct_targets_loaded(
157+
"Cargo.toml",
158+
"issues_6517",
159+
exp_targets,
160+
2,
161+
CargoFmtStrategy::Root,
162+
);
163+
}
164+
}
137165
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[workspace]
2+
members = ["inner_bin", "inner_lib"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "inner_bin"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "inner_lib"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: u64, right: u64) -> u64 {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

0 commit comments

Comments
 (0)