summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-03-31 20:29:10 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2019-03-31 20:29:10 +0300
commitb8fde4cf03e6a5d057b4f4f05a45f85669694f53 (patch)
tree990b4908dc8a6fa19a4164f1e7ef79f0ce08ab55
parent2a030e33f3c000134fd0d19204133befcae338c2 (diff)
downloadmeson-clangformatheader.tar.gz
Also format headers with Clang-Format. Closes #5184.clangformatheader
-rw-r--r--mesonbuild/scripts/clangformat.py1
-rwxr-xr-xrun_unittests.py25
-rw-r--r--test cases/unit/53 clang-format/header_expected_h3
-rw-r--r--test cases/unit/53 clang-format/header_orig_h9
4 files changed, 28 insertions, 10 deletions
diff --git a/mesonbuild/scripts/clangformat.py b/mesonbuild/scripts/clangformat.py
index fcdf5af74..351d06b41 100644
--- a/mesonbuild/scripts/clangformat.py
+++ b/mesonbuild/scripts/clangformat.py
@@ -21,6 +21,7 @@ from ..compilers import lang_suffixes
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
index f22a9b2eb..f381efc47 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -3271,20 +3271,25 @@ recommended as it is not supported on some platforms''')
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')
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
index 000000000..430317604
--- /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
index 000000000..f2222f305
--- /dev/null
+++ b/test cases/unit/53 clang-format/header_orig_h
@@ -0,0 +1,9 @@
+#pragma once
+
+int
+fun
+(
+int
+argc
+)
+;