Skip to content

Add recursive config setting to appropriate tests #4113

Closed
@calebcartwright

Description

@calebcartwright

rustfmt 1.x ran in "recursive" mode by default wherein all the mods within the AST would be visited and formatted, including those mods defined in external files not explicitly passed as args to rustfmt.

rustfmt 2.x inverts that behavior and will now only format files explicitly passed to rustfmt unless the --recursive flag is passed (in which case rustfmt 2.x formats everything like rustfmt 1.x)

As such a few of our test cases needed to be updated to explicitly include the recursive. Currently these tests are running in "non-recursive" mode and unintentionally ignoring some files which has resulted in a few false positves.

This can be addressed by adding the below snippet to the top of the corresponding pairs of test files under rustfmt-core/rustfmt-lib/tests/{source, target}/**

// rustfmt-recursive: true

Some (perhaps all) of the tests that need this change can be found by reviewing the skipped files in rustfmt-core/rustfmt-lib/src/test/mod.rs to determine the corresponding entry point files that need recursive enabled.

const SKIP_FILE_WHITE_LIST: &[&str] = &[
"issue-3434/no_entry.rs",
"issue-3665/sub_mod.rs",
// Testing for issue-3779
"issue-3779/ice.rs",
// These files and directory are a part of modules defined inside `cfg_if!`.
"cfg_if/mod.rs",
"cfg_if/detect",
"issue-3253/foo.rs",
"issue-3253/bar.rs",
"issue-3253/paths",
// These files and directory are a part of modules defined inside `cfg_attr(..)`.
"cfg_mod/dir",
"cfg_mod/bar.rs",
"cfg_mod/foo.rs",
"cfg_mod/wasm32.rs",
// We want to ensure `recursive` is working correctly, so do not test
// these files directly
"configs/recursive/disabled/foo.rs",
"configs/recursive/enabled/foo.rs",
];

For example, we can see there's some test files within the cfg_if directory (rustfmt-core/rustfmt-lib/tests/{source,target}/cfg_if/mod.rs that are being explicitly ignored to validate the target behavior, so the entry test file in this case (rustfmt-core/rustfmt-lib/tests/{source,target}/cfg_if/lib.rs) needs to have recursive mode included by adding // rustfmt-recursive: true

This would be a good first issue for anyone interested in working on rustfmt!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions