@@ -26,6 +26,8 @@ type VolatileItem = Box<dyn Fn(VolatileItemKind) -> bool>;
2626type ArrayArg = Box < dyn Fn ( crate :: Fn , Parameter ) -> bool > ;
2727/// A function that determines whether to skip a test, taking in the identifier name.
2828type SkipTest = Box < dyn Fn ( & str ) -> bool > ;
29+ /// A function that determines whether a type alias is a c enum.
30+ type CEnum = Box < dyn Fn ( & str ) -> bool > ;
2931
3032/// A builder used to generate a test suite.
3133#[ derive( Default ) ]
@@ -42,6 +44,7 @@ pub struct TestGenerator {
4244 pub ( crate ) skips : Vec < Skip > ,
4345 pub ( crate ) verbose_skip : bool ,
4446 pub ( crate ) volatile_items : Vec < VolatileItem > ,
47+ pub ( crate ) c_enums : Vec < CEnum > ,
4548 pub ( crate ) array_arg : Option < ArrayArg > ,
4649 pub ( crate ) skip_private : bool ,
4750 pub ( crate ) skip_roundtrip : Option < SkipTest > ,
@@ -206,6 +209,20 @@ impl TestGenerator {
206209 self
207210 }
208211
212+ /// Indicate that a type alias is actually a C enum.
213+ ///
214+ /// # Examples
215+ /// ```no_run
216+ /// use ctest::TestGenerator;
217+ ///
218+ /// let mut cfg = TestGenerator::new();
219+ /// cfg.alias_is_c_enum(|e| e == "pid_type");
220+ /// ```
221+ pub fn alias_is_c_enum ( & mut self , f : impl Fn ( & str ) -> bool + ' static ) -> & mut Self {
222+ self . c_enums . push ( Box :: new ( f) ) ;
223+ self
224+ }
225+
209226 /// Indicate that a struct field should be marked `volatile`.
210227 ///
211228 /// # Examples
@@ -516,6 +533,30 @@ impl TestGenerator {
516533 self
517534 }
518535
536+ /// Configures whether tests for a C enum are generated.
537+ ///
538+ /// A C enum consists of a type alias, as well as constants that have the same type. Tests
539+ /// for both the alias as well as the constants are skipped.
540+ ///
541+ /// # Examples
542+ ///
543+ /// ```no_run
544+ /// use ctest::TestGenerator;
545+ ///
546+ /// let mut cfg = TestGenerator::new();
547+ /// cfg.skip_c_enum(|e| e == "pid_type");
548+ /// ```
549+ pub fn skip_c_enum ( & mut self , f : impl Fn ( & str ) -> bool + ' static ) -> & mut Self {
550+ self . skips . push ( Box :: new ( move |item| {
551+ if let MapInput :: CEnumType ( e) = item {
552+ f ( e)
553+ } else {
554+ false
555+ }
556+ } ) ) ;
557+ self
558+ }
559+
519560 /// Add a flag to the C compiler invocation.
520561 ///
521562 /// # Examples
@@ -976,6 +1017,7 @@ impl TestGenerator {
9761017 MapInput :: UnionField ( _, f) => f. ident ( ) . to_string ( ) ,
9771018 MapInput :: StructType ( ty) => format ! ( "struct {ty}" ) ,
9781019 MapInput :: UnionType ( ty) => format ! ( "union {ty}" ) ,
1020+ MapInput :: CEnumType ( ty) => format ! ( "enum {ty}" ) ,
9791021 MapInput :: StructFieldType ( _, f) => f. ident ( ) . to_string ( ) ,
9801022 MapInput :: UnionFieldType ( _, f) => f. ident ( ) . to_string ( ) ,
9811023 MapInput :: Type ( ty) => translate_primitive_type ( ty) ,
0 commit comments