Commit b954b187 authored by machenbach's avatar machenbach Committed by Commit bot

[Coverage] Add sancov_formatter unittest for split.

Unittest for feature added in:
https://codereview.chromium.org/1808663002/

BUG=chromium:568949
LOG=n
NOTRY=true

Review URL: https://codereview.chromium.org/1810043004

Cr-Commit-Position: refs/heads/master@{#34923}
parent b7aa4c3a
...@@ -401,7 +401,7 @@ def split(options): ...@@ -401,7 +401,7 @@ def split(options):
json.dump(new_data, f, sort_keys=True) json.dump(new_data, f, sort_keys=True)
def main(): def main(args=None):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--coverage-dir', parser.add_argument('--coverage-dir',
help='Path to the sancov output files.') help='Path to the sancov output files.')
...@@ -414,7 +414,7 @@ def main(): ...@@ -414,7 +414,7 @@ def main():
parser.add_argument('action', choices=['all', 'merge', 'split'], parser.add_argument('action', choices=['all', 'merge', 'split'],
help='Action to perform.') help='Action to perform.')
options = parser.parse_args() options = parser.parse_args(args)
if options.action.lower() == 'all': if options.action.lower() == 'all':
if not options.json_output: if not options.json_output:
print '--json-output is required' print '--json-output is required'
......
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
import copy import copy
import coverage import coverage
import logging import logging
import json
import os import os
import shutil
import sys import sys
import tempfile
import unittest import unittest
...@@ -128,6 +131,44 @@ EXPECTED_COVERED_LINES_DATA = { ...@@ -128,6 +131,44 @@ EXPECTED_COVERED_LINES_DATA = {
} }
#------------------------------------------------------------------------------
# Data for test_split.
EXPECTED_SPLIT_FILES = [
(
os.path.join('src', 'baz', 'bar.h.json'),
{
'version': 1,
'tests': ['cctest', 'd8', 'unittests'],
'files': {
'src/baz/bar.h': [[0, 0b0], [3, 0b11], [7, 0b11], [8, 0b0]],
},
},
),
(
os.path.join('src', 'baz.cc.json'),
{
'version': 1,
'tests': ['cctest', 'd8', 'unittests'],
'files': {
'src/baz.cc': [[1, 0b0], [2, 0b101]],
},
},
),
(
os.path.join('src', 'foo.cc.json'),
{
'version': 1,
'tests': ['cctest', 'd8', 'unittests'],
'files': {
'src/foo.cc': [[1, 0b1], [11, 0b10], [92, 0b100], [93, 0b0]],
},
},
),
]
class FormatterTests(unittest.TestCase): class FormatterTests(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
...@@ -157,3 +198,25 @@ class FormatterTests(unittest.TestCase): ...@@ -157,3 +198,25 @@ class FormatterTests(unittest.TestCase):
sancov_formatter.merge_covered_line_results( sancov_formatter.merge_covered_line_results(
data, COVERED_LINE_RESULTS) data, COVERED_LINE_RESULTS)
self.assertEquals(EXPECTED_COVERED_LINES_DATA, data) self.assertEquals(EXPECTED_COVERED_LINES_DATA, data)
def test_split(self):
_, json_input = tempfile.mkstemp(prefix='tmp_coverage_test_split')
with open(json_input, 'w') as f:
json.dump(EXPECTED_COVERED_LINES_DATA, f)
output_dir = tempfile.mkdtemp(prefix='tmp_coverage_test_split')
try:
sancov_formatter.main([
'split',
'--json-input', json_input,
'--output-dir', output_dir,
])
for file_name, expected_data in EXPECTED_SPLIT_FILES:
full_path = os.path.join(output_dir, file_name)
self.assertTrue(os.path.exists(full_path))
with open(full_path) as f:
self.assertEquals(expected_data, json.load(f))
finally:
os.remove(json_input)
shutil.rmtree(output_dir)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment