|
15 | 15 | package com.google.devtools.build.lib.rules.cpp; |
16 | 16 |
|
17 | 17 | import static com.google.common.truth.Truth.assertThat; |
| 18 | +import static org.junit.Assert.assertThrows; |
18 | 19 |
|
19 | 20 | import com.google.common.collect.ImmutableList; |
20 | 21 | import com.google.common.collect.Iterables; |
|
24 | 25 | import com.google.devtools.build.lib.analysis.RuleContext; |
25 | 26 | import com.google.devtools.build.lib.analysis.util.AnalysisMock; |
26 | 27 | import com.google.devtools.build.lib.packages.util.Crosstool.CcToolchainConfig; |
| 28 | +import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ExpansionException; |
27 | 29 | import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.LibraryToLinkValue; |
28 | 30 | import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.VariableValue; |
29 | 31 | import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; |
@@ -473,6 +475,35 @@ public void testIsCcTestLinkActionBuildVariable() throws Exception { |
473 | 475 | .isFalse(); |
474 | 476 | } |
475 | 477 |
|
| 478 | + @Test |
| 479 | + public void testDisableIsCcTestLinkActionBuildVariable() throws Exception { |
| 480 | + // The use of this feature (implied by the flag) replaces the use of the build variable. |
| 481 | + // This test ensures the build variable is never *set*. |
| 482 | + useConfiguration("--incompatible_enable_cc_test_feature"); |
| 483 | + |
| 484 | + scratch.file( |
| 485 | + "x/BUILD", |
| 486 | + "cc_test(name = 'foo_test', srcs = ['a.cc'])", |
| 487 | + "cc_binary(name = 'foo', srcs = ['a.cc'])"); |
| 488 | + scratch.file("x/a.cc"); |
| 489 | + |
| 490 | + ConfiguredTarget testTarget = getConfiguredTarget("//x:foo_test"); |
| 491 | + CcToolchainVariables testVariables = |
| 492 | + getLinkBuildVariables(testTarget, LinkTargetType.EXECUTABLE); |
| 493 | + |
| 494 | + assertThrows( |
| 495 | + ExpansionException.class, |
| 496 | + () -> testVariables.getVariable(LinkBuildVariables.IS_CC_TEST.getVariableName())); |
| 497 | + |
| 498 | + ConfiguredTarget binaryTarget = getConfiguredTarget("//x:foo"); |
| 499 | + CcToolchainVariables binaryVariables = |
| 500 | + getLinkBuildVariables(binaryTarget, LinkTargetType.EXECUTABLE); |
| 501 | + |
| 502 | + assertThrows( |
| 503 | + ExpansionException.class, |
| 504 | + () -> binaryVariables.getVariable(LinkBuildVariables.IS_CC_TEST.getVariableName())); |
| 505 | + } |
| 506 | + |
476 | 507 | @Test |
477 | 508 | public void testStripBinariesIsEnabledWhenStripModeIsAlwaysNoMatterWhat() throws Exception { |
478 | 509 | scratch.file("x/BUILD", "cc_binary(name = 'foo', srcs = ['a.cc'])"); |
|
0 commit comments