-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages
Description
As pointed out by @flip1995 in #3824 (comment), we currently don't have an easy way to run rustfmt
on the tests locally like we do on CI.
What we are doing on CI currently:
Line 24 in 8dfabdf
rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force |
Line 26 in 8dfabdf
cargo +nightly fmt --all -- --check |
Lines 53 to 78 in 8dfabdf
# make sure tests are formatted | |
# some lints are sensitive to formatting, exclude some files | |
tests_need_reformatting="false" | |
# switch to nightly | |
rustup override set nightly | |
# avoid loop spam and allow cmds with exit status != 0 | |
set +ex | |
for file in `find tests -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do | |
rustfmt ${file} --check | |
if [ $? -ne 0 ]; then | |
echo "${file} needs reformatting!" | |
tests_need_reformatting="true" | |
fi | |
done | |
set -ex # reset | |
if [ "${tests_need_reformatting}" == "true" ] ; then | |
echo "Tests need reformatting!" | |
exit 2 | |
fi | |
# switch back to master | |
rustup override set master |
It would be nice if we could extract that into a separate script so that people can use to format their tests locally, instead of waiting for CI.
Some things to consider when doing this:
- The script also needs to add the
rustfmt
component if it isn't present locally - We use
rustfmt
instead ofcargo fmt
for the test formatting because ofcargo fmt
doesn't format files in sub-directories intests
rustfmt#1820 - To make it idempotent, the new script should automatically detect the 'current' toolchain and switch back to it after the formatting script has finished (instead of switching to
master
) - Unlike a fresh VM on CI, We can't just use
rustup override set nightly
, because that doesn't update the locally installed nightly rust. We should probably pin to a specific nightly instead and update the version from time to time. - Using a shell script will not work cross-platform but I think doing it in Rust might be too much work?
felix91gr
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages