forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update creating exec groups that explicitly copy from defaults.
Also add an ExecGroupSubject to improve testing. PiperOrigin-RevId: 372387338
Showing
8 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/com/google/devtools/build/lib/analysis/testing/ExecGroupSubject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2021 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.analysis.testing; | ||
|
||
import static com.google.common.truth.Truth.assertAbout; | ||
|
||
import com.google.common.truth.BooleanSubject; | ||
import com.google.common.truth.FailureMetadata; | ||
import com.google.common.truth.IterableSubject; | ||
import com.google.common.truth.Subject; | ||
import com.google.devtools.build.lib.cmdline.Label; | ||
import com.google.devtools.build.lib.packages.ExecGroup; | ||
import java.util.stream.Collectors; | ||
|
||
/** A Truth {@link Subject} for {@link ExecGroup}. */ | ||
public class ExecGroupSubject extends Subject { | ||
// Static data. | ||
|
||
/** Entry point for test assertions related to {@link ExecGroup}. */ | ||
public static ExecGroupSubject assertThat(ExecGroup execGroup) { | ||
return assertAbout(ExecGroupSubject::new).that(execGroup); | ||
} | ||
|
||
/** Static method for getting the subject factory (for use with assertAbout()). */ | ||
public static Subject.Factory<ExecGroupSubject, ExecGroup> execGroups() { | ||
return ExecGroupSubject::new; | ||
} | ||
|
||
// Instance fields. | ||
|
||
private final ExecGroup actual; | ||
|
||
protected ExecGroupSubject(FailureMetadata failureMetadata, ExecGroup subject) { | ||
super(failureMetadata, subject); | ||
this.actual = subject; | ||
} | ||
|
||
public IterableSubject requiredToolchains() { | ||
return check("requiredToolchainTypes()") | ||
.that(actual.requiredToolchains().stream().collect(Collectors.toList())); | ||
} | ||
|
||
public void hasRequiredToolchain(String toolchainTypeLabel) { | ||
hasRequiredToolchain(Label.parseAbsoluteUnchecked(toolchainTypeLabel)); | ||
} | ||
|
||
public void hasRequiredToolchain(Label toolchainType) { | ||
requiredToolchains().contains(toolchainType); | ||
} | ||
|
||
public IterableSubject execCompatibleWith() { | ||
return check("execCompatibleWith()") | ||
.that(actual.execCompatibleWith().stream().collect(Collectors.toList())); | ||
} | ||
|
||
public void hasExecCompatibleWith(String constraintLabel) { | ||
hasExecCompatibleWith(Label.parseAbsoluteUnchecked(constraintLabel)); | ||
} | ||
|
||
public void hasExecCompatibleWith(Label constraintLabel) { | ||
execCompatibleWith().contains(constraintLabel); | ||
} | ||
|
||
public BooleanSubject isCopiedFromDefault() { | ||
return check("isCopiedFromDefault()").that(actual.isCopiedFromDefault()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters