summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2020-03-03 10:28:48 -0800
committerMatt Clay <matt@mystile.com>2020-03-03 14:07:29 -0800
commit1a8fdaadc797e56b74822cee18f1454f76bbe1d8 (patch)
tree2b1f450912fd5499e3fee1235d3c8e644e6b432c
parentd61332b50e32d529127c37219f6eb509ea6b83b2 (diff)
downloadansible-1a8fdaadc797e56b74822cee18f1454f76bbe1d8.tar.gz
Fix powershell coverage path rewriting.
This applies the same rewrite logic to PowerShell coverage as is used for Python coverage.
-rw-r--r--changelogs/fragments/ansible-test-powershell-coverage-paths.yml2
-rw-r--r--test/lib/ansible_test/_internal/coverage/__init__.py8
-rw-r--r--test/lib/ansible_test/_internal/coverage/analyze/targets/generate.py3
-rw-r--r--test/lib/ansible_test/_internal/coverage/combine.py4
4 files changed, 13 insertions, 4 deletions
diff --git a/changelogs/fragments/ansible-test-powershell-coverage-paths.yml b/changelogs/fragments/ansible-test-powershell-coverage-paths.yml
new file mode 100644
index 0000000000..cabddf0e6d
--- /dev/null
+++ b/changelogs/fragments/ansible-test-powershell-coverage-paths.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - ansible-test now correctly rewrites coverage paths for PowerShell files when testing collections
diff --git a/test/lib/ansible_test/_internal/coverage/__init__.py b/test/lib/ansible_test/_internal/coverage/__init__.py
index 4da90551d1..db05a7cdb2 100644
--- a/test/lib/ansible_test/_internal/coverage/__init__.py
+++ b/test/lib/ansible_test/_internal/coverage/__init__.py
@@ -153,7 +153,11 @@ def enumerate_python_arcs(
yield filename, set(arcs)
-def enumerate_powershell_lines(path): # type: (str) -> t.Generator[t.Tuple[str, t.Dict[int, int]]]
+def enumerate_powershell_lines(
+ path, # type: str
+ collection_search_re, # type: t.Optional[t.Pattern]
+ collection_sub_re, # type: t.Optional[t.Pattern]
+): # type: (...) -> t.Generator[t.Tuple[str, t.Dict[int, int]]]
"""Enumerate PowerShell code coverage lines in the given file."""
if os.path.getsize(path) == 0:
display.warning('Empty coverage file: %s' % path, verbosity=2)
@@ -166,7 +170,7 @@ def enumerate_powershell_lines(path): # type: (str) -> t.Generator[t.Tuple[str,
return
for filename, hits in coverage_run.items():
- filename = sanitize_filename(filename)
+ filename = sanitize_filename(filename, collection_search_re=collection_search_re, collection_sub_re=collection_sub_re)
if not filename:
continue
diff --git a/test/lib/ansible_test/_internal/coverage/analyze/targets/generate.py b/test/lib/ansible_test/_internal/coverage/analyze/targets/generate.py
index 4e33255946..3ff074b242 100644
--- a/test/lib/ansible_test/_internal/coverage/analyze/targets/generate.py
+++ b/test/lib/ansible_test/_internal/coverage/analyze/targets/generate.py
@@ -90,6 +90,7 @@ def analyze_powershell_coverage(
): # type: (...) -> Lines
"""Analyze PowerShell code coverage"""
results = {} # type: Lines
+ collection_search_re, collection_sub_re = get_collection_path_regexes()
powershell_files = get_powershell_coverage_files()
for powershell_file in powershell_files:
@@ -99,7 +100,7 @@ def analyze_powershell_coverage(
target_name = get_target_name(powershell_file)
target_index = get_target_index(target_name, target_indexes)
- for filename, hits in enumerate_powershell_lines(powershell_file):
+ for filename, hits in enumerate_powershell_lines(powershell_file, collection_search_re, collection_sub_re):
lines = results.setdefault(filename, {})
for covered_line in hits:
diff --git a/test/lib/ansible_test/_internal/coverage/combine.py b/test/lib/ansible_test/_internal/coverage/combine.py
index e4a6f61415..bb2474b1a0 100644
--- a/test/lib/ansible_test/_internal/coverage/combine.py
+++ b/test/lib/ansible_test/_internal/coverage/combine.py
@@ -135,6 +135,8 @@ def _command_coverage_combine_powershell(args):
sources = _get_coverage_targets(args, walk_powershell_targets)
groups = _build_stub_groups(args, sources, _default_stub_value)
+ collection_search_re, collection_sub_re = get_collection_path_regexes()
+
for coverage_file in coverage_files:
counter += 1
display.info('[%4d/%4d] %s' % (counter, len(coverage_files), coverage_file), verbosity=2)
@@ -145,7 +147,7 @@ def _command_coverage_combine_powershell(args):
display.warning('Unexpected name for coverage file: %s' % coverage_file)
continue
- for filename, hits in enumerate_powershell_lines(coverage_file):
+ for filename, hits in enumerate_powershell_lines(coverage_file, collection_search_re, collection_sub_re):
if group not in groups:
groups[group] = {}