Skip to content

Commit

Permalink
Add LoggingContext and use that from ProjectRefresherTest.
Browse files Browse the repository at this point in the history
Makes it easier to debug.

(cherry picked from commit 8090cbd)
  • Loading branch information
Googler authored and mai93 committed May 15, 2023
1 parent 738fc97 commit 84409ff
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions querysync/javatests/com/google/idea/blaze/qsync/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
java_library(
name = "TestUtils",
srcs = [
"LoggingContext.java",
"NoopContext.java",
"QuerySyncTestUtils.java",
],
Expand All @@ -11,6 +12,7 @@ java_library(
"//querysync/javatests/com/google/idea/blaze/qsync/testdata",
"//shared",
"//shared:vcs",
"//third_party/java/flogger",
"@com_google_guava_guava//jar",
],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2023 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.idea.blaze.qsync;

import com.google.common.flogger.GoogleLogger;
import com.google.idea.blaze.common.Output;

public class LoggingContext extends NoopContext {

private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();

@Override
public <T extends Output> void output(T output) {
logger.atInfo().log(output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testStartPartialRefresh_upstreamRevisionChange() {
RefreshOperation update =
createRefresher()
.startPartialRefresh(
QuerySyncTestUtils.NOOP_CONTEXT,
QuerySyncTestUtils.LOGGING_CONTEXT,
project,
Optional.of(new VcsState("2", ImmutableSet.of(), Optional.empty())),
project.projectDefinition());
Expand All @@ -73,7 +73,7 @@ public void testStartPartialRefresh_buildFileAddedThenReverted() {
RefreshOperation update =
createRefresher()
.startPartialRefresh(
QuerySyncTestUtils.NOOP_CONTEXT,
QuerySyncTestUtils.LOGGING_CONTEXT,
project,
Optional.of(new VcsState("1", ImmutableSet.of(), Optional.empty())),
project.projectDefinition());
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testStartPartialRefresh_buildFileDeletedThenReverted() {
RefreshOperation update =
createRefresher()
.startPartialRefresh(
QuerySyncTestUtils.NOOP_CONTEXT,
QuerySyncTestUtils.LOGGING_CONTEXT,
project,
Optional.of(new VcsState("1", ImmutableSet.of(), Optional.empty())),
project.projectDefinition());
Expand Down Expand Up @@ -134,7 +134,7 @@ public void testStartPartialRefresh_buildFileModifiedThenReverted() {
RefreshOperation update =
createRefresher()
.startPartialRefresh(
QuerySyncTestUtils.NOOP_CONTEXT,
QuerySyncTestUtils.LOGGING_CONTEXT,
project,
Optional.of(new VcsState("1", ImmutableSet.of(), Optional.empty())),
project.projectDefinition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ private QuerySyncTestUtils() {}

public static final Context<?> NOOP_CONTEXT = new NoopContext();

public static final Context<?> LOGGING_CONTEXT = new LoggingContext();

public static final PackageReader EMPTY_PACKAGE_READER = p -> "";

public static final Optional<VcsState> CLEAN_VCS_STATE =
Expand Down
5 changes: 5 additions & 0 deletions shared/java/com/google/idea/blaze/common/PrintOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public String getText() {
return text;
}

@Override
public String toString() {
return getText();
}

@Nonnull
public OutputType getOutputType() {
return outputType;
Expand Down

0 comments on commit 84409ff

Please sign in to comment.