2 # ===----------------------------------------------------------------------===##
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 # ===----------------------------------------------------------------------===##
15 cur_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
16 bisect_script
= os
.path
.join(cur_dir
, "..", "rsp_bisect.py")
17 test1
= os
.path
.join(cur_dir
, "test_script.py")
18 test2
= os
.path
.join(cur_dir
, "test_script_inv.py")
19 rsp
= os
.path
.join(cur_dir
, "rsp")
22 def run_bisect(success
, test_script
):
32 res
= subprocess
.run(args
, capture_output
=True, encoding
="UTF-8")
33 if len(sys
.argv
) > 1 and sys
.argv
[1] == "-v":
34 print("Ran {} with return code {}".format(args
, res
.returncode
))
39 if res
.returncode
!= (0 if success
else 1):
42 raise AssertionError("unexpected bisection return code for " + str(args
))
46 # Test that an empty rsp file fails.
47 with
open(rsp
, "w") as f
:
50 run_bisect(False, test1
)
52 # Test that an rsp file without any paths fails.
53 with
open(rsp
, "w") as f
:
54 f
.write("hello\nfoo\n")
56 run_bisect(False, test1
)
58 # Test that an rsp file with one path succeeds.
59 with
open(rsp
, "w") as f
:
62 output
= run_bisect(True, test1
)
63 assert "./foo" in output
65 # Test that an rsp file with one path and one extra arg succeeds.
66 with
open(rsp
, "w") as f
:
67 f
.write("hello\n./foo\n")
69 output
= run_bisect(True, test1
)
70 assert "./foo" in output
72 # Test that an rsp file with three paths and one extra arg succeeds.
73 with
open(rsp
, "w") as f
:
74 f
.write("hello\n./foo\n./bar\n./baz\n")
76 output
= run_bisect(True, test1
)
77 assert "./foo" in output
79 with
open(rsp
, "w") as f
:
80 f
.write("hello\n./bar\n./foo\n./baz\n")
82 output
= run_bisect(True, test1
)
83 assert "./foo" in output
85 with
open(rsp
, "w") as f
:
86 f
.write("hello\n./bar\n./baz\n./foo\n")
88 output
= run_bisect(True, test1
)
89 assert "./foo" in output
91 output
= run_bisect(True, test2
)
92 assert "./foo" in output
94 with
open(rsp
+ ".0", "r") as f
:
96 assert " ../Other/./foo" in contents
98 with
open(rsp
+ ".1", "r") as f
:
100 assert " ./foo" in contents
103 os
.remove(rsp
+ ".0")
104 os
.remove(rsp
+ ".1")