Skip to content

Commit 60c0531

Browse files
committed
Make tests/tools/run-bindgen.py check expectations if the rust path already exists
1 parent 7cea09c commit 60c0531

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/tools/run-bindgen.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
flags = ["--no-unstable-rust"]
2121

22-
with open(sys.argv[2]) as f:
22+
with open(c_path) as f:
2323
for line in f:
2424
if line.startswith(BINDGEN_FLAGS_PREFIX):
2525
flags.extend(line.strip().split(BINDGEN_FLAGS_PREFIX)[1].split(" "))
@@ -40,11 +40,30 @@
4040
# https://forums.developer.apple.com/thread/9233
4141
if "DYLD_LIBRARY_PATH" not in env and "LIBCLANG_PATH" in env:
4242
env["DYLD_LIBRARY_PATH"] = env["LIBCLANG_PATH"]
43-
subprocess.check_call(base_command, cwd=os.getcwd(), env=env)
4443

44+
# If the rust file already exists, read it now so we can compare its contents
45+
# before and after.
46+
original_rust_contents = None
47+
if os.path.isfile(rust_path):
48+
with open(rust_path) as f:
49+
original_rust_contents = f.read()
50+
51+
subprocess.check_call(base_command, cwd=os.getcwd(), env=env)
4552

4653
name = None
4754
with tempfile.NamedTemporaryFile(delete=False) as tests:
4855
name = tests.name
4956
subprocess.check_call(["rustc", "--test", sys.argv[3], "-o", tests.name])
5057
subprocess.check_call([tests.name])
58+
59+
if original_rust_contents is not None:
60+
new_rust_contents = None
61+
with open(rust_path) as f:
62+
new_rust_contents = f.read()
63+
if new_rust_contents != original_rust_contents:
64+
print("Generated rust bindings do not match expectation!")
65+
print("Expected rust bindings:")
66+
print(original_rust_contents)
67+
print("Actual rust bindings:")
68+
print(new_rust_contents)
69+
sys.exit(1)

0 commit comments

Comments
 (0)