File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
src/tools/rust-analyzer/lib/smol_str/tests Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ use std:: {
2+ env,
3+ path:: { Path , PathBuf } ,
4+ process:: { Command , Stdio } ,
5+ } ;
6+
7+ fn project_root ( ) -> PathBuf {
8+ PathBuf :: from (
9+ env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap_or_else ( |_| env ! ( "CARGO_MANIFEST_DIR" ) . to_owned ( ) ) ,
10+ )
11+ }
12+
13+ fn run ( cmd : & str , dir : impl AsRef < Path > ) -> Result < ( ) , ( ) > {
14+ let mut args: Vec < _ > = cmd. split_whitespace ( ) . collect ( ) ;
15+ let bin = args. remove ( 0 ) ;
16+ println ! ( "> {}" , cmd) ;
17+ let output = Command :: new ( bin)
18+ . args ( args)
19+ . current_dir ( dir)
20+ . stdin ( Stdio :: null ( ) )
21+ . stdout ( Stdio :: piped ( ) )
22+ . stderr ( Stdio :: inherit ( ) )
23+ . output ( )
24+ . map_err ( drop) ?;
25+ if output. status . success ( ) {
26+ Ok ( ( ) )
27+ } else {
28+ let stdout = String :: from_utf8 ( output. stdout ) . map_err ( drop) ?;
29+ print ! ( "{}" , stdout) ;
30+ Err ( ( ) )
31+ }
32+ }
33+
34+ #[ test]
35+ fn check_code_formatting ( ) {
36+ let dir = project_root ( ) ;
37+ if run ( "rustfmt +stable --version" , & dir) . is_err ( ) {
38+ panic ! (
39+ "failed to run rustfmt from toolchain 'stable'; \
40+ please run `rustup component add rustfmt --toolchain stable` to install it.",
41+ ) ;
42+ }
43+ if run ( "cargo +stable fmt -- --check" , & dir) . is_err ( ) {
44+ panic ! ( "code is not properly formatted; please format the code by running `cargo fmt`" )
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments