Skip to content

Commit 2866ab5

Browse files
committed
Speed up integration tests (move building expectations)
Speed up running 'cargo test': -Before: 2'17s -After: 30s Update to use new path: Makefile, .travis.yml, CONTRIBUTING.md, tests/tests.rs Delete unused expectation that fail to compile: tests/expectations/moar_bitfields.rs tests/expectations/variadic_template_args.rs For every 'cargo test' run, the bindgen output where built. We already test that the bindgen output match expectations/*.rs, so there is no need to check it build unless the expectation is updated. Move tests/expectations/*.rs to tests/expectations/tests/*.rs and make tests/expectations a new dev-dependency package. This allow running: - cargo test -p tests_expectations In addition to the speed up, we also get a clean output for the build and test run. In particular, a number of warnings are generated that should probably be silenced, and eventually enforced modifying travis to build: - RUSTFLAGS='-D warnings' cargo test -p tests_expectations The benefit of having it as a new package is that it avoid polluting the 'cargo test' output that should focus on bindgen.
1 parent 9073a4f commit 2866ab5

File tree

118 files changed

+29
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+29
-87
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ script:
3333
- git add -A
3434
- git diff @
3535
- git diff-index --quiet HEAD
36+
- cargo test -p tests_expectations
3637
- cargo build --features "$BINDGEN_FEATURES _docs"
3738

3839
notifications:

CONTRIBUTING.md

+8-2

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ _docs = []
5454
name = "bindgen"
5555
path = "src/lib.rs"
5656

57+
[dev-dependencies.tests_expectations]
58+
path = "tests/expectations"
59+
5760
[[test]]
5861
name = "tests"

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ TEST_HEADERS := $(wildcard tests/headers/*.h) $(wildcard tests/headers/*.hpp)
33

44
TEST_TARGETS := $(TEST_HEADERS:.h=.rs)
55
TEST_TARGETS := $(TEST_TARGETS:.hpp=.rs)
6-
TEST_TARGETS := $(patsubst tests/headers/%, tests/expectations/%, $(TEST_TARGETS))
6+
TEST_TARGETS := $(patsubst tests/headers/%, tests/expectations/tests/%, $(TEST_TARGETS))
77

88
BINDGEN := ./target/debug/bindgen
99

@@ -25,10 +25,10 @@ clean-tests:
2525
$(RM) $(TEST_TARGETS)
2626

2727
# TODO: Add options to add flags and whatnot
28-
tests/expectations/%.rs: tests/headers/%.h
28+
tests/expectations/tests/%.rs: tests/headers/%.h
2929
@mkdir -p $(dir $@)
3030
./tests/tools/run-bindgen.py $(BINDGEN) $< $@
3131

32-
tests/expectations/%.rs: tests/headers/%.hpp
32+
tests/expectations/tests/%.rs: tests/headers/%.hpp
3333
@mkdir -p $(dir $@)
3434
./tests/tools/run-bindgen.py $(BINDGEN) $< $@

tests/expectations/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "tests_expectations"
3+
description = "bindgen results when ran on ../headers/*"
4+
version = "0.1.0"
5+
authors = [
6+
"Jyun-Yan You <[email protected]>",
7+
"Emilio Cobos Álvarez <[email protected]>",
8+
"The Servo project developers",
9+
]
10+
11+
[dependencies]

tests/expectations/moar_bitfields.rs

-48
This file was deleted.

tests/expectations/src/lib.rs

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/expectations/variadic_template_args.rs

-21
This file was deleted.

tests/tests.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ fn spawn_run_bindgen<P, Q, R>(run_bindgen: P,
2424
let bindgen = bindgen.as_ref();
2525
let header = header.as_ref();
2626

27-
// Convert from "tests/headers/foo.hpp" to "tests/expectations/foo.rs" by
27+
// Convert from "tests/headers/foo.hpp" to "tests/expectations/tests/foo.rs" by
2828
// saving the filename, popping off "headers/foo.hpp", pushing
29-
// "expectations", pushing the saved filename, and finally modifying the
29+
// "expectations/tests", pushing the saved filename, and finally modifying the
3030
// extension.
3131

3232
let mut expected = PathBuf::from(header);
@@ -36,6 +36,7 @@ fn spawn_run_bindgen<P, Q, R>(run_bindgen: P,
3636
expected.pop();
3737
expected.pop();
3838
expected.push("expectations");
39+
expected.push("tests");
3940
expected.push(file_name);
4041
expected.set_extension("rs");
4142

tests/tools/run-bindgen.py

-11
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,6 @@ def generate_bindings(bindgen, dummy_uses, flags, header, output):
130130
command.append(header)
131131
run_cmd(command, cwd=os.getcwd(), env=make_bindgen_env())
132132

133-
def test_generated_bindings(bindings):
134-
"""Run the generated bindings's #[test]s."""
135-
name = None
136-
# Do not delete the temp file, because we need to end the with block before
137-
# we can run the tests.
138-
with tempfile.NamedTemporaryFile(delete=False) as tests:
139-
name = tests.name
140-
run_cmd(["rustc", "--test", bindings, "-o", name])
141-
run_cmd([name])
142-
143133
def check_actual_vs_expected(expected_bindings, rust_bindings_path):
144134
"""
145135
Check the actual generated rust bindings versus our expected generated rust
@@ -177,7 +167,6 @@ def main():
177167
test_flags,
178168
args.header,
179169
args.rust_bindings)
180-
test_generated_bindings(args.rust_bindings)
181170
check_actual_vs_expected(expected_bindings, args.rust_bindings)
182171
sys.exit(0)
183172

0 commit comments

Comments
 (0)