Skip to content

Commit

Permalink
Automatic cleanup change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 246137705
  • Loading branch information
katre authored and Copybara-Service committed May 1, 2019
1 parent 63db9a4 commit 42edea6
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.fail;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -438,13 +438,10 @@ public void testExtraActionsCaching() throws Exception {
" mnemonics = ['Javac'],",
" extra_actions = [':extra'])");
reporter.removeHandler(failFastHandler);
try {
update("//java/a:a");
fail();
} catch (ViewCreationFailedException e) {
assertThat(e).hasMessageThat().contains("Analysis of target '//java/a:a' failed");
assertContainsEvent("$(BUG) not defined");
}
ViewCreationFailedException e =
assertThrows(ViewCreationFailedException.class, () -> update("//java/a:a"));
assertThat(e).hasMessageThat().contains("Analysis of target '//java/a:a' failed");
assertContainsEvent("$(BUG) not defined");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.analysis.AnalysisUtils.checkProvider;
import static org.junit.Assert.fail;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.auto.value.AutoValue;
import org.junit.Test;
Expand All @@ -33,12 +33,11 @@ public void checkProviderSucceedsOnClassAnnotatedWithAutoValue() {

@Test
public void checkProviderFailsOnClassGeneratedByAutoValue() {
try {
checkProvider(AutoValue_AnalysisUtilsTest_AutoValuedClass.class);
fail("Expected IllegalArgumentException, but nothing was thrown.");
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().contains("generated by @AutoValue");
}
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class,
() -> checkProvider(AutoValue_AnalysisUtilsTest_AutoValuedClass.class));
assertThat(e).hasMessageThat().contains("generated by @AutoValue");
}

// Note: this has to be defined outside of checkProviderFailsOnClassGeneratedByAutoValue() so it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
package com.google.devtools.build.lib.analysis;

