aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2015-02-25 15:39:06 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-25 15:39:06 +0000
commit53b15a4c104b7f8853ddef54a73d28aa9c695089 (patch)
tree62d9a7b5571a79a5b92d266775c987125eed1e24 /src/test/java/com/google/devtools
parente7e30f43db1944bfac3d649271cdeec2f37c8132 (diff)
Remove ChattyAssertsTestCase. Use static imports, move the code down the
tree, rewrite most uses of assertPresence. This is a small step towards migrating the tests to JUnit 4. Depending on inheritance for the assert* methods is not recommended, and the (old) Asserts class is deprecated in JUnit 4. Sorry, there was no good way to do this piecemeal. -- MOS_MIGRATED_REVID=87154212
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/BuildViewTestCase.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/ChattyAssertsTestCase.java204
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java8
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java4
7 files changed, 22 insertions, 214 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTestCase.java
index 7566f2f80f..99c5740ab4 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTestCase.java
@@ -85,6 +85,7 @@ import com.google.devtools.build.lib.skyframe.SequencedSkyframeExecutor;
import com.google.devtools.build.lib.syntax.Label;
import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.testutil.FoundationTestCase;
+import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.util.BlazeClock;
@@ -968,7 +969,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
*/
protected void assertSameContentsWithCommonElements(Iterable<Artifact> artifacts,
Iterable<String> common, String... expectedInputs) {
- assertSameContents(Iterables.concat(Lists.newArrayList(expectedInputs), common),
+ MoreAsserts.assertSameContents(Iterables.concat(Lists.newArrayList(expectedInputs), common),
ActionsTestUtil.prettyArtifactNames(artifacts));
}
@@ -978,7 +979,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
*/
protected void assertSameContentsWithCommonElements(Iterable<String> artifacts,
String[] expectedInputs, Iterable<String> common) {
- assertSameContents(Iterables.concat(Lists.newArrayList(expectedInputs), common), artifacts);
+ MoreAsserts.assertSameContents(Iterables.concat(Lists.newArrayList(expectedInputs), common),
+ artifacts);
}
/**
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java
index ff0ed2f2d1..ac960e5a25 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.analysis.actions;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
+import com.google.common.collect.Sets;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionOwner;
@@ -59,7 +60,7 @@ public abstract class FileWriteActionTestCase extends BuildViewTestCase {
protected void checkDestinationArtifactIsOutput() {
Collection<Artifact> outputs = action.getOutputs();
- assertEquals(asSet(outputArtifact), asSet(outputs));
+ assertEquals(Sets.newHashSet(outputArtifact), Sets.newHashSet(outputs));
assertEquals(outputArtifact, action.getPrimaryOutput());
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java
index 6ff4a8db4f..e4229b00e2 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java
@@ -14,12 +14,14 @@
package com.google.devtools.build.lib.analysis.actions;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.devtools.build.lib.testutil.MoreAsserts.assertSameContents;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.util.Arrays.asList;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Sets;
import com.google.devtools.build.lib.actions.AbstractAction;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.Artifact;
@@ -85,13 +87,13 @@ public class SpawnActionTest extends BuildViewTestCase {
public void testWelcomeArtifactIsInput() {
SpawnAction copyFromWelcomeToDestination = createCopyFromWelcomeToDestination();
Iterable<Artifact> inputs = copyFromWelcomeToDestination.getInputs();
- assertEquals(asSet(welcomeArtifact), asSet(inputs));
+ assertEquals(Sets.newHashSet(welcomeArtifact), Sets.newHashSet(inputs));
}
public void testDestinationArtifactIsOutput() {
SpawnAction copyFromWelcomeToDestination = createCopyFromWelcomeToDestination();
Collection<Artifact> outputs = copyFromWelcomeToDestination.getOutputs();
- assertEquals(asSet(destinationArtifact), asSet(outputs));
+ assertEquals(Sets.newHashSet(destinationArtifact), Sets.newHashSet(outputs));
}
public void testBuilder() throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java
index 4ab2c12fae..1e6573fd67 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java
@@ -15,6 +15,7 @@ package com.google.devtools.build.lib.analysis.actions;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
+import com.google.common.collect.Sets;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.Artifact;
@@ -53,12 +54,12 @@ public class SymlinkActionTest extends BuildViewTestCase {
public void testInputArtifactIsInput() {
Iterable<Artifact> inputs = action.getInputs();
- assertEquals(asSet(inputArtifact), asSet(inputs));
+ assertEquals(Sets.newHashSet(inputArtifact), Sets.newHashSet(inputs));
}
public void testDestinationArtifactIsOutput() {
Iterable<Artifact> outputs = action.getOutputs();
- assertEquals(asSet(outputArtifact), asSet(outputs));
+ assertEquals(Sets.newHashSet(outputArtifact), Sets.newHashSet(outputs));
}
public void testSymlink() throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/ChattyAssertsTestCase.java b/src/test/java/com/google/devtools/build/lib/testutil/ChattyAssertsTestCase.java
deleted file mode 100644
index 6c5b1e8550..0000000000
--- a/src/test/java/com/google/devtools/build/lib/testutil/ChattyAssertsTestCase.java
+++ /dev/null
@@ -1,204 +0,0 @@
-// Copyright 2014 Google Inc. 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.testutil;
-
-import static com.google.common.truth.Truth.assertThat;
-import static com.google.common.truth.Truth.assertWithMessage;
-
-import com.google.common.collect.Sets;
-import com.google.devtools.build.lib.util.BlazeClock;
-import com.google.devtools.build.lib.util.ExitCode;
-
-import junit.framework.TestCase;
-
-import java.util.Objects;
-import java.util.Set;
-
-/**
- * Most of this stuff is copied from junit's {@link junit.framework.Assert}
- * class, and then customized to make the error messages a bit more informative.
- */
-public abstract class ChattyAssertsTestCase extends TestCase {
- private long currentTestStartTime = -1;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- currentTestStartTime = BlazeClock.instance().currentTimeMillis();
- }
-
- @Override
- protected void tearDown() throws Exception {
- JunitTestUtils.nullifyInstanceFields(this);
- assertFalse("tearDown without setUp!", currentTestStartTime == -1);
-
- super.tearDown();
- }
-
- /**
- * Asserts that two objects are equal. If they are not
- * an AssertionFailedError is thrown with the given message.
- */
- public static void assertEquals(String message, Object expected,
- Object actual) {
- if (Objects.equals(expected, actual)) {
- return;
- }
- chattyFailNotEquals(message, expected, actual);
- }
-
- /**
- * Asserts that two objects are equal. If they are not
- * an AssertionFailedError is thrown.
- */
- public static void assertEquals(Object expected, Object actual) {
- assertEquals(null, expected, actual);
- }
-
- /**
- * Asserts that two Strings are equal.
- */
- public static void assertEquals(String message, String expected, String actual) {
- assertWithMessage(message).that(actual).isEqualTo(expected);
- }
-
- /**
- * Asserts that two Strings are equal.
- */
- public static void assertEquals(String expected, String actual) {
- assertEquals(null, expected, actual);
- }
-
- private static void chattyFailNotEquals(String message, Object expected,
- Object actual) {
- fail(MoreAsserts.chattyFormat(message, expected, actual));
- }
-
- public static void assertNonZeroExitCode(int exitCode, String stdout, String stderr) {
- MoreAsserts.assertNonZeroExitCode(exitCode, stdout, stderr);
- }
-
- public static void assertZeroExitCode(int exitCode, String stdout, String stderr) {
- MoreAsserts.assertExitCode(0, exitCode, stdout, stderr);
- }
-
- public static void assertExitCode(ExitCode expectedExitCode,
- int exitCode, String stdout, String stderr) {
- int expectedExitCodeValue = expectedExitCode.getNumericExitCode();
- if (exitCode != expectedExitCodeValue) {
- fail(String.format("expected exit code '%s' <%d> but exit code was <%d> and stdout was <%s> "
- + "and stderr was <%s>",
- expectedExitCode.name(), expectedExitCodeValue, exitCode, stdout, stderr));
- }
- }
-
- public static void assertExitCode(int expectedExitCode,
- int exitCode, String stdout, String stderr) {
- MoreAsserts.assertExitCode(expectedExitCode, exitCode, stdout, stderr);
- }
-
- public static void assertStdoutContainsString(String expected, String stdout, String stderr) {
- MoreAsserts.assertStdoutContainsString(expected, stdout, stderr);
- }
-
- public static void assertStderrContainsString(String expected, String stdout, String stderr) {
- MoreAsserts.assertStderrContainsString(expected, stdout, stderr);
- }
-
- public static void assertStdoutContainsRegex(String expectedRegex,
- String stdout, String stderr) {
- MoreAsserts.assertStdoutContainsRegex(expectedRegex, stdout, stderr);
- }
-
- public static void assertStderrContainsRegex(String expectedRegex,
- String stdout, String stderr) {
- MoreAsserts.assertStderrContainsRegex(expectedRegex, stdout, stderr);
- }
-
-
-
- /********************************************************************
- * *
- * Other testing utilities (unrelated to "chattiness") *
- * *
- ********************************************************************/
-
- /**
- * Returns the elements from the given collection in a set.
- */
- protected static <T> Set<T> asSet(Iterable<T> collection) {
- return Sets.newHashSet(collection);
- }
-
- /**
- * Returns the arguments given as varargs as a set.
- */
- @SuppressWarnings({"unchecked", "varargs"})
- protected static <T> Set<T> asSet(T... elements) {
- return Sets.newHashSet(elements);
- }
-
- /**
- * An equivalence relation for Collection, based on mapping to Set.
- *
- * Oft-forgotten fact: for all x in Set, y in List, !x.equals(y) even if
- * their elements are the same.
- */
- protected static <T> void
- assertSameContents(Iterable<? extends T> expected, Iterable<? extends T> actual) {
- MoreAsserts.assertSameContents(expected, actual);
- }
-
- /**
- * Asserts the presence or absence of values in the collection.
- */
- protected <T> void assertPresence(Iterable<T> actual, Iterable<Presence<T>> expectedPresences) {
- for (Presence<T> expected : expectedPresences) {
- if (expected.presence) {
- assertThat(actual).contains(expected.value);
- } else {
- assertThat(actual).doesNotContain(expected.value);
- }
- }
- }
-
- /** Creates a presence information with expected value. */
- protected static <T> Presence<T> present(T expected) {
- return new Presence<>(expected, true);
- }
-
- /** Creates an absence information with expected value. */
- protected static <T> Presence<T> absent(T expected) {
- return new Presence<>(expected, false);
- }
-
- /**
- * Combines value with the boolean presence flag.
- *
- * @param <T> value type
- */
- protected final static class Presence <T> {
- /** wrapped value */
- public final T value;
- /** boolean presence flag */
- public final boolean presence;
-
- /** Creates a tuple of value and a boolean presence flag. */
- Presence(T value, boolean presence) {
- this.value = value;
- this.presence = presence;
- }
- }
-
-}
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
index 3302d33f7f..d519e421d6 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
@@ -24,6 +24,8 @@ import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
+import junit.framework.TestCase;
+
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
@@ -31,10 +33,10 @@ import java.util.List;
import java.util.Set;
/**
- * This is a specialization of {@link ChattyAssertsTestCase} that's useful for
- * implementing tests of the "foundation" library.
+ * This is a specialization of {@link TestCase} that's useful for implementing tests of the
+ * "foundation" library.
*/
-public abstract class FoundationTestCase extends ChattyAssertsTestCase {
+public abstract class FoundationTestCase extends TestCase {
protected Path rootDirectory;
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java b/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java
index 9224b8a6ef..8c01655e10 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java
@@ -263,6 +263,10 @@ public class MoreAsserts {
}
}
+ public static void assertZeroExitCode(int exitCode, String stdout, String stderr) {
+ assertExitCode(0, exitCode, stdout, stderr);
+ }
+
public static void assertExitCode(int expectedExitCode,
int exitCode, String stdout, String stderr) {
if (exitCode != expectedExitCode) {