Skip to content

Commit a5c06ec

Browse files
authored
Fix test (#4237)
* Fix tests - Assert that the given parameter is valid. - Fix paths. * Cargo fmt and fix long string literals by hand
1 parent 258a723 commit a5c06ec

17 files changed

+43
-33
lines changed

Diff for: src/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ mod test {
438438
line if-else expressions. A value of zero means always break if-else expressions.";
439439

440440
unstable_features: bool, false, true,
441-
"Enables unstable features on stable and beta channels (unstable features are enabled \
442-
by default on nightly channel)";
441+
"Enables unstable features on stable and beta channels \
442+
(unstable features are enabled by default on nightly channel)";
443443

444444
// Options that are used by the tests
445445
stable_option: bool, false, true, "A stable option";
@@ -667,7 +667,7 @@ ignore = []
667667
assert!(paths[0].ends_with("a/rustfmt.toml"));
668668
assert!(paths[1].ends_with("a/b/rustfmt.toml"));
669669
}
670-
_ => (),
670+
_ => {}
671671
};
672672
}
673673

Diff for: src/config/config_type.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ macro_rules! create_config {
171171
update_config!(self, $i = val, dir);
172172
} else {
173173
eprintln!(
174-
"Warning: can't set `{} = {:?}`, unstable features can only \
175-
be used on stable or beta when `unstable_features` is also enabled.",
174+
"Warning: can't set `{} = {:?}`, unstable features can \
175+
only be used on stable or beta when `unstable_features` \
176+
is also enabled.",
176177
stringify!($i), val
177178
);
178179
}
@@ -249,8 +250,9 @@ macro_rules! create_config {
249250
stringify!($Ty)));
250251
} else {
251252
return eprintln!(
252-
"Warning: can't set `{} = {:?}`, unstable features can only \
253-
be used on stable or beta when `unstable_features` is also enabled.",
253+
"Warning: can't set `{} = {:?}`, unstable features \
254+
can only be used on stable or beta when `unstable_features` \
255+
is also enabled.",
254256
stringify!($i), val
255257
);
256258
}

Diff for: src/config/license.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl TemplateParser {
139139
parser.linum
140140
)));
141141
}
142-
_ => (),
142+
_ => {}
143143
}
144144
parser.parsed.push_str(&regex::escape(&parser.buffer));
145145

Diff for: src/formatting/chains.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl Chain {
353353
CommentPosition::Top,
354354
));
355355
}
356-
_ => (),
356+
_ => {}
357357
}
358358

359359
prev_span_end = chain_item.span.hi();

Diff for: src/formatting/comment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ where
13031303
self.status = CharClassesStatus::LitChar;
13041304
return Some((char_kind, item));
13051305
}
1306-
_ => (),
1306+
_ => {}
13071307
}
13081308

13091309
match self.base.peek() {
@@ -1608,7 +1608,7 @@ pub(crate) fn filter_normal_code(code: &str) -> String {
16081608
buffer.push_str(&line);
16091609
buffer.push('\n');
16101610
}
1611-
_ => (),
1611+
_ => {}
16121612
});
16131613
if !code.ends_with('\n') && buffer.ends_with('\n') {
16141614
buffer.pop();

Diff for: src/formatting/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ fn rewrite_index(
15071507
Some(ref index_str) if !index_str.contains('\n') => {
15081508
return Some(format!("{}[{}]", expr_str, index_str));
15091509
}
1510-
_ => (),
1510+
_ => {}
15111511
}
15121512

15131513
// Try putting index on the next line and see if it fits in a single line.

Diff for: src/formatting/imports.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl UseTree {
427427

428428
// Remove foo::{} or self without attributes.
429429
match last {
430-
_ if self.attrs.is_some() => (),
430+
_ if self.attrs.is_some() => {}
431431
UseSegment::List(ref list) if list.is_empty() => {
432432
self.path = vec![];
433433
return self;
@@ -436,7 +436,7 @@ impl UseTree {
436436
self.path = vec![];
437437
return self;
438438
}
439-
_ => (),
439+
_ => {}
440440
}
441441

442442
// Normalise foo::self -> foo.

Diff for: src/formatting/items.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ pub(crate) fn format_impl(
805805
Some(ref missing_comment) if !missing_comment.is_empty() => {
806806
result.push_str(missing_comment);
807807
}
808-
_ => (),
808+
_ => {}
809809
}
810810
}
811811
}
@@ -1171,7 +1171,7 @@ pub(crate) fn format_trait(
11711171
Some(ref missing_comment) if !missing_comment.is_empty() => {
11721172
result.push_str(missing_comment);
11731173
}
1174-
_ => (),
1174+
_ => {}
11751175
}
11761176
}
11771177
}
@@ -1449,7 +1449,7 @@ fn format_empty_struct_or_tuple(
14491449
let comment_shape =
14501450
Shape::indented(offset, context.config).block_indent(context.config.tab_spaces());
14511451
match rewrite_missing_comment(span, comment_shape, context) {
1452-
Some(ref s) if s.is_empty() => (),
1452+
Some(ref s) if s.is_empty() => {}
14531453
Some(ref s) => {
14541454
if !is_single_line(s) || first_line_contains_single_line_comment(s) {
14551455
let nested_indent_str = offset
@@ -2478,7 +2478,7 @@ fn rewrite_fn_base(
24782478
result.push_str(missing_comment);
24792479
force_new_line_for_brace = true;
24802480
}
2481-
_ => (),
2481+
_ => {}
24822482
}
24832483
}
24842484
}
@@ -2643,7 +2643,7 @@ fn compute_budgets_for_params(
26432643
match fn_brace_style {
26442644
FnBraceStyle::None => used_space += 1, // 1 = `;`
26452645
FnBraceStyle::SameLine => used_space += 2, // 2 = `{}`
2646-
FnBraceStyle::NextLine => (),
2646+
FnBraceStyle::NextLine => {}
26472647
}
26482648
let one_line_budget = context.budget(used_space);
26492649

Diff for: src/formatting/lists.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ pub(crate) fn get_comment_end(
665665
match post_snippet.find('/') {
666666
Some(j) if j < i => block_open_index = None,
667667
_ if post_snippet[..i].ends_with('/') => block_open_index = None,
668-
_ => (),
668+
_ => {}
669669
}
670670
}
671671
let newline_index = post_snippet.find('\n');

Diff for: src/formatting/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn rewrite_macro_inner(
316316

317317
match parser.token.kind {
318318
TokenKind::Eof => break,
319-
TokenKind::Comma => (),
319+
TokenKind::Comma => {}
320320
TokenKind::Semi => {
321321
// Try to parse `vec![expr; expr]`
322322
if FORCED_BRACKET_MACROS.contains(&&macro_name[..]) {

Diff for: src/formatting/modules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
234234
.or_insert(sub_mod);
235235
}
236236
}
237-
_ => (),
237+
_ => {}
238238
}
239239
Ok(())
240240
}

Diff for: src/formatting/modules/visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'a> CfgIfVisitor<'a> {
3030
impl<'a, 'ast: 'a> Visitor<'ast> for CfgIfVisitor<'a> {
3131
fn visit_mac(&mut self, mac: &'ast ast::MacCall) {
3232
match self.visit_mac_inner(mac) {
33-
Ok(()) => (),
33+
Ok(()) => {}
3434
Err(e) => debug!("{}", e),
3535
}
3636
}

Diff for: src/formatting/overflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl<'a> Context<'a> {
479479
{
480480
self.context.force_one_line_chain.replace(true);
481481
}
482-
_ => (),
482+
_ => {}
483483
}
484484
let result = last_item_shape(
485485
&self.items,
@@ -582,7 +582,7 @@ impl<'a> Context<'a> {
582582
}
583583
}
584584
}
585-
_ => (),
585+
_ => {}
586586
}
587587

588588
tactic

Diff for: src/formatting/syntux/session/ignore_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mod test {
5757
assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz.rs"))));
5858
assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/bar.rs"))));
5959
}
60-
_ => (),
60+
_ => {}
6161
};
6262
}
6363
}

