Skip to content

Commit 8637c75

Browse files
author
bors-servo
authored
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
2 parents 4bc1336 + 7a46377 commit 8637c75

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ Run `cargo test` to compare generated Rust bindings to the expectations.
9494
$ cargo test [--all-features]
9595
```
9696

97+
### Running a Single Test
98+
99+
To generate bindings for a single test header, compile the bindings, and run the
100+
layout assertion tests for those bindings, use the `tests/test-one.sh`
101+
script. It supports fuzzy searching for test headers. For example, to test
102+
`tests/headers/what_is_going_on.hpp`, execute this command:
103+
104+
```
105+
$ ./tests/test-one.sh going
106+
```
107+
97108
### Authoring New Tests
98109

99110
To add a new test header to the suite, simply put it in the `tests/headers`

src/ir/dot.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ pub fn write_dot_file<P>(ctx: &BindgenContext, path: P) -> io::Result<()>
3636
try!(writeln!(&mut dot_file, r#"</table> >];"#));
3737

3838
item.trace(ctx,
39-
&mut |sub_id: ItemId, _edge_kind| {
39+
&mut |sub_id: ItemId, edge_kind| {
4040
if err.is_some() {
4141
return;
4242
}
4343

4444
match writeln!(&mut dot_file,
45-
"{} -> {};",
45+
"{} -> {} [label={:?}];",
4646
id.as_usize(),
47-
sub_id.as_usize()) {
47+
sub_id.as_usize(),
48+
edge_kind) {
4849
Ok(_) => {}
4950
Err(e) => err = Some(Err(e)),
5051
}

tests/test-one.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# Usage:
4+
#
5+
# ./tests/test-one.sh <fuzzy-name>
6+
#
7+
# Generate bindings for the first match of `./tests/headers/*<fuzzy-name>*`, use
8+
# `rustc` to compile the bindings with unit tests enabled, and run the generated
9+
# layout tests.
10+
11+
set -eux
12+
13+
cd $(dirname $0)
14+
cd ..
15+
16+
export RUST_BACKTRACE=1
17+
18+
# Grab the first match
19+
TEST=$(find ./tests/headers -type f -iname "*$1*" | head -n 1)
20+
21+
BINDINGS=$(mktemp -t bindings_XXXXXX.rs)
22+
TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXX)
23+
24+
./target/debug/bindgen \
25+
"$TEST" \
26+
--emit-ir \
27+
--emit-ir-graphviz ir.dot \
28+
--emit-clang-ast \
29+
-o "$BINDINGS" \
30+
-- -std=c++14
31+
32+
dot -Tpng ir.dot -o ir.png
33+
34+
rustc --test -o "$TEST_BINDINGS_BINARY" "$BINDINGS"
35+
36+
"$TEST_BINDINGS_BINARY"

0 commit comments

Comments
 (0)