diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-03-15 15:11:48 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-03-15 15:39:36 -0700 |
commit | e446f3b10f886362cfa31f5ba17b91cc638aa60a (patch) | |
tree | 0f403aad406bba930c9712a945f7cbd75b2af61d | |
parent | 4bc133665dc3fb7ca6535d9a8056e6b49a30caac (diff) |
Add a script to test bindings generation and layout for one header at a time
-rw-r--r-- | CONTRIBUTING.md | 11 | ||||
-rwxr-xr-x | tests/test-one.sh | 36 |
2 files changed, 47 insertions, 0 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/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" |