about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorYacin Tmimi <yacintmimi@gmail.com>2022-07-20 09:15:51 -0400
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2022-07-22 17:57:07 -0500
commitc19b14539b79d44f5f433ac189d70e07fb152354 (patch)
treeabee23c6eaefa2a98608e7e06eeae6bc537753db /tests
parent4c78c738ba45c4ac4bab3bb74009712e00d307c7 (diff)
downloadrust-c19b14539b79d44f5f433ac189d70e07fb152354.tar.gz
rust-c19b14539b79d44f5f433ac189d70e07fb152354.zip
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/cargo-fmt/main.rs19
-rw-r--r--tests/cargo-fmt/source/issue_3164/Cargo.toml8
-rw-r--r--tests/cargo-fmt/source/issue_3164/src/main.rs13
-rw-r--r--tests/rustfmt/main.rs15
4 files changed, 55 insertions, 0 deletions
diff --git a/tests/cargo-fmt/main.rs b/tests/cargo-fmt/main.rs
index 5aa4388518b..701c36fadea 100644
--- a/tests/cargo-fmt/main.rs
+++ b/tests/cargo-fmt/main.rs
@@ -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)"
+    ))
+}
diff --git a/tests/cargo-fmt/source/issue_3164/Cargo.toml b/tests/cargo-fmt/source/issue_3164/Cargo.toml
new file mode 100644
index 00000000000..580ef7e6e24
--- /dev/null
+++ b/tests/cargo-fmt/source/issue_3164/Cargo.toml
@@ -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]
diff --git a/tests/cargo-fmt/source/issue_3164/src/main.rs b/tests/cargo-fmt/source/issue_3164/src/main.rs
new file mode 100644
index 00000000000..9330107ac8d
--- /dev/null
+++ b/tests/cargo-fmt/source/issue_3164/src/main.rs
@@ -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() {}
diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs
index 636e3053e0f..7ff301e8019 100644
--- a/tests/rustfmt/main.rs
+++ b/tests/rustfmt/main.rs
@@ -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)"
+    ))
+}