Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuang committed Mar 9, 2025
1 parent 55b004e commit 466b9df
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 46 deletions.
10 changes: 0 additions & 10 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,6 @@ impl<'a> FormatLines<'a> {
}
self.line_len -= 1;
}

// Check for any line width errors we couldn't correct.
let error_kind = ErrorKind::LineOverflow(self.line_len, self.config.max_width());
if self.line_len > self.config.max_width()
&& !self.is_skipped_line()
&& self.should_report_error(kind, &error_kind)
{
let is_string = self.current_line_contains_string_literal;
self.push_err(error_kind, kind.is_comment(), is_string);
}
}

self.line_len = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ fn format_lines_errors_are_reported() {
config.set().error_on_line_overflow(true);
let mut session = Session::<io::Stdout>::new(config, None);
session.format(input).unwrap();
assert!(session.has_formatting_errors());
// TODO: long lines are allowed
// assert!(session.has_formatting_errors());
}

#[test]
Expand All @@ -640,7 +641,7 @@ fn format_lines_errors_are_reported_with_tabs() {
config.set().hard_tabs(true);
let mut session = Session::<io::Stdout>::new(config, None);
session.format(input).unwrap();
assert!(session.has_formatting_errors());
// assert!(session.has_formatting_errors());
}

// For each file, run rustfmt and collect the output.
Expand Down
6 changes: 3 additions & 3 deletions tests/rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ fn rustfmt_emits_error_on_line_overflow_true() {
];

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

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/target/issue-2977/block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro_rules! atomic_bits {
($ldrex:expr) => {
execute(|| {
asm!($ldrex
asm!($ldrex
: "=r"(raw)
: "r"(address)
:
Expand Down
16 changes: 9 additions & 7 deletions tests/target/issue-2977/item.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
macro_rules! atomic_bits {
($ldrex:expr) => {
some_macro!(pub fn foo() {
asm!($ldrex
: "=r"(raw)
: "r"(address)
:
: "volatile");
})
some_macro!(
pub fn foo() {
asm!($ldrex
: "=r"(raw)
: "r"(address)
:
: "volatile");
}
)
};
}
35 changes: 17 additions & 18 deletions tests/target/let_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ fn unbreakable_initializer_expr_pre_formatting_let_else_length_near_max_width()
// The length of `(indent)let pat = init else block;` is 100 (max_width)
// Post Formatting:
// The formatting is left unchanged!
let Some(x) = some_really_really_really_really_really_really_really_long_name_A else { return };
let Some(x) = some_really_really_really_really_really_really_really_long_name_A else {
return;
};

// Pre Formatting:
// The length of `(indent)let pat = init else block;` is 100 (max_width)
Expand Down Expand Up @@ -197,7 +199,9 @@ fn unbreakable_initializer_expr_pre_formatting_length_through_initializer_expr_n
// the `(indent)init` line has a length of 100 which == max_width of 100.
// One might expect formatting to succeed, but I suspect the reason we hit max_width issues is
// because the Shape is accounting for the `;` at the end of the `let-else` statement.
let Some(x) = some_really_really_really_really_really_really_really_really_really_really_really_long_nameJ else {return};
let Some(x) = some_really_really_really_really_really_really_really_really_really_really_really_long_nameJ else {
return;
};
}

fn long_patterns() {
Expand All @@ -211,7 +215,13 @@ fn long_patterns() {
};

// with version=One we don't wrap long array patterns
let [aaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, cccccccccccccccccc, dddddddddddddddddd] = opt else {
let [
aaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbb,
cccccccccccccccccc,
dddddddddddddddddd,
] = opt
else {
return;
};

Expand Down Expand Up @@ -255,31 +265,20 @@ fn with_trailing_try_operator() {

fn issue5901() {
#[cfg(target_os = "linux")]
let Some(x) = foo
else {
todo!()
};
let Some(x) = foo else { todo!() };

#[cfg(target_os = "linux")]
// Some comments between attributes and let-else statement
let Some(x) = foo
else {
todo!()
};
let Some(x) = foo else { todo!() };

#[cfg(target_os = "linux")]
#[cfg(target_arch = "x86_64")]
let Some(x) = foo
else {
todo!()
};
let Some(x) = foo else { todo!() };

// The else block will be multi-lined because attributes and comments before `let`
// are included when calculating max width
#[cfg(target_os = "linux")]
#[cfg(target_arch = "x86_64")]
// Some comments between attributes and let-else statement
let Some(x) = foo() else {
todo!()
};
let Some(x) = foo() else { todo!() };
}
9 changes: 5 additions & 4 deletions tests/target/long_string.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
fn main() {
let f = foo("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").bar(|| {
foo(233545);
let f = foo("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
.bar(|| {
foo(233545);

if let Some(x) = foo(3) {}
});
if let Some(x) = foo(3) {}
});
}
3 changes: 2 additions & 1 deletion tests/target/string-lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ formatting"#;
let unicode = "a̐éö̲\r\n";
let unicode2 = "Löwe 老虎 Léopard";
let unicode3 = "中华Việt Nam";
let unicode4 = "☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃";
let unicode4 =
"☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃☃";

"stuffin'"
}
Expand Down

0 comments on commit 466b9df

Please sign in to comment.