Skip to content

Commit

Permalink
C++: Fixes the way errors are checked in tests.
Browse files Browse the repository at this point in the history
RELNOTES:none
PiperOrigin-RevId: 206287557
  • Loading branch information
oquenchil authored and Copybara-Service committed Jul 27, 2018
1 parent 770b987 commit 5168c50
Showing 1 changed file with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.google.devtools.build.lib.rules.cpp;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -1057,25 +1056,23 @@ public void testLibraryLinkerInputArtifactCategoryError() throws Exception {
" },",
" fragments = ['cpp'],",
");");
AssertionError e = assertThrows(AssertionError.class, () -> getConfiguredTarget("//a:r"));
assertThat(e)
.hasMessageThat()
.contains(
"Possible values for artifact_category: static_library, alwayslink_static_library, "
+ "dynamic_library, interface_library");
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//a:r");
assertContainsEvent(
"Possible values for artifact_category: static_library, "
+ "alwayslink_static_library, dynamic_library, interface_library");
}

@Test
public void testCcLinkingProviderParamsWithoutFlag() throws Exception {
useConfiguration("--noexperimental_enable_cc_skylark_api");
setUpCcLinkingProviderParamsTest();
AssertionError e = assertThrows(AssertionError.class, () -> getConfiguredTarget("//a:r"));
assertThat(e)
.hasMessageThat()
.contains(
"Pass --experimental_enable_cc_skylark_api in order to "
+ "use the C++ API. Beware that we will be making breaking changes to this API "
+ "without prior warning.");
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//a:r");
assertContainsEvent(
"Pass --experimental_enable_cc_skylark_api in order to "
+ "use the C++ API. Beware that we will be making breaking changes to this API "
+ "without prior warning.");
}

@Test
Expand Down Expand Up @@ -1256,8 +1253,9 @@ public void testCcNativeRuleDependingOnSkylarkDefinedRule() throws Exception {
@Test
public void testWhitelist() throws Exception {
SkylarkCcCommonTestHelper.createFiles(scratch, "foo/bar");
AssertionError e = assertThrows(AssertionError.class, () -> getConfiguredTarget("//foo:bin"));
assertThat(e).hasMessageThat().contains("C++ Skylark API is for the time being");
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//foo:bin");
assertContainsEvent("C++ Skylark API is for the time being");
}

@Test
Expand Down Expand Up @@ -1358,10 +1356,9 @@ public void testEmptyCcLinkingInfoError() throws Exception {
"crule = rule(",
" _impl,",
");");
AssertionError e = assertThrows(AssertionError.class, () -> getConfiguredTarget("//a:r"));
assertThat(e)
.hasMessageThat()
.contains("Every CcLinkParams parameter must be passed to CcLinkingInfo.");
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//a:r");
assertContainsEvent("Every CcLinkParams parameter must be passed to CcLinkingInfo.");
}

private CppLinkAction setUpNeverlinkTest(String value) throws Exception {
Expand Down

0 comments on commit 5168c50

Please sign in to comment.