ctest
Automated testing of FFI bindings in Rust. This repository is intended to
validate the *-sys crates that can be found on crates.io to ensure that the
APIs in Rust match the APIs defined in C.
MSRV (Minimum Supported Rust Version)
The MSRV is 1.88.0 because of the transitive dependencies. Note that MSRV may be changed anytime by dependencies.
Example
Unfortunately the usage today is a little wonky, but to use this library, first, create a new Cargo project in your repo:
$ cargo new --bin systest
Then, edit systest/Cargo.toml to add these dependencies:
[]
# ...
= "build.rs"
[]
= { = "../mylib-sys" }
= "0.2"
[]
= "0.5.0-beta.0"
Next, add a build script to systest/build.rs:
Next, add this to src/main.rs
use *;
use *;
include!;
And you're good to go! To run the tests execute cargo run in the systest
directory, and everything should be kicked into action!
How it works
This library will parse the *-sys crate to learn about all definitions within.
It will then generate a test suite to ensure that all function signatures,
constant values, struct layout/alignment, type size/alignment, etc,
all match their C equivalent.
The generated tests come in two forms. One is a Rust file which contains the
main function (hence the include! above), and another is a C file which is
compiled as part of the build script. The C file is what includes all headers
and returns information about the C side of things (which is validated in Rust).
A large amount of configuration can be applied to how the C file is generated, you can browse the documentation.
Projects using ctest
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Modifying test templates
If you modify the test templates for either Rust or C in any way, then before contributing you must run the following command to update the pre-generated test files we check against:
$ LIBC_BLESS=1 cargo test
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in ctest by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.