1#!/usr/bin/env vpython3 2# Copyright 2019 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import os 7import subprocess 8import sys 9import unittest 10 11import mock 12 13import merge_lib as merger 14 15 16class MergeLibTest(unittest.TestCase): 17 18 # pylint: disable=super-with-arguments 19 def __init__(self, *args, **kwargs): 20 super(MergeLibTest, self).__init__(*args, **kwargs) 21 self.maxDiff = None 22 # pylint: enable=super-with-arguments 23 24 @mock.patch.object(subprocess, 'check_output') 25 def test_validate_and_convert_profraw(self, mock_cmd): 26 test_cases = [ 27 ([''], [['mock.profdata'], [], []]), 28 (['Counter overflow'], [[], ['mock.profraw'], ['mock.profraw']]), 29 (subprocess.CalledProcessError( 30 255, 31 'llvm-cov merge -o mock.profdata -sparse=true mock.profraw', 32 output='Malformed profile'), [[], ['mock.profraw'], []]), 33 ] 34 for side_effect, expected_results in test_cases: 35 mock_cmd.side_effect = side_effect 36 output_profdata_files = [] 37 invalid_profraw_files = [] 38 counter_overflows = [] 39 merger._validate_and_convert_profraw( 40 'mock.profraw', output_profdata_files, invalid_profraw_files, 41 counter_overflows, '/usr/bin/llvm-cov') 42 self.assertEqual( 43 expected_results, 44 [output_profdata_files, invalid_profraw_files, counter_overflows]) 45 46 47if __name__ == '__main__': 48 unittest.main() 49