From e446f3b10f886362cfa31f5ba17b91cc638aa60a Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 15 Mar 2017 15:11:48 -0700 Subject: Add a script to test bindings generation and layout for one header at a time --- CONTRIBUTING.md | 11 +++++++++++ tests/test-one.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 tests/test-one.sh 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 +# +# Generate bindings for the first match of `./tests/headers/**`, 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" -- cgit v1.2.3