1# Copyright 2023 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 15"""Tests for StructSubject""" 16 17load("//lib:truth.bzl", "subjects") 18load("//lib:test_suite.bzl", "test_suite") 19load("//tests:test_util.bzl", "test_util") 20 21_tests = [] 22 23def _struct_subject_test(env): 24 fake_meta = test_util.fake_meta(env) 25 actual = subjects.struct( 26 struct(n = 1, x = "foo"), 27 meta = fake_meta, 28 attrs = dict( 29 n = subjects.int, 30 x = subjects.str, 31 ), 32 ) 33 actual.n().equals(1) 34 test_util.expect_no_failures(env, fake_meta, "struct.n()") 35 36 actual.n().equals(99) 37 test_util.expect_failures( 38 env, 39 fake_meta, 40 "struct.n() failure", 41 "expected: 99", 42 ) 43 44 actual.x().equals("foo") 45 test_util.expect_no_failures(env, fake_meta, "struct.foo()") 46 47 actual.x().equals("not-foo") 48 test_util.expect_failures(env, fake_meta, "struct.foo() failure", "expected: not-foo") 49 50_tests.append(_struct_subject_test) 51 52def struct_subject_test_suite(name): 53 test_suite(name = name, basic_tests = _tests) 54