aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-02-01 07:21:27 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-01 07:23:16 -0800
commita904b85376251775d58852a0e8480c0db032bac8 (patch)
tree83e846c6cfebee7259f093661e9313d4fc9338f8 /src/test/java/com/google/devtools/build
parent5a50a7c403e567b850d5037d1ee0dad96be0b39d (diff)
Allow CustomCommandLine's mapFn to expand each object into multiple items.
This is needed to migrate JavaCompileAction away from CustomMultiArgv. PiperOrigin-RevId: 184136486
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java71
-rw-r--r--src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetFingerprintCacheTest.java32
2 files changed, 65 insertions, 38 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 7e514bd37f..9e4b9389bc 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
@@ -37,6 +37,7 @@ import com.google.devtools.build.lib.vfs.Root;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.function.Consumer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -173,14 +174,14 @@ public class CustomCommandLineTest {
.inOrder();
assertThat(
builder()
- .addAll(VectorArg.of(list(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll(VectorArg.of(list(foo("1"), foo("2"))).mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("1", "2")
.inOrder();
assertThat(
builder()
- .addAll(VectorArg.of(nestedSet(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll(VectorArg.of(nestedSet(foo("1"), foo("2"))).mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("1", "2")
@@ -215,14 +216,15 @@ public class CustomCommandLineTest {
.inOrder();
assertThat(
builder()
- .addAll("--arg", VectorArg.of(list(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll("--arg", VectorArg.of(list(foo("1"), foo("2"))).mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "1", "2")
.inOrder();
assertThat(
builder()
- .addAll("--arg", VectorArg.of(nestedSet(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll(
+ "--arg", VectorArg.of(nestedSet(foo("1"), foo("2"))).mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "1", "2")
@@ -276,14 +278,17 @@ public class CustomCommandLineTest {
.inOrder();
assertThat(
builder()
- .addAll(VectorArg.join(":").each(list(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll(VectorArg.join(":").each(list(foo("1"), foo("2"))).mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("1:2")
.inOrder();
assertThat(
builder()
- .addAll(VectorArg.join(":").each(nestedSet(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll(
+ VectorArg.join(":")
+ .each(nestedSet(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("1:2")
@@ -341,7 +346,8 @@ public class CustomCommandLineTest {
assertThat(
builder()
.addAll(
- "--arg", VectorArg.join(":").each(list(foo("1"), foo("2"))).mapped(Foo::str))
+ "--arg",
+ VectorArg.join(":").each(list(foo("1"), foo("2"))).mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "1:2")
@@ -350,7 +356,9 @@ public class CustomCommandLineTest {
builder()
.addAll(
"--arg",
- VectorArg.join(":").each(nestedSet(foo("1"), foo("2"))).mapped(Foo::str))
+ VectorArg.join(":")
+ .each(nestedSet(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "1:2")
@@ -408,7 +416,10 @@ public class CustomCommandLineTest {
.inOrder();
assertThat(
builder()
- .addAll(VectorArg.format("-D%s").each(list(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll(
+ VectorArg.format("-D%s")
+ .each(list(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D1", "-D2")
@@ -416,7 +427,9 @@ public class CustomCommandLineTest {
assertThat(
builder()
.addAll(
- VectorArg.format("-D%s").each(nestedSet(foo("1"), foo("2"))).mapped(Foo::str))
+ VectorArg.format("-D%s")
+ .each(nestedSet(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D1", "-D2")
@@ -476,7 +489,9 @@ public class CustomCommandLineTest {
builder()
.addAll(
"--arg",
- VectorArg.format("-D%s").each(list(foo("1"), foo("2"))).mapped(Foo::str))
+ VectorArg.format("-D%s")
+ .each(list(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "-D1", "-D2")
@@ -485,7 +500,9 @@ public class CustomCommandLineTest {
builder()
.addAll(
"--arg",
- VectorArg.format("-D%s").each(nestedSet(foo("1"), foo("2"))).mapped(Foo::str))
+ VectorArg.format("-D%s")
+ .each(nestedSet(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "-D1", "-D2")
@@ -550,7 +567,7 @@ public class CustomCommandLineTest {
VectorArg.format("-D%s")
.join(":")
.each(list(foo("1"), foo("2")))
- .mapped(Foo::str))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D1:-D2")
@@ -561,7 +578,7 @@ public class CustomCommandLineTest {
VectorArg.format("-D%s")
.join(":")
.each(nestedSet(foo("1"), foo("2")))
- .mapped(Foo::str))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D1:-D2")
@@ -628,7 +645,7 @@ public class CustomCommandLineTest {
VectorArg.format("-D%s")
.join(":")
.each(list(foo("1"), foo("2")))
- .mapped(Foo::str))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "-D1:-D2")
@@ -640,7 +657,7 @@ public class CustomCommandLineTest {
VectorArg.format("-D%s")
.join(":")
.each(nestedSet(foo("1"), foo("2")))
- .mapped(Foo::str))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("--arg", "-D1:-D2")
@@ -698,7 +715,10 @@ public class CustomCommandLineTest {
.inOrder();
assertThat(
builder()
- .addAll(VectorArg.addBefore("-D").each(list(foo("1"), foo("2"))).mapped(Foo::str))
+ .addAll(
+ VectorArg.addBefore("-D")
+ .each(list(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D", "1", "-D", "2")
@@ -706,7 +726,9 @@ public class CustomCommandLineTest {
assertThat(
builder()
.addAll(
- VectorArg.addBefore("-D").each(nestedSet(foo("1"), foo("2"))).mapped(Foo::str))
+ VectorArg.addBefore("-D")
+ .each(nestedSet(foo("1"), foo("2")))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D", "1", "-D", "2")
@@ -772,7 +794,7 @@ public class CustomCommandLineTest {
VectorArg.addBefore("-D")
.format("D%s")
.each(list(foo("1"), foo("2")))
- .mapped(Foo::str))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D", "D1", "-D", "D2")
@@ -783,7 +805,7 @@ public class CustomCommandLineTest {
VectorArg.addBefore("-D")
.format("D%s")
.each(nestedSet(foo("1"), foo("2")))
- .mapped(Foo::str))
+ .mapped(Foo::expandToStr))
.build()
.arguments())
.containsExactly("-D", "D1", "-D", "D2")
@@ -915,7 +937,10 @@ public class CustomCommandLineTest {
.add(builder().addAll(VectorArg.addBefore("--foo=%s").each(values)).build())
.add(builder().addAll(VectorArg.join("--foo=%s").each(values)).build())
.add(builder().addAll(VectorArg.format("--foo=%s").each(values)).build())
- .add(builder().addAll(VectorArg.of(values).mapped(s -> s + "_mapped")).build())
+ .add(
+ builder()
+ .addAll(VectorArg.of(values).mapped((s, args) -> args.accept(s + "_mapped")))
+ .build())
.build();
// Ensure all these command lines have distinct keys
@@ -992,8 +1017,8 @@ public class CustomCommandLineTest {
this.str = str;
}
- static String str(Foo foo) {
- return foo.str;
+ static void expandToStr(Foo foo, Consumer<String> args) {
+ args.accept(foo.str);
}
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetFingerprintCacheTest.java b/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetFingerprintCacheTest.java
index 99bc4bbd9c..feba06b6bd 100644
--- a/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetFingerprintCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetFingerprintCacheTest.java
@@ -23,6 +23,7 @@ import com.google.devtools.build.lib.analysis.actions.CommandLineItem.CapturingM
import com.google.devtools.build.lib.analysis.actions.CommandLineItem.MapFn;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.util.Fingerprint;
+import java.util.function.Consumer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -102,7 +103,7 @@ public class NestedSetFingerprintCacheTest {
cache.addNestedSetToFingerprint(
CommandLineItem.MapFn.DEFAULT, explicitDefaultMapFnFingerprint, a);
Fingerprint mappedFingerprint = new Fingerprint();
- cache.addNestedSetToFingerprint(s -> s + "_mapped", mappedFingerprint, a);
+ cache.addNestedSetToFingerprint((s, args) -> args.accept(s + "_mapped"), mappedFingerprint, a);
String defaultMapFnDigest = defaultMapFnFingerprint.hexDigestAndReset();
String explicitDefaultMapFnDigest = explicitDefaultMapFnFingerprint.hexDigestAndReset();
@@ -124,24 +125,25 @@ public class NestedSetFingerprintCacheTest {
// Make sure a normal method reference doesn't get blacklisted.
for (int i = 0; i < 2; ++i) {
cache.addNestedSetToFingerprint(
- NestedSetFingerprintCacheTest::simpleMapFn, new Fingerprint(), nestedSet);
+ NestedSetFingerprintCacheTest::simpleExpand, new Fingerprint(), nestedSet);
}
// Try again to make sure Java synthesizes a new class for a second method reference.
for (int i = 0; i < 2; ++i) {
cache.addNestedSetToFingerprint(
- NestedSetFingerprintCacheTest::simpleMapFn2, new Fingerprint(), nestedSet);
+ NestedSetFingerprintCacheTest::simpleExpand2, new Fingerprint(), nestedSet);
}
// Make sure a non-capturing lambda doesn't get blacklisted
for (int i = 0; i < 2; ++i) {
- cache.addNestedSetToFingerprint(s -> s + "_mapped", new Fingerprint(), nestedSet);
+ cache.addNestedSetToFingerprint(
+ (s, args) -> args.accept(s + "_mapped"), new Fingerprint(), nestedSet);
}
// Make sure a CapturingMapFn doesn't get blacklisted
for (int i = 0; i < 2; ++i) {
cache.addNestedSetToFingerprint(
- (CapturingMapFn<String>) object -> object, new Fingerprint(), nestedSet);
+ (CapturingMapFn<String>) (s, args) -> args.accept(s + 1), new Fingerprint(), nestedSet);
}
// Make sure a ParametrizedMapFn doesn't get blacklisted until it exceeds its instance count
@@ -159,7 +161,7 @@ public class NestedSetFingerprintCacheTest {
() -> {
for (int i = 0; i < 2; ++i) {
StringJoiner str = new StringJoiner("hello");
- cache.addNestedSetToFingerprint(str::join, new Fingerprint(), nestedSet);
+ cache.addNestedSetToFingerprint(str::expand, new Fingerprint(), nestedSet);
}
});
@@ -170,7 +172,7 @@ public class NestedSetFingerprintCacheTest {
for (int i = 0; i < 2; ++i) {
final int capturedVariable = i;
cache.addNestedSetToFingerprint(
- s -> s + capturedVariable, new Fingerprint(), nestedSet);
+ (s, args) -> args.accept(s + capturedVariable), new Fingerprint(), nestedSet);
}
});
}
@@ -183,8 +185,8 @@ public class NestedSetFingerprintCacheTest {
}
@Override
- public String expandToCommandLine(String object) {
- return object + i;
+ public void expandToCommandLine(String object, Consumer<String> args) {
+ args.accept(object + i);
}
@Override
@@ -217,16 +219,16 @@ public class NestedSetFingerprintCacheTest {
this.str = str;
}
- private String join(String other) {
- return str + other;
+ private void expand(String other, Consumer<String> args) {
+ args.accept(str + other);
}
}
- private static String simpleMapFn(String o) {
- return o + "_mapped";
+ private static void simpleExpand(String o, Consumer<String> args) {
+ args.accept(o + "_mapped");
}
- private static String simpleMapFn2(String o) {
- return o + "_mapped2";
+ private static void simpleExpand2(String o, Consumer<String> args) {
+ args.accept(o + "_mapped2");
}
}