Skip to content

Commit

Permalink
Fix tests execution
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoader committed Aug 30, 2024
1 parent 4cdfa88 commit b325547
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.idea.blaze.base.bazel.BuildSystemProvider;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.ExternalWorkspaceData;
import com.google.idea.blaze.base.model.primitives.ExternalWorkspace;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.model.primitives.TargetName;
Expand All @@ -37,7 +36,6 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -213,7 +211,7 @@ private static synchronized WorkspaceRoot getExternalWorkspaceRootsFile(String w
return workspaceRootCache.get(workspaceName);
}

BlazeProjectData blazeProjectData = getBlazeProjectData(project);
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData != null) {
File workspaceDir = new File(blazeProjectData.getBlazeInfo().getOutputBase(), "external/" + workspaceName);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.idea.blaze.base.lang.buildfile.references;

import com.google.common.collect.ImmutableList;
import com.google.idea.blaze.base.ExternalWorkspaceFixture;
import com.google.idea.blaze.base.lang.buildfile.BuildFileIntegrationTestCase;
import com.google.idea.blaze.base.lang.buildfile.psi.BuildFile;
import com.google.idea.blaze.base.model.ExternalWorkspaceData;
Expand All @@ -18,17 +19,23 @@
import static org.junit.Assert.assertNotNull;

@RunWith(JUnit4.class)
public class ModuleRepositoryCompletionTest extends BuildFileIntegrationTestCase {
public class ModuleRepositoryReferenceTest extends BuildFileIntegrationTestCase {

final ExternalWorkspaceFixture unmappedWorkspace =
new ExternalWorkspaceFixture(ExternalWorkspace.create("workspace_one", "workspace_one"));

final ExternalWorkspaceFixture remappedWorkspace =
new ExternalWorkspaceFixture(ExternalWorkspace.create("workspace_one", "com_workspace_one"));
protected ExternalWorkspaceFixture unmappedWorkspace;
protected ExternalWorkspaceFixture remappedWorkspace;

@Override
protected ExternalWorkspaceData mockExternalWorkspaceData() {
return ExternalWorkspaceData.create(ImmutableList.of(unmappedWorkspace.workspace, remappedWorkspace.workspace));
System.out.println("mockExternalWorkspaceData called");
new Exception().printStackTrace();
unmappedWorkspace = new ExternalWorkspaceFixture(
ExternalWorkspace.create("workspace_one", "workspace_one"), fileSystem);

remappedWorkspace = new ExternalWorkspaceFixture(
ExternalWorkspace.create("workspace_two", "com_workspace_two"), fileSystem);

return ExternalWorkspaceData.create(
ImmutableList.of(unmappedWorkspace.workspace, remappedWorkspace.workspace));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.google.idea.blaze.base;

import com.google.idea.blaze.base.lang.buildfile.psi.BuildFile;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.primitives.ExternalWorkspace;
import com.google.idea.blaze.base.model.primitives.WorkspacePath;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
import com.intellij.psi.PsiFile;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

import static com.google.common.truth.Truth.assertThat;
import static com.google.idea.blaze.base.settings.ui.ProjectViewUi.getProject;
import static org.junit.Assert.assertNotNull;

public class ExternalWorkspaceFixture {
public final ExternalWorkspace workspace;

final TestFileSystem fileSystem;
WorkspaceFileSystem workspaceFileSystem;

public ExternalWorkspaceFixture(ExternalWorkspace workspace, TestFileSystem fileSystem) {
this.workspace = workspace;
this.fileSystem = fileSystem;
}

public WorkspaceRoot getWorkspaceRoot() {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();

File outputBase = blazeProjectData.getBlazeInfo().getOutputBase();

Path workspaceRootPath = Paths.get(
blazeProjectData.getBlazeInfo().getOutputBase().getAbsolutePath(),
"external", workspace.name());

return new WorkspaceRoot(workspaceRootPath.normalize().toFile());
}

public BuildFile createBuildFile(WorkspacePath workspacePath, String... contentLines) {
PsiFile file = getWorkspaceFileSystem().createPsiFile(workspacePath, contentLines);
assertThat(file).isInstanceOf(BuildFile.class);
return (BuildFile) file;
}

WorkspaceFileSystem getWorkspaceFileSystem() {
if (workspaceFileSystem == null) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertNotNull(blazeProjectData);

File outputBase = blazeProjectData.getBlazeInfo().getOutputBase();


WorkspaceRoot workspaceRoot = new WorkspaceRoot(Paths.get(
blazeProjectData.getBlazeInfo().getOutputBase().getAbsolutePath(),
"external", workspace.name()).normalize().toFile());

File workspaceRootFile = workspaceRoot.directory();
assertThat(workspaceRootFile).isNotNull();
workspaceFileSystem = new WorkspaceFileSystem(workspaceRoot, fileSystem);
}

return workspaceFileSystem;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,22 @@
*/
package com.google.idea.blaze.base.lang.buildfile;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNotNull;

import com.google.common.base.Joiner;
import com.google.idea.blaze.base.BlazeIntegrationTestCase;
import com.google.idea.blaze.base.EditorTestHelper;
import com.google.idea.blaze.base.WorkspaceFileSystem;
import com.google.idea.blaze.base.lang.buildfile.psi.BuildFile;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.ExternalWorkspaceData;
import com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder;
import com.google.idea.blaze.base.model.MockBlazeProjectDataManager;
import com.google.idea.blaze.base.model.primitives.ExternalWorkspace;
import com.google.idea.blaze.base.model.primitives.WorkspacePath;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import org.junit.Before;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.junit.Before;
import static com.google.common.truth.Truth.assertThat;

/** BUILD file specific integration test base */
public abstract class BuildFileIntegrationTestCase extends BlazeIntegrationTestCase {
Expand Down Expand Up @@ -84,50 +75,4 @@ protected void assertFileContents(PsiFile file, List<String> contentLines) {
String contents = Joiner.on('\n').join(contentLines);
assertThat(file.getText()).isEqualTo(contents);
}

protected final class ExternalWorkspaceFixture {
public final ExternalWorkspace workspace;
WorkspaceFileSystem workspaceFileSystem;

public ExternalWorkspaceFixture(ExternalWorkspace workspace) {
this.workspace = workspace;
}

WorkspaceFileSystem getWorkspaceFileSystem() {
if (workspaceFileSystem == null) {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertNotNull(blazeProjectData);

File outputBase = blazeProjectData.getBlazeInfo().getOutputBase();
WorkspaceRoot workspaceRoot = new WorkspaceRoot(Paths.get(
blazeProjectData.getBlazeInfo().getOutputBase().getAbsolutePath(),
"external", workspace.name()).normalize().toFile());

File workspaceRootFile = workspaceRoot.directory();
assertThat(workspaceRootFile).isNotNull();
workspaceFileSystem = new WorkspaceFileSystem(workspaceRoot, BuildFileIntegrationTestCase.this.fileSystem);
}

return workspaceFileSystem;
}

public WorkspaceRoot getWorkspaceRoot() {
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();

File outputBase = blazeProjectData.getBlazeInfo().getOutputBase();

Path workspaceRootPath = Paths.get(
blazeProjectData.getBlazeInfo().getOutputBase().getAbsolutePath(),
"external", workspace.name());

return new WorkspaceRoot(workspaceRootPath.normalize().toFile());
}

public BuildFile createBuildFile(WorkspacePath workspacePath, String... contentLines) {
PsiFile file = getWorkspaceFileSystem().createPsiFile(workspacePath, contentLines);
assertThat(file).isInstanceOf(BuildFile.class);
return (BuildFile) file;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public MockBlazeProjectDataBuilder setWorkspaceLanguageSettings(
}

@CanIgnoreReturnValue
public MockBlazeProjectDataBuilder setExternalWorkspaceData(ExternalWorkspaceData externalWorkspaceData) {
public MockBlazeProjectDataBuilder setExternalWorkspaceData(
ExternalWorkspaceData externalWorkspaceData) {
this.externalWorkspaceData = externalWorkspaceData;
return this;
}
Expand Down

0 comments on commit b325547

Please sign in to comment.