|
| 1 | +// Copyright 2021 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 | +package com.google.devtools.build.lib.analysis.testing; |
| 15 | + |
| 16 | +import static com.google.common.truth.Truth.assertAbout; |
| 17 | + |
| 18 | +import com.google.common.truth.BooleanSubject; |
| 19 | +import com.google.common.truth.FailureMetadata; |
| 20 | +import com.google.common.truth.IterableSubject; |
| 21 | +import com.google.common.truth.Subject; |
| 22 | +import com.google.devtools.build.lib.cmdline.Label; |
| 23 | +import com.google.devtools.build.lib.packages.ExecGroup; |
| 24 | +import java.util.stream.Collectors; |
| 25 | + |
| 26 | +/** A Truth {@link Subject} for {@link ExecGroup}. */ |
| 27 | +public class ExecGroupSubject extends Subject { |
| 28 | + // Static data. |
| 29 | + |
| 30 | + /** Entry point for test assertions related to {@link ExecGroup}. */ |
| 31 | + public static ExecGroupSubject assertThat(ExecGroup execGroup) { |
| 32 | + return assertAbout(ExecGroupSubject::new).that(execGroup); |
| 33 | + } |
| 34 | + |
| 35 | + /** Static method for getting the subject factory (for use with assertAbout()). */ |
| 36 | + public static Subject.Factory<ExecGroupSubject, ExecGroup> execGroups() { |
| 37 | + return ExecGroupSubject::new; |
| 38 | + } |
| 39 | + |
| 40 | + // Instance fields. |
| 41 | + |
| 42 | + private final ExecGroup actual; |
| 43 | + |
| 44 | + protected ExecGroupSubject(FailureMetadata failureMetadata, ExecGroup subject) { |
| 45 | + super(failureMetadata, subject); |
| 46 | + this.actual = subject; |
| 47 | + } |
| 48 | + |
| 49 | + public IterableSubject requiredToolchains() { |
| 50 | + return check("requiredToolchainTypes()") |
| 51 | + .that(actual.requiredToolchains().stream().collect(Collectors.toList())); |
| 52 | + } |
| 53 | + |
| 54 | + public void hasRequiredToolchain(String toolchainTypeLabel) { |
| 55 | + hasRequiredToolchain(Label.parseAbsoluteUnchecked(toolchainTypeLabel)); |
| 56 | + } |
| 57 | + |
| 58 | + public void hasRequiredToolchain(Label toolchainType) { |
| 59 | + requiredToolchains().contains(toolchainType); |
| 60 | + } |
| 61 | + |
| 62 | + public IterableSubject execCompatibleWith() { |
| 63 | + return check("execCompatibleWith()") |
| 64 | + .that(actual.execCompatibleWith().stream().collect(Collectors.toList())); |
| 65 | + } |
| 66 | + |
| 67 | + public void hasExecCompatibleWith(String constraintLabel) { |
| 68 | + hasExecCompatibleWith(Label.parseAbsoluteUnchecked(constraintLabel)); |
| 69 | + } |
| 70 | + |
| 71 | + public void hasExecCompatibleWith(Label constraintLabel) { |
| 72 | + execCompatibleWith().contains(constraintLabel); |
| 73 | + } |
| 74 | + |
| 75 | + public BooleanSubject isCopiedFromDefault() { |
| 76 | + return check("isCopiedFromDefault()").that(actual.isCopiedFromDefault()); |
| 77 | + } |
| 78 | +} |
0 commit comments