@@ -610,6 +610,58 @@ def swift_cc_test_library(**kwargs):
610
610
611
611
native .cc_library (** kwargs )
612
612
613
+ def swift_c_test (name , type , ** kwargs ):
614
+ """Wraps cc_test to enforce Swift testing conventions for C code.
615
+
616
+ This rule creates a test target along with a target that contains the sources
617
+ of the test. The name of the sources is created with the '.srcs' suffix.
618
+
619
+ Args:
620
+ name: A unique name for this rule.
621
+ type: Specifies whether the test is a unit or integration test.
622
+
623
+ These are passed to cc_test as tags which enables running
624
+ these test types seperately: `bazel test --test_tag_filters=unit //...`
625
+
626
+ **kwargs: See https://bazel.build/reference/be/c-cpp#cc_test
627
+
628
+ The following additional attributes are supported:
629
+
630
+ local_includes: List of local (non-public) include paths. Prefer
631
+ this to passing local includes using copts. Paths are expected to
632
+ be relative to the package this macro is called from.
633
+ """
634
+
635
+ _ = kwargs .pop ("nocopts" , []) # To handle API compatibility.
636
+
637
+ srcs_name = name + ".srcs"
638
+ srcs = kwargs .get ("srcs" , [])
639
+
640
+ native .filegroup (
641
+ name = srcs_name ,
642
+ srcs = srcs ,
643
+ visibility = ["//visibility:public" ],
644
+ tags = [TEST_SRCS ],
645
+ target_compatible_with = kwargs .get ("target_compatible_with" , []),
646
+ )
647
+
648
+ kwargs ["srcs" ] = [":" + srcs_name ]
649
+
650
+ if not (type == UNIT or type == INTEGRATION ):
651
+ fail ("The 'type' attribute must be either UNIT or INTEGRATION" )
652
+
653
+ local_includes = _construct_local_includes (kwargs .pop ("local_includes" , []))
654
+
655
+ kwargs ["copts" ] = local_includes + kwargs .get ("copts" , []) + _tests_warn_deprecated_declarations ()
656
+ kwargs ["data" ] = kwargs .get ("data" , []) + _symbolizer_data ()
657
+ kwargs ["env" ] = _symbolizer_env (kwargs .get ("env" , {}))
658
+ kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
659
+ kwargs ["name" ] = name
660
+ kwargs ["tags" ] = [TEST , type ] + kwargs .get ("tags" , [])
661
+ kwargs ["target_compatible_with" ] = kwargs .get ("target_compatible_with" , []) + _test_compatible_with ()
662
+
663
+ native .cc_test (** kwargs )
664
+
613
665
def swift_cc_test (name , type , ** kwargs ):
614
666
"""Wraps cc_test to enforce Swift testing conventions.
615
667
0 commit comments