Debian Codegraph @

clang/tools/scan-build-py/tests/functional/cases/test_exec_anatomy.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 # See https://llvm.org/LICENSE.txt for license information.
4 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6 import libear
7 import unittest
8
9 import os.path
10 import subprocess
11 import json
12
13
14 def run(source_dir, target_dir):
15 def execute(cmd):
16 return subprocess.check_call(
17 cmd, cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
18 )
19
20 execute(["cmake", source_dir])
21 execute(["make"])
22
23 result_file = os.path.join(target_dir, "result.json")
24 expected_file = os.path.join(target_dir, "expected.json")
25 execute(["intercept-build", "--cdb", result_file, "./exec", expected_file])
26 return (expected_file, result_file)
27
28
29 class ExecAnatomyTest(unittest.TestCase):
30 def assertEqualJson(self, expected, result):
31 def read_json(filename):
32 with open(filename) as handler:
33 return json.load(handler)
34
35 lhs = read_json(expected)
36 rhs = read_json(result)
37 for item in lhs:
38 self.assertTrue(rhs.count(item))
39 for item in rhs:
40 self.assertTrue(lhs.count(item))
41
42 def test_all_exec_calls(self):
43 this_dir, _ = os.path.split(__file__)
44 source_dir = os.path.abspath(os.path.join(this_dir, "..", "exec"))
45 with libear.TemporaryDirectory() as tmp_dir:
46 expected, result = run(source_dir, tmp_dir)
47 self.assertEqualJson(expected, result)