File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,17 @@ def parse_pattern_file(fname: Path) -> T.List[str]:
36
36
return patterns
37
37
38
38
def run_clang_format (exelist : T .List [str ], fname : Path , check : bool ) -> subprocess .CompletedProcess :
39
+ if check :
40
+ original = fname .read_bytes ()
39
41
before = fname .stat ().st_mtime
40
- ret = subprocess .run (exelist + ['-style=file' , '-i' , str (fname )])
42
+ args = ['-style=file' , '-i' , str (fname )]
43
+ ret = subprocess .run (exelist + args )
41
44
after = fname .stat ().st_mtime
42
45
if before != after :
43
46
print ('File reformatted: ' , fname )
44
47
if check :
48
+ # Restore the original if only checking.
49
+ fname .write_bytes (original )
45
50
ret .returncode = 1
46
51
return ret
47
52
Original file line number Diff line number Diff line change @@ -5634,7 +5634,7 @@ def test_devenv(self):
5634
5634
self ._run (cmd + python_command + [script ])
5635
5635
self .assertEqual ('This is text.' , self ._run (cmd + [app ]).strip ())
5636
5636
5637
- def test_clang_format (self ):
5637
+ def test_clang_format_check (self ):
5638
5638
if self .backend is not Backend .ninja :
5639
5639
raise unittest .SkipTest (f'Skipping clang-format tests with { self .backend .name } backend' )
5640
5640
if not shutil .which ('clang-format' ):
@@ -5658,9 +5658,10 @@ def test_clang_format(self):
5658
5658
output = self .build ('clang-format-check' )
5659
5659
self .assertEqual (1 , output .count ('File reformatted:' ))
5660
5660
5661
- # All code has been reformatted already, so it should be no-op now.
5661
+ # The check format should not touch any files. Thus
5662
+ # running format again has some work to do.
5662
5663
output = self .build ('clang-format' )
5663
- self .assertEqual (0 , output .count ('File reformatted:' ))
5664
+ self .assertEqual (1 , output .count ('File reformatted:' ))
5664
5665
self .build ('clang-format-check' )
5665
5666
5666
5667
def test_custom_target_implicit_include (self ):
You can’t perform that action at this time.
0 commit comments