summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md11
-rwxr-xr-xtests/test-one.sh36
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"