diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-03-15 15:43:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-15 15:43:19 -0700 |
commit | 8637c759662b6ea58bd1ff5df82cc5057672339d (patch) | |
tree | 30ec9fd56c40921824328a527613f0e020349e84 | |
parent | 4bc133665dc3fb7ca6535d9a8056e6b49a30caac (diff) | |
parent | 7a46377dbfedbd688ed8d4f27efab544d50b9a76 (diff) |
Auto merge of #587 - fitzgen:little-helper-stuff, r=emilio
Little helper stuff
A couple things that I've found helpful for iterative debugging.
r? @emilio
-rw-r--r-- | CONTRIBUTING.md | 11 | ||||
-rw-r--r-- | src/ir/dot.rs | 7 | ||||
-rwxr-xr-x | tests/test-one.sh | 36 |
3 files changed, 51 insertions, 3 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index df32998b..0aad4f2c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -94,6 +94,17 @@ Run `cargo test` to compare generated Rust bindings to the expectations. $ cargo test [--all-features] ``` +### Running a Single Test + +To generate bindings for a single test header, compile the bindings, and run the +layout assertion tests for those bindings, use the `tests/test-one.sh` +script. It supports fuzzy searching for test headers. For example, to test +`tests/headers/what_is_going_on.hpp`, execute this command: + +``` +$ ./tests/test-one.sh going +``` + ### Authoring New Tests To add a new test header to the suite, simply put it in the `tests/headers` diff --git a/src/ir/dot.rs b/src/ir/dot.rs index e7e1f47b..7472dd8e 100644 --- a/src/ir/dot.rs +++ b/src/ir/dot.rs @@ -36,15 +36,16 @@ pub fn write_dot_file<P>(ctx: &BindgenContext, path: P) -> io::Result<()> try!(writeln!(&mut dot_file, r#"</table> >];"#)); item.trace(ctx, - &mut |sub_id: ItemId, _edge_kind| { + &mut |sub_id: ItemId, edge_kind| { if err.is_some() { return; } match writeln!(&mut dot_file, - "{} -> {};", + "{} -> {} [label={:?}];", id.as_usize(), - sub_id.as_usize()) { + sub_id.as_usize(), + edge_kind) { Ok(_) => {} Err(e) => err = Some(Err(e)), } diff --git a/tests/test-one.sh b/tests/test-one.sh new file mode 100755 index 00000000..6475df7f --- /dev/null +++ b/tests/test-one.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Usage: +# +# ./tests/test-one.sh <fuzzy-name> +# +# Generate bindings for the first match of `./tests/headers/*<fuzzy-name>*`, use +# `rustc` to compile the bindings with unit tests enabled, and run the generated +# layout tests. + +set -eux + +cd $(dirname $0) +cd .. + +export RUST_BACKTRACE=1 + +# Grab the first match +TEST=$(find ./tests/headers -type f -iname "*$1*" | head -n 1) + +BINDINGS=$(mktemp -t bindings_XXXXXX.rs) +TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXX) + +./target/debug/bindgen \ + "$TEST" \ + --emit-ir \ + --emit-ir-graphviz ir.dot \ + --emit-clang-ast \ + -o "$BINDINGS" \ + -- -std=c++14 + +dot -Tpng ir.dot -o ir.png + +rustc --test -o "$TEST_BINDINGS_BINARY" "$BINDINGS" + +"$TEST_BINDINGS_BINARY" |