import static org.junit.Assert.fail;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
import com.google.devtools.build.lib.clock.BlazeClock;
Expand Down Expand Up @@ -54,10 +54,6 @@ public void testGlobIOException() throws Exception {
scratch.file("a/BUILD", "sh_library(name = 'a', srcs = glob(['a.sh']))");
crashMessage = path -> path.toString().contains("a.sh") ? "bork" : null;
reporter.removeHandler(failFastHandler);
try {
update("//b:b");
fail("Expected failure");
} catch (ViewCreationFailedException expected) {
}
assertThrows(ViewCreationFailedException.class, () -> update("//b:b"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.google.devtools.build.lib.analysis;

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

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
Expand Down Expand Up @@ -80,36 +80,27 @@ public void getRuleAttributeValue() throws Exception {

@Test
public void getAspectAttributeValue() throws Exception {
try {
mapper.get("fromaspect", BuildType.LABEL);
fail("Expected failure because value queries aren't supported for aspect attributes");
} catch (UnsupportedOperationException e) {
// Expected.
}
assertThrows(
UnsupportedOperationException.class, () -> mapper.get("fromaspect", BuildType.LABEL));
}

@Test
public void getAspectValueWrongType() throws Exception {
try {
mapper.get("fromaspect", BuildType.LABEL_LIST);
fail("Expected failure on wrong-typed attribute");
} catch (IllegalArgumentException e) {
assertThat(e)
.hasMessageThat()
.isEqualTo("attribute fromaspect has type label, not expected type list(label)");
}
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class, () -> mapper.get("fromaspect", BuildType.LABEL_LIST));
assertThat(e)
.hasMessageThat()
.isEqualTo("attribute fromaspect has type label, not expected type list(label)");
}

@Test
public void getMissingAttributeValue() throws Exception {
try {
mapper.get("noexist", BuildType.LABEL);
fail("Expected failure on non-existent attribute");
} catch (IllegalArgumentException e) {
assertThat(e)
.hasMessageThat()
.isEqualTo("no attribute 'noexist' in either //foo:myrule or its aspects");
}
IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> mapper.get("noexist", BuildType.LABEL));
assertThat(e)
.hasMessageThat()
.isEqualTo("no attribute 'noexist' in either //foo:myrule or its aspects");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.fail;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -223,16 +223,14 @@ public void duplicateAspect() throws Exception {
Aspect a1 = createAspect("a1");
Aspect a2 = createAspect("a2", "a1");
Aspect a3 = createAspect("a3", "a2", "a1");
try {
AspectCollection
.create(
ImmutableList.of(a2, a1, a2, a3),
ImmutableSet.of(a3.getDescriptor()));
fail();
} catch (AspectCycleOnPathException e) {
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}
AspectCycleOnPathException e =
assertThrows(
AspectCycleOnPathException.class,
() ->
AspectCollection.create(
ImmutableList.of(a2, a1, a2, a3), ImmutableSet.of(a3.getDescriptor())));
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}

/**
Expand All @@ -245,16 +243,14 @@ public void duplicateAspect2() throws Exception {
Aspect a1 = createAspect("a1");
Aspect a2 = createAspect("a2", "a1");
Aspect a3 = createAspect("a3", "a2");
try {
AspectCollection
.create(
ImmutableList.of(a2, a1, a2, a3),
ImmutableSet.of(a3.getDescriptor()));
fail();
} catch (AspectCycleOnPathException e) {
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}
AspectCycleOnPathException e =
assertThrows(
AspectCycleOnPathException.class,
() ->
AspectCollection.create(
ImmutableList.of(a2, a1, a2, a3), ImmutableSet.of(a3.getDescriptor())));
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}

/**
Expand Down Expand Up @@ -293,16 +289,14 @@ public void duplicateAspect3() throws Exception {
Aspect a1 = createAspect("a1", "a2");
Aspect a2 = createAspect("a2", "a1");
Aspect a3 = createAspect("a3", "a1", "a2");
try {
AspectCollection
.create(
ImmutableList.of(a2, a1, a2, a3),
ImmutableSet.of(a3.getDescriptor()));
fail();
} catch (AspectCycleOnPathException e) {
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}
AspectCycleOnPathException e =
assertThrows(
AspectCycleOnPathException.class,
() ->
AspectCollection.create(
ImmutableList.of(a2, a1, a2, a3), ImmutableSet.of(a3.getDescriptor())));
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}

/**
Expand All @@ -315,16 +309,14 @@ public void duplicateAspect4() throws Exception {
Aspect a1 = createAspect("a1", "a2");
Aspect a2 = createAspect("a2", "a1");
Aspect a3 = createAspect("a3", "a2");
try {
AspectCollection
.create(
ImmutableList.of(a2, a1, a2, a3),
ImmutableSet.of(a3.getDescriptor()));
fail();
} catch (AspectCycleOnPathException e) {
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}
AspectCycleOnPathException e =
assertThrows(
AspectCycleOnPathException.class,
() ->
AspectCollection.create(
ImmutableList.of(a2, a1, a2, a3), ImmutableSet.of(a3.getDescriptor())));
assertThat(e.getAspect()).isEqualTo(a2.getDescriptor());
assertThat(e.getPreviousAspect()).isEqualTo(a1.getDescriptor());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.packages.Attribute.attr;
import static org.junit.Assert.fail;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -94,29 +94,29 @@ public void testAspectWithImplicitOrLateboundAttribute_AddsToAttributeMap() thro

@Test
public void testAspectWithDuplicateAttribute_FailsToAdd() throws Exception {
try {
new AspectDefinition.Builder(TEST_ASPECT_CLASS)
.add(attr("$runtime", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//run:time")))
.add(attr("$runtime", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//oops")));
fail(); // expected IllegalArgumentException
} catch (IllegalArgumentException e) {
// expected
}
assertThrows(
IllegalArgumentException.class,
() ->
new AspectDefinition.Builder(TEST_ASPECT_CLASS)
.add(
attr("$runtime", BuildType.LABEL)
.value(Label.parseAbsoluteUnchecked("//run:time")))
.add(
attr("$runtime", BuildType.LABEL)
.value(Label.parseAbsoluteUnchecked("//oops"))));
}

@Test
public void testAspectWithUserVisibleAttribute_FailsToAdd() throws Exception {
try {
new AspectDefinition.Builder(TEST_ASPECT_CLASS)
.add(
attr("invalid", BuildType.LABEL)
.value(Label.parseAbsoluteUnchecked("//run:time"))
.allowedFileTypes(FileTypeSet.NO_FILE))
.build();
fail(); // expected IllegalArgumentException
} catch (IllegalArgumentException e) {
// expected
}
assertThrows(
IllegalArgumentException.class,
() ->
new AspectDefinition.Builder(TEST_ASPECT_CLASS)
.add(
attr("invalid", BuildType.LABEL)
.value(Label.parseAbsoluteUnchecked("//run:time"))
.allowedFileTypes(FileTypeSet.NO_FILE))
.build());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static org.junit.Assert.fail;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -291,12 +291,7 @@ public void aspectInError() throws Exception {
reporter.removeHandler(failFastHandler);
// getConfiguredTarget() uses a separate code path that does not hit
// SkyframeBuildView#configureTargets
try {
update("//a:a");
fail();
} catch (ViewCreationFailedException e) {
// expected
}
assertThrows(ViewCreationFailedException.class, () -> update("//a:a"));
assertContainsEvent("Aspect error");
}

Expand All @@ -314,12 +309,7 @@ public void transitiveAspectInError() throws Exception {
reporter.removeHandler(failFastHandler);
// getConfiguredTarget() uses a separate code path that does not hit
// SkyframeBuildView#configureTargets
try {
update("//a:a");
fail();
} catch (ViewCreationFailedException e) {
// expected
}
assertThrows(ViewCreationFailedException.class, () -> update("//a:a"));
assertContainsEvent("Aspect error");
}

Expand Down

0 comments on commit 42edea6

Please sign in to comment.