2023-03-09 09:23:42 -05:00
|
|
|
"""
|
|
|
|
This module contains rules and macros for building and testing Go code.
|
|
|
|
"""
|
|
|
|
|
|
|
|
load("@io_bazel_rules_go//go:def.bzl", _go_test = "go_test")
|
|
|
|
|
2023-02-03 05:05:42 -05:00
|
|
|
def go_test(ld = None, count = 3, **kwargs):
|
2023-03-09 09:23:42 -05:00
|
|
|
"""go_test is a wrapper for go_test that uses default settings for Constellation.
|
|
|
|
|
|
|
|
It adds the following:
|
|
|
|
- Sets test count to 3.
|
2023-06-09 04:35:52 -04:00
|
|
|
- Sets race detector to on by default (except Mac OS)
|
2023-03-09 09:23:42 -05:00
|
|
|
- Optionally sets the interpreter path to ld.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
ld: path to interpreter to that will be written into the elf header.
|
2023-02-03 05:05:42 -05:00
|
|
|
count: number of times each test should be executed. defaults to 3.
|
2023-03-09 09:23:42 -05:00
|
|
|
**kwargs: all other arguments are passed to go_test.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Sets test count to 3.
|
|
|
|
kwargs.setdefault("args", [])
|
2023-02-03 05:05:42 -05:00
|
|
|
kwargs["args"].append("--test.count={}".format(count))
|
2023-03-09 09:23:42 -05:00
|
|
|
|
|
|
|
# enable race detector by default
|
2023-06-09 04:35:52 -04:00
|
|
|
race_value = select({
|
|
|
|
"@platforms//os:macos": "off",
|
|
|
|
"//conditions:default": "on",
|
|
|
|
})
|
|
|
|
pure_value = select({
|
|
|
|
"@platforms//os:macos": "on",
|
|
|
|
"//conditions:default": "off",
|
|
|
|
})
|
|
|
|
kwargs.setdefault("race", race_value)
|
|
|
|
kwargs.setdefault("pure", pure_value)
|
2023-03-09 09:23:42 -05:00
|
|
|
|
|
|
|
# set gc_linkopts to set the interpreter path to ld.
|
|
|
|
kwargs.setdefault("gc_linkopts", [])
|
|
|
|
if ld:
|
|
|
|
kwargs["gc_linkopts"] += ["-I", ld]
|
|
|
|
|
|
|
|
_go_test(**kwargs)
|