use of com.google.devtools.build.lib.util.LazyString in project bazel by bazelbuild.
the class FileWriteActionTest method testFileWriteActionWithCompressionDoesNotForceLazyString.
@Test
public void testFileWriteActionWithCompressionDoesNotForceLazyString() throws Exception {
Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt");
final String backingContents = generateLongRandomString();
class ForceCountingLazyString extends LazyString {
public int forced = 0;
@Override
public String toString() {
forced += 1;
return backingContents;
}
}
ForceCountingLazyString contents = new ForceCountingLazyString();
FileWriteAction action = FileWriteAction.create(NULL_ACTION_OWNER, outputArtifact, contents, /*makeExecutable=*/
false, FileWriteAction.Compression.ALLOW);
// The string should only be forced once we actually read it, not when the action is
// constructed.
assertThat(contents.forced).isEqualTo(0);
assertThat(action.getFileContents()).isEqualTo(backingContents);
assertThat(contents.forced).isEqualTo(1);
}
use of com.google.devtools.build.lib.util.LazyString in project bazel by bazelbuild.
the class ProtoCompileActionBuilderTest method outReplacementAreLazilyEvaluated.
@Test
public void outReplacementAreLazilyEvaluated() throws Exception {
final boolean[] hasBeenCalled = new boolean[1];
hasBeenCalled[0] = false;
CharSequence outReplacement = new LazyString() {
@Override
public String toString() {
hasBeenCalled[0] = true;
return "mu";
}
};
ProtoLangToolchainProvider toolchain = ProtoLangToolchainProvider.create("--java_out=param1,param2:$(OUT)", null, /* pluginExecutable */
mock(TransitiveInfoCollection.class), /* runtime */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER));
SupportData supportData = SupportData.create(Predicates.<TransitiveInfoCollection>alwaysFalse(), ImmutableList.<Artifact>of(), NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER), /* protosInDirectDeps */
NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER), true);
CustomCommandLine cmdLine = createCommandLineFromToolchains(ImmutableList.of(new ToolchainInvocation("pluginName", toolchain, outReplacement)), supportData.getDirectProtoSources(), supportData.getTransitiveImports(), supportData.getProtosInDirectDeps(), "//foo:bar", true, /* allowServices */
ImmutableList.<String>of());
assertThat(hasBeenCalled[0]).isFalse();
cmdLine.arguments();
assertThat(hasBeenCalled[0]).isTrue();
}
use of com.google.devtools.build.lib.util.LazyString in project bazel by bazelbuild.
the class FileWriteActionTest method testFileWriteActionWithLazyString.
@Test
public void testFileWriteActionWithLazyString() throws Exception {
Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt");
final String backingString = "Hello world";
LazyString contents = new LazyString() {
@Override
public String toString() {
return backingString;
}
};
FileWriteAction action = FileWriteAction.create(NULL_ACTION_OWNER, outputArtifact, contents, /*makeExecutable=*/
false, FileWriteAction.Compression.DISALLOW);
assertThat(action.getFileContents()).isEqualTo(backingString);
}
Aggregations