Skip to content

Commit 1ba1005

Browse files
committed
ctest: Fix skipped tests for non-CStr pointers
Currently nothing is added if a constant is a pointer but not a `c_char`. Resolve this by reducing to a single branch.
1 parent 7d5a341 commit 1ba1005

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

ctest-next/src/template.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,18 @@ impl TestTemplate {
7171
let mut const_tests = vec![];
7272
let mut const_cstr_tests = vec![];
7373
for constant in ffi_items.constants() {
74-
if let syn::Type::Ptr(ptr) = &constant.ty {
75-
let is_const_c_char_ptr = matches!(
76-
&*ptr.elem,
77-
syn::Type::Path(path)
78-
if path.path.segments.last().unwrap().ident == "c_char"
79-
&& ptr.mutability.is_none()
80-
);
81-
if is_const_c_char_ptr {
82-
let item = TestCstr {
83-
test_ident: cstr_test_ident(constant.ident()),
84-
rust_ident: constant.ident().into(),
85-
c_ident: helper.c_ident(constant).into(),
86-
c_type: helper.c_type(constant)?.into(),
87-
};
88-
const_cstr_tests.push(item)
89-
}
74+
if let syn::Type::Ptr(ptr) = &constant.ty
75+
&& let syn::Type::Path(path) = &*ptr.elem
76+
&& path.path.segments.last().unwrap().ident == "c_char"
77+
&& ptr.mutability.is_none()
78+
{
79+
let item = TestCstr {
80+
test_ident: cstr_test_ident(constant.ident()),
81+
rust_ident: constant.ident().into(),
82+
c_ident: helper.c_ident(constant).into(),
83+
c_type: helper.c_type(constant)?.into(),
84+
};
85+
const_cstr_tests.push(item)
9086
} else {
9187
let item = TestConst {
9288
test_ident: const_test_ident(constant.ident()),

0 commit comments

Comments
 (0)