Skip to content

Commit c19b145

Browse files
ytmimicalebcartwright
authored andcommitted
test for issue 3164
Closes 3164 Show that when `error_on_line_overflow=true` is set in the rustfmt.toml that an error message is written to stderr.
1 parent 4c78c73 commit c19b145

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

Diff for: tests/cargo-fmt/main.rs

+19
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,22 @@ fn cargo_fmt_out_of_line_test_modules() {
9898
assert!(stdout.contains(&format!("Diff in {}", path.display())))
9999
}
100100
}
101+
102+
#[rustfmt_only_ci_test]
103+
#[test]
104+
fn cargo_fmt_emits_error_on_line_overflow_true() {
105+
// See also https://github.com/rust-lang/rustfmt/issues/3164
106+
let args = [
107+
"--check",
108+
"--manifest-path",
109+
"tests/cargo-fmt/source/issue_3164/Cargo.toml",
110+
"--",
111+
"--config",
112+
"error_on_line_overflow=true",
113+
];
114+
115+
let (_stdout, stderr) = cargo_fmt(&args);
116+
assert!(stderr.contains(
117+
"line formatted, but exceeded maximum width (maximum: 100 (see `max_width` option)"
118+
))
119+
}

Diff for: tests/cargo-fmt/source/issue_3164/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "issue_3164"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

Diff for: tests/cargo-fmt/source/issue_3164/src/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[allow(unused_macros)]
2+
macro_rules! foo {
3+
($id:ident) => {
4+
macro_rules! bar {
5+
($id2:tt) => {
6+
#[cfg(any(target_feature = $id2, target_feature = $id2, target_feature = $id2, target_feature = $id2, target_feature = $id2))]
7+
fn $id() {}
8+
};
9+
}
10+
};
11+
}
12+
13+
fn main() {}

Diff for: tests/rustfmt/main.rs

+15
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,18 @@ fn mod_resolution_error_path_attribute_does_not_exist() {
159159
// The path attribute points to a file that does not exist
160160
assert!(stderr.contains("does_not_exist.rs does not exist"));
161161
}
162+
163+
#[test]
164+
fn rustfmt_emits_error_on_line_overflow_true() {
165+
// See also https://github.com/rust-lang/rustfmt/issues/3164
166+
let args = [
167+
"--config",
168+
"error_on_line_overflow=true",
169+
"tests/cargo-fmt/source/issue_3164/src/main.rs",
170+
];
171+
172+
let (_stdout, stderr) = rustfmt(&args);
173+
assert!(stderr.contains(
174+
"line formatted, but exceeded maximum width (maximum: 100 (see `max_width` option)"
175+
))
176+
}

0 commit comments

Comments
 (0)