#
#  Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This file contains basic functions for cc fuzz test."""

load("@rules_cc//cc:defs.bzl", "cc_test")
load("//fuzzing:common.bzl", "fuzzing_launcher")

def cc_fuzz_test(
        name,
        srcs,
        copts = [],
        linkopts = [],
        deps = [],
        tags = [],
        visibility = None):
    """This macro provide two targets:
    <name>: the executable file built by cc_test.
    <name>_run: an executable to launch the fuzz test.
"""

    cc_test(
        name = name,
        srcs = srcs,
        copts = ["-fsanitize=fuzzer"] + copts,
        linkopts = ["-fsanitize=fuzzer"] + linkopts,
        deps = deps,
        tags = tags + ["fuzz_test"],
        visibility = visibility,
    )

    fuzzing_launcher(
        name = name + "_run",
        target = name,
        # Since the script depends on the _fuzz_test above, which is a cc_test,
        # this attribute must be set.
        testonly = True,
    )

@@ -768,130 +768,58 @@
     
-srcs,%0A        copts = %5B%5D,%0A        linkopts = %5B%5D,%0A        deps = %5B%5D,%0A        tags = %5B%5D,%0A        visibility = None):
+**kwargs):%0A    %22%22%22Macro for c++ fuzzing test%0A
 %0A    
-%22%22%22
 This
@@ -832,16 +832,17 @@
  provide
+s
  two tar
@@ -965,249 +965,133 @@
     
-cc_test(%0A        name = name,%0A        srcs = srcs,%0A        copts = %5B%22-fsanitize=fuzzer%22%5D + copts,%0A        linkopts = %5B%22-fsanitize=fuzzer%22%5D + linkopts,%0A        deps = deps,%0A        tags = tags + %5B%22fuzz_test%22%5D,%0A        visibility = visibility,
+# Add fuzz_test tag%0A    kwargs.setdefault(%22tags%22, %5B%5D).append(%22fuzz_test%22)%0A%0A    cc_test(%0A        name = name,%0A        **kwargs
 %0A   

Use **kwargs to forward attributes in cc_fuzz_test (#39)