Skip to content

Commit

Permalink
test for issue 3164
Browse files Browse the repository at this point in the history
Closes 3164

Show that when `error_on_line_overflow=true` is set in the rustfmt.toml
that an error message is written to stderr.
  • Loading branch information
ytmimi authored and calebcartwright committed Jul 22, 2022
1 parent 4c78c73 commit c19b145
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,22 @@ fn cargo_fmt_out_of_line_test_modules() {
assert!(stdout.contains(&format!("Diff in {}", path.display())))
}
}

#[rustfmt_only_ci_test]
#[test]
fn cargo_fmt_emits_error_on_line_overflow_true() {
// See also https://github.com/rust-lang/rustfmt/issues/3164
let args = [
"--check",
"--manifest-path",
"tests/cargo-fmt/source/issue_3164/Cargo.toml",
"--",
"--config",
"error_on_line_overflow=true",
];

let (_stdout, stderr) = cargo_fmt(&args);
assert!(stderr.contains(
"line formatted, but exceeded maximum width (maximum: 100 (see `max_width` option)"
))
}
8 changes: 8 additions & 0 deletions tests/cargo-fmt/source/issue_3164/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "issue_3164"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
13 changes: 13 additions & 0 deletions tests/cargo-fmt/source/issue_3164/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[allow(unused_macros)]
macro_rules! foo {
($id:ident) => {
macro_rules! bar {
($id2:tt) => {
#[cfg(any(target_feature = $id2, target_feature = $id2, target_feature = $id2, target_feature = $id2, target_feature = $id2))]
fn $id() {}
};
}
};
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,18 @@ fn mod_resolution_error_path_attribute_does_not_exist() {
// The path attribute points to a file that does not exist
assert!(stderr.contains("does_not_exist.rs does not exist"));
}

#[test]
fn rustfmt_emits_error_on_line_overflow_true() {
// See also https://github.com/rust-lang/rustfmt/issues/3164
let args = [
"--config",
"error_on_line_overflow=true",
"tests/cargo-fmt/source/issue_3164/src/main.rs",
];

let (_stdout, stderr) = rustfmt(&args);
assert!(stderr.contains(
"line formatted, but exceeded maximum width (maximum: 100 (see `max_width` option)"
))
}

0 comments on commit c19b145

Please sign in to comment.