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
):
24 bisect_script
, '--test', test_script
, '--rsp', rsp
, '--other-rel-path',
27 res
= subprocess
.run(args
, capture_output
=True, encoding
='UTF-8')
28 if len(sys
.argv
) > 1 and sys
.argv
[1] == '-v':
29 print('Ran {} with return code {}'.format(args
, res
.returncode
))
34 if res
.returncode
!= (0 if success
else 1):
37 raise AssertionError('unexpected bisection return code for ' + str(args
))
41 # Test that an empty rsp file fails.
42 with
open(rsp
, 'w') as f
:
45 run_bisect(False, test1
)
47 # Test that an rsp file without any paths fails.
48 with
open(rsp
, 'w') as f
:
49 f
.write('hello\nfoo\n')
51 run_bisect(False, test1
)
53 # Test that an rsp file with one path succeeds.
54 with
open(rsp
, 'w') as f
:
57 output
= run_bisect(True, test1
)
58 assert './foo' in output
60 # Test that an rsp file with one path and one extra arg succeeds.
61 with
open(rsp
, 'w') as f
:
62 f
.write('hello\n./foo\n')
64 output
= run_bisect(True, test1
)
65 assert './foo' in output
67 # Test that an rsp file with three paths and one extra arg succeeds.
68 with
open(rsp
, 'w') as f
:
69 f
.write('hello\n./foo\n./bar\n./baz\n')
71 output
= run_bisect(True, test1
)
72 assert './foo' in output
74 with
open(rsp
, 'w') as f
:
75 f
.write('hello\n./bar\n./foo\n./baz\n')
77 output
= run_bisect(True, test1
)
78 assert './foo' in output
80 with
open(rsp
, 'w') as f
:
81 f
.write('hello\n./bar\n./baz\n./foo\n')
83 output
= run_bisect(True, test1
)
84 assert './foo' in output
86 output
= run_bisect(True, test2
)
87 assert './foo' in output
89 with
open(rsp
+ '.0', 'r') as f
:
91 assert ' ../Other/./foo' in contents
93 with
open(rsp
+ '.1', 'r') as f
:
95 assert ' ./foo' in contents