mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 11:31:04 +01:00
Inconsistent execution environments make using a path-as-define difficult, so switch to an embedded file. Also fixes the lldb launch so that passing tests run cleanly, and adds TEST_TARGET to gdb (but without testing there). I'm dropping `sourceMap` because it's not handled quite correctly (also not great to be trying to pass source mappings in two different ways), and `env` didn't seem to be working as intended either; maybe specifying `initCommands` causes other things to not be evaluated. But the straight `initCommands` looks like it's working. I used lldb to validate execution of these changes. ``` Running initCommands: (lldb) command script import external/+llvm_project+llvm-project/llvm/utils/lldbDataFormatters.py (lldb) settings set target.source-map "." "/usr/local/google/home/jperkins/dev/carbon-lang" (lldb) settings set target.source-map "/proc/self/cwd" "/usr/local/google/home/jperkins/dev/carbon-lang" (lldb) env TEST_TARGET=//toolchain/testing:file_test (lldb) env TEST_TMPDIR=/tmp Running tests with 128 thread(s) . Done! Note: Google Test filter = ToolchainFileTest.toolchain/check/testdata/const/collapse.carbon [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from ToolchainFileTest [ RUN ] ToolchainFileTest.toolchain/check/testdata/const/collapse.carbon [ OK ] ToolchainFileTest.toolchain/check/testdata/const/collapse.carbon (0 ms) [----------] 1 test from ToolchainFileTest (0 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (1 ms total) [ PASSED ] 1 test. Process 3869310 exited with status = 0 (0x00000000) ```
81 lines
2.6 KiB
Python
81 lines
2.6 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", "manifest_as_cpp")
|
|
|
|
def file_test(
|
|
name,
|
|
tests,
|
|
srcs = [],
|
|
deps = [],
|
|
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.
|
|
srcs: Passed to cc_test.
|
|
deps: Passed to cc_test.
|
|
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.
|
|
if prebuilt_binary:
|
|
# TODO: The prebuilt_binary support is only used by explorer. We should
|
|
# remove this once explorer is removed, and think about better factoring
|
|
# approaches if we need it later for toolchain.
|
|
tests_file = "{0}.tests".format(name)
|
|
manifest(
|
|
name = tests_file,
|
|
srcs = tests,
|
|
testonly = 1,
|
|
)
|
|
args = ["--explorer_test_targets_file=$(rootpath :{0})".format(tests_file)] + args
|
|
|
|
native.sh_test(
|
|
name = name,
|
|
srcs = srcs + [prebuilt_binary],
|
|
deps = deps,
|
|
data = [":" + tests_file] + tests + data,
|
|
args = args,
|
|
env = cc_env(),
|
|
**kwargs
|
|
)
|
|
else:
|
|
manifest_cpp = "{0}_autogen_manifest.cpp".format(name)
|
|
manifest_as_cpp(
|
|
name = manifest_cpp,
|
|
var_name = "CarbonFileTestManifest",
|
|
srcs = tests,
|
|
testonly = 1,
|
|
)
|
|
cc_test(
|
|
name = name,
|
|
srcs = srcs + [":" + manifest_cpp],
|
|
deps = deps + ["//testing/file_test:manifest_impl"],
|
|
data = tests + data,
|
|
args = args,
|
|
env = cc_env(),
|
|
**kwargs
|
|
)
|