1# Copyright (C) 2022 The Android Open Source Project 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 15load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") 16 17def _rule_failure_impl(ctx): 18 env = analysistest.begin(ctx) 19 asserts.expect_failure(env, ctx.attr.failure_message) 20 return analysistest.end(env) 21 22expect_failure_test = analysistest.make( 23 impl = _rule_failure_impl, 24 expect_failure = True, 25 attrs = { 26 "failure_message": attr.string(), 27 }, 28 doc = "This test checks that a rule fails with the expected failure_message", 29) 30 31def _target_under_test_exist_impl(ctx): 32 env = analysistest.begin(ctx) 33 return analysistest.end(env) 34 35target_under_test_exist_test = analysistest.make( 36 impl = _target_under_test_exist_impl, 37 doc = "This test checks that the target under test exists without failure", 38) 39