Skip to content

Commit

Permalink
added psw status to simple integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
LeFrosch committed Nov 4, 2024
1 parent fc28246 commit c2906ad
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
8 changes: 2 additions & 6 deletions clwb/src/META-INF/clwb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<programRunner implementation="com.google.idea.blaze.clwb.run.BlazeCppRunner"/>

<postStartupActivity implementation="com.google.idea.blaze.plugin.ClwbProjectSpecificInitializer"/>

<editorNotificationProvider implementation="com.google.idea.blaze.clwb.BazelCNotificationProvider"/>
<moduleType id="BLAZE_CPP_MODULE" implementationClass="com.google.idea.blaze.clwb.BlazeCppModuleType"/>
<postStartupActivity implementation="com.google.idea.blaze.clwb.run.producers.NonBlazeProducerSuppressor"/>
Expand All @@ -48,10 +50,4 @@
<CppSupportChecker implementation="com.google.idea.blaze.clwb.ClwbSupportsCpp" />
<CppEnvironmentProvider implementation="com.google.idea.blaze.clwb.MSVCEnvironmentProvider" />
</extensions>

<project-components>
<component>
<implementation-class>com.google.idea.blaze.plugin.ClwbProjectSpecificInitializer</implementation-class>
</component>
</project-components>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
package com.google.idea.blaze.plugin;

import com.google.idea.blaze.clwb.CLionNotificationProvider;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;

/** Runs on project startup, and customizes CLion UI. */
public class ClwbProjectSpecificInitializer implements ProjectComponent {

private final Project project;

public ClwbProjectSpecificInitializer(Project project) {
this.project = project;
public class ClwbProjectSpecificInitializer implements StartupActivity.DumbAware {
@Override
public void runActivity(@NotNull Project project) {
runStartupActivity(project);
}

@Override
public void projectOpened() {
@VisibleForTesting
public static void runStartupActivity(Project project) {
CLionNotificationProvider.register(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.idea.blaze.clwb.base.Assertions.assertContainsHeader;
import static com.google.idea.blaze.clwb.base.Assertions.assertProjectStatus;

import com.intellij.openapi.util.SystemInfo;
import com.jetbrains.cidr.lang.workspace.compiler.ClangCompilerKind;
import com.jetbrains.cidr.lang.workspace.compiler.GCCCompilerKind;
import com.jetbrains.cidr.lang.workspace.compiler.MSVCCompilerKind;
import com.google.idea.blaze.clwb.base.ClwbIntegrationTestCase;
import com.jetbrains.cidr.project.ui.widget.Status;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -22,6 +24,7 @@ public void testClwb() {

checkCompiler();
checkTest();
checkStatus();
}

private void checkCompiler() {
Expand All @@ -44,4 +47,10 @@ private void checkTest() {
assertContainsHeader("iostream", compilerSettings);
assertContainsHeader("catch2/catch_test_macros.hpp", compilerSettings);
}

private void checkStatus() {
final var file = findProjectFile("main/hello-world.cc");

assertProjectStatus(getProject(), file, Status.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
import static com.google.common.truth.Truth.assertWithMessage;

import com.google.common.truth.StringSubject;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.cidr.lang.workspace.OCCompilerSettings;
import com.jetbrains.cidr.lang.workspace.headerRoots.HeadersSearchRoot;
import com.jetbrains.cidr.project.ui.widget.Status;
import com.jetbrains.cidr.project.ui.widget.WidgetStatus;
import com.jetbrains.cidr.project.ui.widget.WidgetStatusProvider;
import java.util.Objects;
import java.util.regex.Pattern;

public class Assertions {

private final static Pattern defineRx = Pattern.compile("#define ([^ ]+) ?(.*)");

public static void assertContainsHeader(String fileName, OCCompilerSettings settings) {
Expand Down Expand Up @@ -74,4 +80,15 @@ public static StringSubject assertDefine(String symbol, OCCompilerSettings setti

return assertWithMessage("symbol is not defined: " + symbol).that((String) null);
}

public static void assertProjectStatus(Project project, VirtualFile file, Status expected) {
final var actual = WidgetStatusProvider.Companion.getEP_NAME().getExtensionList().stream()
.map((it) -> it.getWidgetStatus(project, file))
.filter(Objects::nonNull)
.findFirst()
.map(WidgetStatus::getStatus)
.orElse(null);

assertThat(actual).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.idea.blaze.base.wizard2.BlazeProjectImportBuilder;
import com.google.idea.blaze.base.wizard2.CreateFromScratchProjectViewOption;
import com.google.idea.blaze.base.wizard2.WorkspaceTypeData;
import com.google.idea.blaze.plugin.ClwbProjectSpecificInitializer;
import com.google.idea.testing.ServiceHelper;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
Expand Down Expand Up @@ -201,6 +202,9 @@ protected void setUpProject() throws Exception {
}

builder.builder().commitToProject(myProject);

// run startup activities, needs to be done manually
ClwbProjectSpecificInitializer.runStartupActivity(myProject);
}

protected @Language("projectview") String projectViewText() {
Expand Down

0 comments on commit c2906ad

Please sign in to comment.