Skip to content

Commit

Permalink
Extend CMake tests with testing different config variants
Browse files Browse the repository at this point in the history
We now test "no config file", "explicit config file" and "implicit
config file", which are all supported variants.
  • Loading branch information
jschwe committed Mar 12, 2023
1 parent e648562 commit 9f427e5
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/depfile/cbindgen_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function(add_cbindgen_command custom_target_name header_destination)
"${CBINDGEN_PATH}"
--output "${header_destination}"
--depfile "${depfile_destination}"
${ARGN}
DEPFILE "${depfile_destination}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Running cbindgen"
Expand Down
1 change: 1 addition & 0 deletions tests/depfile/single_crate_config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
13 changes: 13 additions & 0 deletions tests/depfile/single_crate_config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.21.0)

project(depfile_test
LANGUAGES C
DESCRIPTION "A CMake Project to test the --depfile output from cbindgen"
)

include(../cbindgen_test.cmake)

add_cbindgen_command(gen_bindings
"${CMAKE_CURRENT_BINARY_DIR}/single_crate.h"
--config "${CMAKE_CURRENT_SOURCE_DIR}/config.toml"
)
7 changes: 7 additions & 0 deletions tests/depfile/single_crate_config/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/depfile/single_crate_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "single_crate"
version = "0.1.0"
authors = ["cbindgen"]

[features]
cbindgen = []
Empty file.
4 changes: 4 additions & 0 deletions tests/depfile/single_crate_config/expectations/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config.toml
src/alias/mod.rs
src/annotation.rs
src/lib.rs
32 changes: 32 additions & 0 deletions tests/depfile/single_crate_config/src/alias/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[repr(C)]
struct Dep {
a: i32,
b: f32,
}

#[repr(C)]
struct Foo<X> {
a: X,
b: X,
c: Dep,
}

#[repr(u32)]
enum Status {
Ok,
Err,
}

type IntFoo = Foo<i32>;
type DoubleFoo = Foo<f64>;

type Unit = i32;
type SpecialStatus = Status;

#[no_mangle]
pub extern "C" fn root(
x: IntFoo,
y: DoubleFoo,
z: Unit,
w: SpecialStatus,
) {}
43 changes: 43 additions & 0 deletions tests/depfile/single_crate_config/src/annotation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// cbindgen:derive-lt=true
/// cbindgen:derive-lte=true
/// cbindgen:derive-constructor=true
/// cbindgen:rename-all=GeckoCase
#[repr(C)]
struct A(i32);

/// cbindgen:field-names=[x, y]
#[repr(C)]
struct B(i32, f32);

/// cbindgen:trailing-values=[Z, W]
#[repr(u32)]
enum C {
X = 2,
Y,
}

/// cbindgen:derive-helper-methods=true
#[repr(u8)]
enum F {
Foo(i16),
Bar { x: u8, y: i16 },
Baz,
}

/// cbindgen:derive-helper-methods
#[repr(C, u8)]
enum H {
Hello(i16),
There { x: u8, y: i16 },
Everyone,
}

#[no_mangle]
pub extern "C" fn root(
x: A,
y: B,
z: C,
f: F,
h: H,
) {}

2 changes: 2 additions & 0 deletions tests/depfile/single_crate_config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod alias;
mod annotation;
1 change: 1 addition & 0 deletions tests/depfile/single_crate_default_config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
12 changes: 12 additions & 0 deletions tests/depfile/single_crate_default_config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.21.0)

project(depfile_test
LANGUAGES C
DESCRIPTION "A CMake Project to test the --depfile output from cbindgen"
)

include(../cbindgen_test.cmake)

add_cbindgen_command(gen_bindings
"${CMAKE_CURRENT_BINARY_DIR}/single_crate.h"
)
7 changes: 7 additions & 0 deletions tests/depfile/single_crate_default_config/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/depfile/single_crate_default_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "single_crate"
version = "0.1.0"
authors = ["cbindgen"]

[features]
cbindgen = []
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cbindgen.toml
src/alias/mod.rs
src/annotation.rs
src/lib.rs
32 changes: 32 additions & 0 deletions tests/depfile/single_crate_default_config/src/alias/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[repr(C)]
struct Dep {
a: i32,
b: f32,
}

#[repr(C)]
struct Foo<X> {
a: X,
b: X,
c: Dep,
}

#[repr(u32)]
enum Status {
Ok,
Err,
}

type IntFoo = Foo<i32>;
type DoubleFoo = Foo<f64>;

type Unit = i32;
type SpecialStatus = Status;

#[no_mangle]
pub extern "C" fn root(
x: IntFoo,
y: DoubleFoo,
z: Unit,
w: SpecialStatus,
) {}
43 changes: 43 additions & 0 deletions tests/depfile/single_crate_default_config/src/annotation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// cbindgen:derive-lt=true
/// cbindgen:derive-lte=true
/// cbindgen:derive-constructor=true
/// cbindgen:rename-all=GeckoCase
#[repr(C)]
struct A(i32);

/// cbindgen:field-names=[x, y]
#[repr(C)]
struct B(i32, f32);

/// cbindgen:trailing-values=[Z, W]
#[repr(u32)]
enum C {
X = 2,
Y,
}

/// cbindgen:derive-helper-methods=true
#[repr(u8)]
enum F {
Foo(i16),
Bar { x: u8, y: i16 },
Baz,
}

/// cbindgen:derive-helper-methods
#[repr(C, u8)]
enum H {
Hello(i16),
There { x: u8, y: i16 },
Everyone,
}

#[no_mangle]
pub extern "C" fn root(
x: A,
y: B,
z: C,
f: F,
h: H,
) {}

2 changes: 2 additions & 0 deletions tests/depfile/single_crate_default_config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod alias;
mod annotation;

0 comments on commit 9f427e5

Please sign in to comment.