diff options
author | 2017-12-15 11:30:04 -0800 | |
---|---|---|
committer | 2017-12-15 11:32:02 -0800 | |
commit | c4071e8b634440cf873b719dd948b8777b03f50e (patch) | |
tree | 1a6585f7411d820fda0e14c4b02825c85e566fcb /src/test/java/com | |
parent | c8201d4f94a9df581fe5e94b90b3d57ac3792c4a (diff) |
Don't suggest using bazel clean --async when it's unsupported
Fixes #4176 (https://github.com/bazelbuild/bazel/issues/4176).
Closes #4236.
PiperOrigin-RevId: 179218605
Diffstat (limited to 'src/test/java/com')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/BUILD | 5 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/runtime/commands/CleanCommandRecommendsAsyncTest.java | 116 |
2 files changed, 120 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD index e947617222..d1c037f016 100644 --- a/src/test/java/com/google/devtools/build/lib/BUILD +++ b/src/test/java/com/google/devtools/build/lib/BUILD @@ -1031,7 +1031,10 @@ java_test( java_test( name = "runtime-tests", - srcs = glob(["runtime/*.java"]), + srcs = glob([ + "runtime/*.java", + "runtime/commands/*.java", + ]), test_class = "com.google.devtools.build.lib.AllTests", deps = [ ":foundations_testutil", diff --git a/src/test/java/com/google/devtools/build/lib/runtime/commands/CleanCommandRecommendsAsyncTest.java b/src/test/java/com/google/devtools/build/lib/runtime/commands/CleanCommandRecommendsAsyncTest.java new file mode 100644 index 0000000000..bfa2b907de --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/runtime/commands/CleanCommandRecommendsAsyncTest.java @@ -0,0 +1,116 @@ +// Copyright 2017 The Bazel Authors. 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.runtime.commands; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.BlazeDirectories; +import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; +import com.google.devtools.build.lib.analysis.ServerDirectories; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; +import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher; +import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.LockingMode; +import com.google.devtools.build.lib.runtime.BlazeModule; +import com.google.devtools.build.lib.runtime.BlazeRuntime; +import com.google.devtools.build.lib.runtime.BlazeServerStartupOptions; +import com.google.devtools.build.lib.testutil.Scratch; +import com.google.devtools.build.lib.testutil.TestConstants; +import com.google.devtools.build.lib.util.OS; +import com.google.devtools.build.lib.util.io.RecordingOutErr; +import com.google.devtools.common.options.OptionsParser; +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** Tests {@link CleanCommand}'s recommendation of the --async flag. */ +@RunWith(Parameterized.class) +public class CleanCommandRecommendsAsyncTest { + + private final RecordingOutErr outErr = new RecordingOutErr(); + private final List<String> commandLine; + private final OS os; + private final boolean expectSuggestion; + private static final String EXPECTED_SUGGESTION = "Consider using --async"; + + public CleanCommandRecommendsAsyncTest(List<String> commandLine, OS os, boolean expectSuggestion) + throws Exception { + this.commandLine = commandLine; + this.os = os; + this.expectSuggestion = expectSuggestion; + } + + @Parameters(name = "Command line {0} on OS {1}") + public static Iterable<Object[]> data() { + return Arrays.asList( + new Object[][] { + // When --async is provided, don't expect --async to be suggested. + {ImmutableList.of("clean", "--async"), OS.LINUX, false}, + {ImmutableList.of("clean", "--async"), OS.WINDOWS, false}, + {ImmutableList.of("clean", "--async"), OS.DARWIN, false}, + + // When --async is not provided, expect the suggestion on platforms that support it. + {ImmutableList.of("clean"), OS.LINUX, true}, + {ImmutableList.of("clean"), OS.WINDOWS, false}, + {ImmutableList.of("clean"), OS.DARWIN, false}, + + // When --noasync is explicitly provided, unfortunately we still expect the suggestion, + // since there's no way to tell the difference between false-by-default and explicit + // false. + {ImmutableList.of("clean", "--noasync"), OS.LINUX, true}, + }); + } + + @Test + public void testCleanProvidesExpectedSuggestion() throws Exception { + String productName = TestConstants.PRODUCT_NAME; + Scratch scratch = new Scratch(); + ServerDirectories serverDirectories = + new ServerDirectories(scratch.dir("install"), scratch.dir("output")); + BlazeRuntime runtime = + new BlazeRuntime.Builder() + .setFileSystem(scratch.getFileSystem()) + .setProductName(productName) + .setServerDirectories(serverDirectories) + .setStartupOptionsProvider( + OptionsParser.newOptionsParser(BlazeServerStartupOptions.class)) + .addBlazeModule( + new BlazeModule() { + @Override + public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) { + // We must add these options so that the defaults package can be created. + builder.addConfigurationOptions(BuildConfiguration.Options.class); + // The tools repository is needed for createGlobals + builder.setToolsRepository(TestConstants.TOOLS_REPOSITORY); + } + }) + .build(); + BlazeDirectories directories = + new BlazeDirectories(serverDirectories, scratch.dir("workspace"), productName); + runtime.initWorkspace(directories, /* binTools= */ null); + + BlazeCommandDispatcher dispatcher = new BlazeCommandDispatcher(runtime, new CleanCommand(os)); + dispatcher.exec(commandLine, LockingMode.ERROR_OUT, "test", outErr); + String output = outErr.toString(); + + if (expectSuggestion) { + assertThat(output).contains(EXPECTED_SUGGESTION); + } else { + assertThat(output).doesNotContain(EXPECTED_SUGGESTION); + } + } +} |