mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-23 17:02:39 +00:00
This takes the mechanism currently used for autoupdate and expands it to the regular tests (deliberately trying to unify logic for test/autoupdate/dump to deliver consistent behavior). I'm seeing about a 85% reduction in test time, though results will vary based on test system. This does some small edits to test output to make it fit better with the new flow. Note I'm stopping printing of the "here's how to run" on every test by default, since it's autoupdated into file content by default. However, it's still there for test failures. --------- Co-authored-by: Geoff Romer <gromer@google.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
"""Rules for building file tests.
|
|
|
|
file_test uses the tests_as_input_file rule to transform test dependencies into
|
|
a file which can be accessed as a list. This avoids long argument parsing.
|
|
"""
|
|
|
|
load("@rules_cc//cc:defs.bzl", "cc_test")
|
|
load("//bazel/cc_toolchains:defs.bzl", "cc_env")
|
|
load("//bazel/manifest:defs.bzl", "manifest")
|
|
|
|
def file_test(
|
|
name,
|
|
tests,
|
|
data = [],
|
|
args = [],
|
|
prebuilt_binary = None,
|
|
**kwargs):
|
|
"""Generates tests using the file_test base.
|
|
|
|
There will be one main test using `name` that can be sharded, and includes
|
|
all files. Additionally, per-file tests will be generated as
|
|
`name.file_path`; these per-file tests will be manual.
|
|
|
|
Args:
|
|
name: The base name of the tests.
|
|
tests: The list of test files to use as data, typically a glob.
|
|
data: Passed to cc_test.
|
|
args: Passed to cc_test.
|
|
prebuilt_binary: If set, specifies a prebuilt test binary to use instead
|
|
of building a new one.
|
|
**kwargs: Passed to cc_test.
|
|
"""
|
|
|
|
# Ensure tests are always a filegroup for tests_as_input_file_rule.
|
|
tests_file = "{0}.tests".format(name)
|
|
manifest(
|
|
name = tests_file,
|
|
srcs = tests,
|
|
testonly = 1,
|
|
)
|
|
args = ["--test_targets_file=$(rootpath :{0})".format(tests_file)] + args
|
|
data = [":" + tests_file] + tests + data
|
|
|
|
if prebuilt_binary:
|
|
native.sh_test(
|
|
name = name,
|
|
srcs = [prebuilt_binary],
|
|
data = data,
|
|
args = args,
|
|
env = cc_env(),
|
|
**kwargs
|
|
)
|
|
else:
|
|
cc_test(
|
|
name = name,
|
|
data = data,
|
|
args = args,
|
|
env = cc_env(),
|
|
**kwargs
|
|
)
|