aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar laszlocsomor <laszlocsomor@google.com>2017-07-18 16:30:36 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-07-19 10:19:37 +0200
commitf4aeaedb5f72f234711813b84e214c1edd94d643 (patch)
tree8fe44da60d732e153eee8fa14428f6426cedf9a3 /src/test/java/com
parent672510ebbace33eb62ac36b0f9985e6f696b6c9e (diff)
CustomCommandLine: add emptiness checks
This is a semantic roll-forward of https://github.com/bazelbuild/bazel/commit/a76c94be7c56b93fc5a2f9ececfba7ac1f61f69c which was rolled back in https://github.com/bazelbuild/bazel/commit/33cd68e18f554b98194b4ce924580d3333ab9217 due to memory regressions. In this commit: - add @Nullable annotations to CustomCommandLine.Builder.add* methods where it makes sense - add Preconditions.checkNotNull for non-nullable arguments - add emptiness checks for Iterables in add(String, Iterable) style methods, to avoid adding the argument when the Iterable is empty and so the argument would not be followed by any values RELNOTES: none PiperOrigin-RevId: 162349842
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java105
1 files changed, 98 insertions, 7 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
index ea061beb2d..d0eb08e2c1 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
@@ -18,6 +18,7 @@ import static org.junit.Assert.fail;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
+import com.google.common.testing.NullPointerTester;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType;
@@ -187,13 +188,103 @@ public class CustomCommandLineTest {
}
@Test
- public void testAddNulls() {
- CustomCommandLine cl = CustomCommandLine.builder()
- .add("--args", null)
- .addExecPaths(null, ImmutableList.of(artifact1))
- .addExecPath(null, null)
- .build();
- assertThat(cl.arguments()).isEqualTo(ImmutableList.of());
+ public void testAddNulls() throws Exception {
+ Artifact treeArtifact = createTreeArtifact("myTreeArtifact");
+ assertThat(treeArtifact).isNotNull();
+
+ CustomCommandLine cl =
+ CustomCommandLine.builder()
+ .add((CharSequence) null)
+ .add((Label) null)
+ .add("foo", null)
+ .add("foo", ImmutableList.of())
+ .add((Iterable<String>) null)
+ .add(ImmutableList.<String>of())
+ .addExecPath("foo", null)
+ .addExecPaths("foo", (Iterable<Artifact>) null)
+ .addExecPaths("foo", ImmutableList.<Artifact>of())
+ .addExecPaths(null)
+ .addExecPaths(ImmutableList.of())
+ .addPlaceholderTreeArtifactExecPath("foo", null)
+ .addJoinStrings("foo", "bar", null)
+ .addJoinStrings("foo", "bar", ImmutableList.of())
+ .addJoinValues("foo", "bar", null, String::toString)
+ .addJoinValues("foo", "bar", ImmutableList.of(), String::toString)
+ .addJoinExecPaths("foo", "bar", null)
+ .addJoinExecPaths("foo", "bar", ImmutableList.of())
+ .addPath(null)
+ .addPlaceholderTreeArtifactFormattedExecPath("foo", null)
+ .addJoinPaths("foo", null)
+ .addJoinPaths("foo", ImmutableList.of())
+ .addBeforeEachPath("foo", null)
+ .addBeforeEachPath("foo", ImmutableList.of())
+ .addBeforeEach("foo", null)
+ .addBeforeEach("foo", ImmutableList.of())
+ .addBeforeEachExecPath("foo", null)
+ .addBeforeEachExecPath("foo", ImmutableList.of())
+ .addFormatEach("%s", null)
+ .addFormatEach("%s", ImmutableList.of())
+ .add((CustomArgv) null)
+ .add((CustomMultiArgv) null)
+ .build();
+ assertThat(cl.arguments()).isEmpty();
+
+ assertThat(
+ CustomCommandLine.builder()
+ .addPaths("foo")
+ .addPaths("bar", (PathFragment[]) null)
+ .addPaths("baz", new PathFragment[0])
+ .build()
+ .arguments())
+ .containsExactly("foo", "baz")
+ .inOrder();
+
+ CustomCommandLine.Builder obj = CustomCommandLine.builder();
+ Class<CustomCommandLine.Builder> clazz = CustomCommandLine.Builder.class;
+ NullPointerTester npt =
+ new NullPointerTester()
+ .setDefault(Artifact.class, artifact1)
+ .setDefault(String.class, "foo")
+ .setDefault(PathFragment[].class, new PathFragment[] {PathFragment.create("foo")});
+
+ npt.testMethod(obj, clazz.getMethod("add", String.class, Iterable.class));
+ npt.testMethod(obj, clazz.getMethod("addExecPath", String.class, Artifact.class));
+ npt.testMethod(obj, clazz.getMethod("addExecPaths", String.class, Iterable.class));
+ npt.testMethod(
+ obj, clazz.getMethod("addPlaceholderTreeArtifactExecPath", String.class, Artifact.class));
+ npt.testMethod(
+ obj,
+ clazz.getMethod(
+ "addPlaceholderTreeArtifactFormattedExecPath", String.class, Artifact.class));
+ npt.testMethod(obj, clazz.getMethod("addParamFile", String.class, Artifact.class));
+ npt.testMethod(obj, clazz.getMethod("addPaths", String.class, PathFragment[].class));
+ npt.testMethod(
+ obj, clazz.getMethod("addJoinExpandedTreeArtifactExecPath", String.class, Artifact.class));
+ npt.testMethod(obj, clazz.getMethod("addExpandedTreeArtifactExecPaths", Artifact.class));
+
+ npt.setDefault(Iterable.class, ImmutableList.of("foo"));
+ npt.testMethod(
+ obj, clazz.getMethod("addJoinStrings", String.class, String.class, Iterable.class));
+ npt.testMethod(
+ obj,
+ clazz.getMethod(
+ "addJoinValues", String.class, String.class, Iterable.class, Function.class));
+ npt.testMethod(obj, clazz.getMethod("addBeforeEach", String.class, Iterable.class));
+ npt.testMethod(obj, clazz.getMethod("addFormatEach", String.class, Iterable.class));
+
+ npt.setDefault(Iterable.class, ImmutableList.of(artifact1));
+ npt.testMethod(
+ obj, clazz.getMethod("addJoinExecPaths", String.class, String.class, Iterable.class));
+ npt.testMethod(obj, clazz.getMethod("addBeforeEachExecPath", String.class, Iterable.class));
+
+ npt.setDefault(Iterable.class, ImmutableList.of(PathFragment.create("foo")));
+ npt.testMethod(obj, clazz.getMethod("addJoinPaths", String.class, Iterable.class));
+ npt.testMethod(obj, clazz.getMethod("addBeforeEachPath", String.class, Iterable.class));
+
+ npt.setDefault(Artifact.class, treeArtifact);
+ npt.testMethod(
+ obj, clazz.getMethod("addJoinExpandedTreeArtifactExecPath", String.class, Artifact.class));
+ npt.testMethod(obj, clazz.getMethod("addExpandedTreeArtifactExecPaths", Artifact.class));
}
@Test