Skip to content

Commit

Permalink
Add black box test for package loading cached by benign workspace change
Browse files Browse the repository at this point in the history
- similar to loading_phase_test.sh test_no_package_loading_on_benign_workspace_file_changes

Closes #7765.

PiperOrigin-RevId: 239355718
  • Loading branch information
irengrig authored and copybara-github committed Mar 20, 2019
1 parent 8b72ef9 commit 973542e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ public ProcessResult build(String... args) throws Exception {
return runBinary("build", args);
}

/**
* Runs <code>bazel query &lt;args&gt;</code> and returns the result. Asserts that the process
* exit code is zero. Does not assert that the error stream is empty.
*
* @param args arguments to pass to query command
* @return ProcessResult with process exit code, strings with stdout and error streams contents
* @throws TimeoutException in case of timeout
* @throws IOException in case of the process startup/interaction problems
* @throws InterruptedException if the current thread is interrupted while waiting
* @throws ProcessRunnerException if the process return code is not zero or error stream is not
* empty when it was expected
*/
public ProcessResult query(String... args) throws Exception {
return runBinary("query", args);
}

/**
* Runs <code>bazel run &lt;args&gt;</code> and returns the result. Asserts that the process exit
* code is zero. Does not assert that the error stream is empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.devtools.build.lib.blackbox.framework.BuilderRunner;
import com.google.devtools.build.lib.blackbox.framework.PathUtils;
import com.google.devtools.build.lib.blackbox.framework.ProcessResult;
import com.google.devtools.build.lib.blackbox.junit.AbstractBlackBoxTest;
import com.google.devtools.build.lib.util.OS;
import java.nio.file.Files;
Expand Down Expand Up @@ -183,6 +184,39 @@ public void testWorkspaceChanges() throws Exception {
WorkspaceTestUtils.assertLinesExactly(xPath, "bye");
}

@Test
public void testNoPackageLoadingOnBenignWorkspaceChanges() throws Exception {
Path repo = context().getTmpDir().resolve(testName.getMethodName());
new RepoWithRuleWritingTextGenerator(repo).withOutputText("hi").setupRepository();

context()
.write(
WORKSPACE,
String.format(
"local_repository(name = 'ext', path = '%s',)",
PathUtils.pathForStarlarkFile(repo)));

BuilderRunner bazel =
WorkspaceTestUtils.bazel(context())
// This combination of flags ensures all progress events get into stdout
// and Bazel recognizes that there is a terminal, so progress events will be displayed
.withFlags("--experimental_ui_debug_all_events", "--curses=yes");

final String progressMessage = "PROGRESS <no location>: Loading package: @ext//";

ProcessResult result = bazel.query("@ext//:all");
assertThat(result.outString()).contains(progressMessage);

result = bazel.query("@ext//:all");
assertThat(result.outString()).doesNotContain(progressMessage);

Path workspaceFile = context().getWorkDir().resolve(WORKSPACE);
PathUtils.append(workspaceFile, "# comment");

result = bazel.query("@ext//:all");
assertThat(result.outString()).doesNotContain(progressMessage);
}

@Test
public void testPathWithSpace() throws Exception {
context().write("a b/WORKSPACE");
Expand Down

0 comments on commit 973542e

Please sign in to comment.