aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlois Wohlschlager <alois1@gmx-topmail.de>2021-07-30 11:10:12 +0200
committerDaniel Mensinger <daniel@mensinger-ka.de>2021-08-04 20:31:35 +0200
commit40d5a38d1b92826c46230e971524053d14a68ae4 (patch)
tree4d7c90320981b7635dd4cbbda0500f24123a120c
parent3c3fa0a12c68da8966410ad9bacd1148dc8bd65d (diff)
downloadmeson-40d5a38d1b92826c46230e971524053d14a68ae4.zip
meson-40d5a38d1b92826c46230e971524053d14a68ae4.tar.gz
meson-40d5a38d1b92826c46230e971524053d14a68ae4.tar.bz2
Escape path in exclude filter passed to gcovr
Gcovr interprets exclude filters, as passed to the -e option, as regexes. Since we want to exclude a raw path, the argument must be escaped.
-rw-r--r--mesonbuild/scripts/coverage.py10
-rw-r--r--test cases/common/243 escape++/meson.build4
-rw-r--r--test cases/common/243 escape++/test.c3
-rw-r--r--unittests/allplatformstests.py20
4 files changed, 32 insertions, 5 deletions
diff --git a/mesonbuild/scripts/coverage.py b/mesonbuild/scripts/coverage.py
index 2bd93e8..a9e83c2 100644
--- a/mesonbuild/scripts/coverage.py
+++ b/mesonbuild/scripts/coverage.py
@@ -14,7 +14,7 @@
from mesonbuild import environment, mesonlib
-import argparse, sys, os, subprocess, pathlib, stat
+import argparse, re, sys, os, subprocess, pathlib, stat
import typing as T
def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build_root: str, log_dir: str, use_llvm_cov: bool) -> int:
@@ -38,7 +38,7 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
if gcovr_exe:
subprocess.check_call(gcovr_base_cmd +
['-x',
- '-e', subproject_root,
+ '-e', re.escape(subproject_root),
'-o', os.path.join(log_dir, 'coverage.xml')
] + gcov_exe_args)
outfiles.append(('Xml', pathlib.Path(log_dir, 'coverage.xml')))
@@ -51,7 +51,7 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
subprocess.check_call(gcovr_base_cmd +
['--sonarqube',
'-o', os.path.join(log_dir, 'sonarqube.xml'),
- '-e', subproject_root
+ '-e', re.escape(subproject_root)
] + gcov_exe_args)
outfiles.append(('Sonarqube', pathlib.Path(log_dir, 'sonarqube.xml')))
elif outputs:
@@ -61,7 +61,7 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
if not outputs or 'text' in outputs:
if gcovr_exe:
subprocess.check_call(gcovr_base_cmd +
- ['-e', subproject_root,
+ ['-e', re.escape(subproject_root),
'-o', os.path.join(log_dir, 'coverage.txt')
] + gcov_exe_args)
outfiles.append(('Text', pathlib.Path(log_dir, 'coverage.txt')))
@@ -140,7 +140,7 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
['--html',
'--html-details',
'--print-summary',
- '-e', subproject_root,
+ '-e', re.escape(subproject_root),
'-o', os.path.join(htmloutdir, 'index.html'),
])
outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
diff --git a/test cases/common/243 escape++/meson.build b/test cases/common/243 escape++/meson.build
new file mode 100644
index 0000000..5fcc00f
--- /dev/null
+++ b/test cases/common/243 escape++/meson.build
@@ -0,0 +1,4 @@
+project('regex escape test', 'c')
+
+exe = executable('testprog', 'test.c')
+test('runtest', exe)
diff --git a/test cases/common/243 escape++/test.c b/test cases/common/243 escape++/test.c
new file mode 100644
index 0000000..9b6bdc2
--- /dev/null
+++ b/test cases/common/243 escape++/test.c
@@ -0,0 +1,3 @@
+int main(void) {
+ return 0;
+}
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index a94d9cb..bd1e3fa 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -3434,6 +3434,26 @@ class AllPlatformTests(BasePlatformTests):
self.run_target('coverage-xml')
self._check_coverage_files(['xml'])
+ def test_coverage_escaping(self):
+ if mesonbuild.environment.detect_msys2_arch():
+ raise SkipTest('Skipped due to problems with coverage on MSYS2')
+ gcovr_exe, gcovr_new_rootdir = mesonbuild.environment.detect_gcovr()
+ if not gcovr_exe:
+ raise SkipTest('gcovr not found, or too old')
+ testdir = os.path.join(self.common_test_dir, '243 escape++')
+ env = get_fake_env(testdir, self.builddir, self.prefix)
+ cc = detect_c_compiler(env, MachineChoice.HOST)
+ if cc.get_id() == 'clang':
+ if not mesonbuild.environment.detect_llvm_cov():
+ raise SkipTest('llvm-cov not found')
+ if cc.get_id() == 'msvc':
+ raise SkipTest('Test only applies to non-MSVC compilers')
+ self.init(testdir, extra_args=['-Db_coverage=true'])
+ self.build()
+ self.run_tests()
+ self.run_target('coverage')
+ self._check_coverage_files()
+
def test_cross_file_constants(self):
with temp_filename() as crossfile1, temp_filename() as crossfile2:
with open(crossfile1, 'w', encoding='utf-8') as f: