about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorrufevean <deerajmydearalways@gmail.com>2024-09-01 20:38:03 +0530
committerYacin Tmimi <yacintmimi@gmail.com>2024-09-12 10:57:14 -0400
commit14d51659603af7fa034e05eae18ad7e7a1d243e5 (patch)
treedc689b9a759d9006e7d5a99d926fb1b93edbaa19 /tests
parent16f0ecc84c12b0e31ad62355e79c131ae368f209 (diff)
downloadrust-14d51659603af7fa034e05eae18ad7e7a1d243e5.tar.gz
rust-14d51659603af7fa034e05eae18ad7e7a1d243e5.zip
refactor - show file path in error message when parsing config from toml
fixes 6302

Display the path to the toml config file that rustfmt failed to parse
configurations from.
Diffstat (limited to 'tests')
-rw-r--r--tests/config/issue-6302.toml1
-rw-r--r--tests/rustfmt/main.rs13
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/config/issue-6302.toml b/tests/config/issue-6302.toml
new file mode 100644
index 00000000000..8148b37b1f6
--- /dev/null
+++ b/tests/config/issue-6302.toml
@@ -0,0 +1 @@
+edition = 2019
diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs
index e99890acd1b..a9f58b9328e 100644
--- a/tests/rustfmt/main.rs
+++ b/tests/rustfmt/main.rs
@@ -219,3 +219,16 @@ fn rustfmt_generates_no_error_if_failed_format_code_in_doc_comments() {
     assert!(stderr.is_empty());
     assert!(stdout.is_empty());
 }
+
+#[test]
+fn rustfmt_error_improvement_regarding_invalid_toml() {
+    // See also https://github.com/rust-lang/rustfmt/issues/6302
+    let invalid_toml_config = "tests/config/issue-6302.toml";
+    let args = ["--config-path", invalid_toml_config];
+    let (_stdout, stderr) = rustfmt(&args);
+
+    let toml_path = Path::new(invalid_toml_config).canonicalize().unwrap();
+    let expected_error_message = format!("The file `{}` failed to parse", toml_path.display());
+
+    assert!(stderr.contains(&expected_error_message));
+}