• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Helpers for creating tests for the rule based toolchain."""
15
16load("@rules_testing//lib:analysis_test.bzl", _analysis_test = "analysis_test")
17load("@rules_testing//lib:truth.bzl", "matching")
18load("@rules_testing//lib:util.bzl", "util")
19load(":subjects.bzl", "FACTORIES")
20
21visibility("//tests/rule_based_toolchain/...")
22
23helper_target = util.helper_target
24
25def analysis_test(*, name, **kwargs):
26    """An analysis test for the toolchain rules.
27
28    Args:
29      name: (str) The name of the test suite.
30      **kwargs: Kwargs to be passed to rules_testing's analysis_test.
31    """
32
33    _analysis_test(
34        name = name,
35        provider_subject_factories = FACTORIES,
36        **kwargs
37    )
38
39def expect_failure_test(*, name, target, failure_message):
40    def _impl(env, target):
41        env.expect.that_target(target).failures().contains_predicate(matching.contains(failure_message))
42
43    _analysis_test(
44        name = name,
45        expect_failure = True,
46        impl = _impl,
47        target = target,
48    )
49