Skip to content

Commit

Permalink
ensure parse errors aren't emitted when formatting doc comments (#6232)
Browse files Browse the repository at this point in the history
This adds a test case to validate behavior when using
`format_code_in_doc_comments=true`
  • Loading branch information
giordan12 authored Jul 8, 2024
1 parent eed7e23 commit c8290a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs::remove_file;
use std::path::Path;
use std::process::Command;

use rustfmt_config_proc_macro::rustfmt_only_ci_test;
use rustfmt_config_proc_macro::{nightly_only_test, rustfmt_only_ci_test};

/// Run the rustfmt executable and return its output.
fn rustfmt(args: &[&str]) -> (String, String) {
Expand Down Expand Up @@ -207,3 +207,15 @@ fn rustfmt_emits_error_when_control_brace_style_is_always_next_line() {
let (_stdout, stderr) = rustfmt(&args);
assert!(!stderr.contains("error[internal]: left behind trailing whitespace"))
}

#[nightly_only_test]
#[test]
fn rustfmt_generates_no_error_if_failed_format_code_in_doc_comments() {
// See also https://github.com/rust-lang/rustfmt/issues/6109

let file = "tests/target/issue-6109.rs";
let args = ["--config", "format_code_in_doc_comments=true", file];
let (stdout, stderr) = rustfmt(&args);
assert!(stderr.is_empty());
assert!(stdout.is_empty());
}
7 changes: 7 additions & 0 deletions tests/target/issue-6109.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Some doc comment with code snippet:
///```
/// '\u{1F}
/// ```
pub struct Code {}

fn main() {}

0 comments on commit c8290a5

Please sign in to comment.