Diff for: src/formatting/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn rewrite_segment(
286286
shape,
287287
)?);
288288
}
289-
_ => (),
289+
_ => {}
290290
}
291291
}
292292

@@ -556,7 +556,7 @@ impl Rewrite for ast::GenericParam {
556556
// FIXME: If there are more than one attributes, this will force multiline.
557557
match self.attrs.rewrite(context, shape) {
558558
Some(ref rw) if !rw.is_empty() => result.push_str(&format!("{} ", rw)),
559-
_ => (),
559+
_ => {}
560560
}
561561

562562
if let rustc_ast::ast::GenericParamKind::Const { ref ty } = &self.kind {

Diff for: src/formatting/visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
331331
self.push_str(" ");
332332
continue;
333333
}
334-
0 => (),
334+
0 => {}
335335
1 if prev_is_comment
336336
&& last_line_contains_single_line_comment(&self.buffer) =>
337337
{
338338
self.push_str("\n")
339339
}
340-
1 => (),
340+
1 => {}
341341
_ => self.push_str("\n"),
342342
}
343343
newline_inserted = true;
@@ -853,7 +853,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
853853
FormatError::from_span(ErrorKind::BadAttr, self.parse_sess, attr.span),
854854
);
855855
}
856-
_ => (),
856+
_ => {}
857857
}
858858
}
859859
}

Diff for: src/test/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ fn is_file_skip(skip_file_white_list: &[&str], path: &Path) -> bool {
9898
// given path. The `recursive` argument controls if files from subdirectories
9999
// are also returned.
100100
fn get_test_files(path: &Path, recursive: bool, skip_file_white_list: &[&str]) -> Vec<PathBuf> {
101+
assert!(path.exists(), "{} does not exist", path.display());
102+
101103
let mut files = vec![];
102104
if path.is_dir() {
103105
for entry in fs::read_dir(path)
@@ -384,9 +386,9 @@ fn self_tests() {
384386
return;
385387
}
386388
let skip_file_white_list = ["target", "tests"];
387-
let files = get_test_files(Path::new("../../rustfmt-core"), true, &skip_file_white_list);
389+
let files = get_test_files(Path::new("src"), true, &skip_file_white_list);
388390

389-
let (reports, count, fails) = check_files(files, &Some(PathBuf::from("../../rustfmt.toml")));
391+
let (reports, count, fails) = check_files(files, &Some(PathBuf::from("rustfmt.toml")));
390392
let mut warnings = 0;
391393

392394
// Display results.
@@ -672,6 +674,12 @@ fn idempotent_check(
672674
) -> Result<FormatReport, IdempotentCheckError> {
673675
let sig_comments = read_significant_comments(filename);
674676
let (config, builder, _) = if let Some(ref config_file_path) = opt_config {
677+
assert!(
678+
config_file_path.exists(),
679+
"{} does not exist",
680+
config_file_path.display()
681+
);
682+
675683
let config = Config::from_toml_path(config_file_path).expect("`rustfmt.toml` not found");
676684
let builder = OperationSetting::default();
677685
let emitter_config = EmitterConfig::default();

0 commit comments

Comments
 (0)