From a904b85376251775d58852a0e8480c0db032bac8 Mon Sep 17 00:00:00 2001 From: tomlu Date: Thu, 1 Feb 2018 07:21:27 -0800 Subject: Allow CustomCommandLine's mapFn to expand each object into multiple items. This is needed to migrate JavaCompileAction away from CustomMultiArgv. PiperOrigin-RevId: 184136486 --- .../build/lib/actions/CustomCommandLineTest.java | 71 +++++++++++++++------- 1 file changed, 48 insertions(+), 23 deletions(-) (limited to 'src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java') 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 args) { + args.accept(foo.str); } } } -- cgit v1.2.3