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
14 def run(source_dir
, target_dir
):
16 return subprocess
.check_call(
17 cmd
, cwd
=target_dir
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
20 execute(["cmake", source_dir
])
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
)
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
)
35 lhs
= read_json(expected
)
36 rhs
= read_json(result
)
38 self
.assertTrue(rhs
.count(item
))
40 self
.assertTrue(lhs
.count(item
))
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
)