Skip to content

Commit

Permalink
Fix unit test failure with bazel@head (#6188)
Browse files Browse the repository at this point in the history
  • Loading branch information
mai93 committed Mar 14, 2024
1 parent ac9d7c3 commit 78eb3dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.idea.blaze.qsync.QuerySyncTestUtils.REPOSITORY_MAPPED_LABEL_CORRESPONDENCE;
import static com.google.idea.blaze.qsync.QuerySyncTestUtils.LabelIgnoringCanonicalFormat;
import static org.mockito.Mockito.when;

import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -81,10 +82,9 @@ public void getPendingExternalDeps_followJavaDeps_allBuilt() throws Exception {
blazeProject.setCurrent(context, snapshot);
DependencyTrackerImpl dt =
new DependencyTrackerImpl(blazeProject, dependencyBuilder, artifactTracker);
// This version of rules_jvm_external here has to exactly match the version in MODULE.bazel
// Otherwise, this test will fail
String guava = "@@rules_jvm_external~6.0~maven~com_google_guava_guava//jar:jar";
when(artifactTracker.getLiveCachedTargets()).thenReturn(ImmutableSet.of(Label.of(guava)));
LabelIgnoringCanonicalFormat guava = new LabelIgnoringCanonicalFormat("@com_google_guava_guava//jar:jar");
when(artifactTracker.getLiveCachedTargets()).thenReturn(ImmutableSet.of(guava));

assertThat(
dt.getPendingExternalDeps(
ImmutableSet.copyOf(TestData.JAVA_LIBRARY_EXTERNAL_DEP_QUERY.getAssumedLabels())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public static PathPackage of(String path, String pkg) {
}
}

public static class LabelIgnoringCanonicalFormat extends Label {
public LabelIgnoringCanonicalFormat(String label) {
super(label);
}

@Override
public boolean equals(Object that) {
if (!(that instanceof Label)) {
return false;
}
return cleanLabel(this.toString()).equals(cleanLabel(that.toString()));
}
}

/**
* Creates a dummy source jar at the specified destination with a package structure defined by
* {@code pathPackages}
Expand Down

0 comments on commit 78eb3dc

Please sign in to comment.