Skip to content

Speed up integration tests (move building expectations) #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ script:
- git add -A
- git diff @
- git diff-index --quiet HEAD
- cargo test -p tests_expectations
- cargo build --features "$BINDGEN_FEATURES _docs"

notifications:
Expand Down
10 changes: 8 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ $ cargo build --features "llvm_stable _docs"
### Overview <span id="tests-overview"/>

Input C/C++ test headers reside in the `tests/headers` directory. The expected
output rust bindings live in `tests/expectations`; for example,
output rust bindings live in `tests/expectations/tests`; for example,
`tests/headers/my_header.h`'s expected generated rust bindings would be
`tests/expectations/my_header.rs`.
`tests/expectations/tests/my_header.rs`.

The `tests/tools/run-bindgen.py` script runs `bindgen` on the test headers and
compares the results to the expectations.
Expand Down Expand Up @@ -96,6 +96,12 @@ specify the required features at the top of the test header in a similar manner:
// bingden-features: llvm_stable
```

Then verify the new rust bindings compile and its tests pass:

```
$ cargo test -p tests_expectations
```

## Automatic code formatting <span id="formatting"/>

There's a `rustfmt.toml` file in the repo. Ideally changes should be consistent
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ _docs = []
name = "bindgen"
path = "src/lib.rs"

[dev-dependencies.tests_expectations]
path = "tests/expectations"

[[test]]
name = "tests"
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TEST_HEADERS := $(wildcard tests/headers/*.h) $(wildcard tests/headers/*.hpp)

TEST_TARGETS := $(TEST_HEADERS:.h=.rs)
TEST_TARGETS := $(TEST_TARGETS:.hpp=.rs)
TEST_TARGETS := $(patsubst tests/headers/%, tests/expectations/%, $(TEST_TARGETS))
TEST_TARGETS := $(patsubst tests/headers/%, tests/expectations/tests/%, $(TEST_TARGETS))

BINDGEN := ./target/debug/bindgen

Expand All @@ -25,10 +25,10 @@ clean-tests:
$(RM) $(TEST_TARGETS)

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

tests/expectations/%.rs: tests/headers/%.hpp
tests/expectations/tests/%.rs: tests/headers/%.hpp
@mkdir -p $(dir $@)
./tests/tools/run-bindgen.py $(BINDGEN) $< $@
11 changes: 11 additions & 0 deletions tests/expectations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "tests_expectations"
description = "bindgen results when ran on ../headers/*"
version = "0.1.0"
authors = [
"Jyun-Yan You <[email protected]>",
"Emilio Cobos Álvarez <[email protected]>",
"The Servo project developers",
]

[dependencies]
48 changes: 0 additions & 48 deletions tests/expectations/moar_bitfields.rs

This file was deleted.

Empty file added tests/expectations/src/lib.rs
Empty file.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 0 additions & 21 deletions tests/expectations/variadic_template_args.rs

This file was deleted.

5 changes: 3 additions & 2 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fn spawn_run_bindgen<P, Q, R>(run_bindgen: P,
let bindgen = bindgen.as_ref();
let header = header.as_ref();

// Convert from "tests/headers/foo.hpp" to "tests/expectations/foo.rs" by
// Convert from "tests/headers/foo.hpp" to "tests/expectations/tests/foo.rs" by
// saving the filename, popping off "headers/foo.hpp", pushing
// "expectations", pushing the saved filename, and finally modifying the
// "expectations/tests", pushing the saved filename, and finally modifying the
// extension.

let mut expected = PathBuf::from(header);
Expand All @@ -36,6 +36,7 @@ fn spawn_run_bindgen<P, Q, R>(run_bindgen: P,
expected.pop();
expected.pop();
expected.push("expectations");
expected.push("tests");
expected.push(file_name);
expected.set_extension("rs");

Expand Down
11 changes: 0 additions & 11 deletions tests/tools/run-bindgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ def generate_bindings(bindgen, dummy_uses, flags, header, output):
command.append(header)
run_cmd(command, cwd=os.getcwd(), env=make_bindgen_env())

def test_generated_bindings(bindings):
"""Run the generated bindings's #[test]s."""
name = None
# Do not delete the temp file, because we need to end the with block before
# we can run the tests.
with tempfile.NamedTemporaryFile(delete=False) as tests:
name = tests.name
run_cmd(["rustc", "--test", bindings, "-o", name])
run_cmd([name])

def check_actual_vs_expected(expected_bindings, rust_bindings_path):
"""
Check the actual generated rust bindings versus our expected generated rust
Expand Down Expand Up @@ -177,7 +167,6 @@ def main():
test_flags,
args.header,
args.rust_bindings)
test_generated_bindings(args.rust_bindings)
check_actual_vs_expected(expected_bindings, args.rust_bindings)
sys.exit(0)

Expand Down