Repository: mesonbuild/meson

Issue:
clang-format: Also format header files
Currently the code
```python
suffixes = set(lang_suffixes['c']).union(set(lang_suffixes['cpp']))
```
in `mesonbuild/scripts/clangformat.py` just takes all `*.c` and `*.cpp` files and formats them but ignores all `*.h` (or `*.hpp`) files in the source.


Discussion:
.h files are broken but .hpp files should not be. `lang_suffixes['c']` does contain `.hpp`.

Resolving patch:
diff --git a/mesonbuild/scripts/clangformat.py b/mesonbuild/scripts/clangformat.py
--- a/mesonbuild/scripts/clangformat.py
+++ b/mesonbuild/scripts/clangformat.py
@@ -21,6 +21,7 @@
 def clangformat(srcdir_name, builddir_name):
     srcdir = pathlib.Path(srcdir_name)
     suffixes = set(lang_suffixes['c']).union(set(lang_suffixes['cpp']))
+    suffixes.add('h')
     futures = []
     with ThreadPoolExecutor() as e:
         for f in (x for suff in suffixes for x in srcdir.glob('**/*.' + suff)):
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -3271,20 +3271,25 @@ def test_clang_format(self):
         testfile = os.path.join(testdir, 'prog.c')
         badfile = os.path.join(testdir, 'prog_orig_c')
         goodfile = os.path.join(testdir, 'prog_expected_c')
+        testheader = os.path.join(testdir, 'header.h')
+        badheader = os.path.join(testdir, 'header_orig_h')
+        goodheader = os.path.join(testdir, 'header_expected_h')
         try:
-            self.run_clangformat(testdir, testfile, badfile, goodfile)
+            shutil.copyfile(badfile, testfile)
+            shutil.copyfile(badheader, testheader)
+            self.init(testdir)
+            self.assertNotEqual(Path(testfile).read_text(),
+                                Path(goodfile).read_text())
+            self.assertNotEqual(Path(testheader).read_text(),
+                                Path(goodheader).read_text())
+            self.run_target('clang-format')
+            self.assertEqual(Path(testheader).read_text(),
+                             Path(goodheader).read_text())
         finally:
             if os.path.exists(testfile):
                 os.unlink(testfile)
-
-    def run_clangformat(self, testdir, testfile, badfile, goodfile):
-        shutil.copyfile(badfile, testfile)
-        self.init(testdir)
-        self.assertNotEqual(Path(testfile).read_text(),
-                            Path(goodfile).read_text())
-        self.run_target('clang-format')
-        self.assertEqual(Path(testfile).read_text(),
-                         Path(goodfile).read_text())
+            if os.path.exists(testheader):
+                os.unlink(testheader)
 
     def test_introspect_buildoptions_without_configured_build(self):
         testdir = os.path.join(self.unit_test_dir, '56 introspect buildoptions')


Test patch:
diff --git a/test cases/unit/53 clang-format/header_expected_h b/test cases/unit/53 clang-format/header_expected_h
new file mode 100644
--- /dev/null
+++ b/test cases/unit/53 clang-format/header_expected_h	
@@ -0,0 +1,3 @@
+#pragma once
+
+int fun(int argc);
diff --git a/test cases/unit/53 clang-format/header_orig_h b/test cases/unit/53 clang-format/header_orig_h
new file mode 100644
--- /dev/null
+++ b/test cases/unit/53 clang-format/header_orig_h	
@@ -0,0 +1,9 @@
+#pragma once
+
+int
+fun
+(
+int
+argc
+)
+;