-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add catch2 test support in CLion (#7141)
Based on the changes from #7062 this adds support for catch2 run configurations.
- Loading branch information
Showing
4 changed files
with
123 additions
and
66 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
clwb/src/com/google/idea/blaze/clwb/radler/RadCatchTestContextProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 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.clwb.radler | ||
|
||
import com.jetbrains.rider.model.RadTestElementModel | ||
import com.jetbrains.rider.model.RadTestFramework | ||
|
||
class RadCatchTestContextProvider : RadTestContextProvider() { | ||
|
||
override val testFramework: RadTestFramework = RadTestFramework.Catch | ||
|
||
override fun createTestFilter(test: RadTestElementModel): String? { | ||
return test.test | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
clwb/src/com/google/idea/blaze/clwb/radler/RadTestContextProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2024 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.clwb.radler | ||
|
||
import com.google.common.util.concurrent.Futures | ||
import com.google.common.util.concurrent.ListenableFuture | ||
import com.google.idea.blaze.base.dependencies.TargetInfo | ||
import com.google.idea.blaze.base.model.primitives.RuleType | ||
import com.google.idea.blaze.base.run.ExecutorType | ||
import com.google.idea.blaze.base.run.SourceToTargetFinder | ||
import com.google.idea.blaze.base.run.TestTargetHeuristic | ||
import com.google.idea.blaze.base.run.producers.RunConfigurationContext | ||
import com.google.idea.blaze.base.run.producers.TestContext | ||
import com.google.idea.blaze.base.run.producers.TestContextProvider | ||
import com.google.idea.blaze.base.util.pluginProjectScope | ||
import com.google.idea.blaze.cpp.CppBlazeRules.RuleTypes | ||
import com.intellij.execution.actions.ConfigurationContext | ||
import com.intellij.util.asSafely | ||
import com.jetbrains.cidr.radler.testing.RadTestPsiElement | ||
import com.jetbrains.rider.model.RadTestElementModel | ||
import com.jetbrains.rider.model.RadTestFramework | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.guava.asListenableFuture | ||
import kotlinx.coroutines.guava.await | ||
import java.io.File | ||
import java.util.* | ||
|
||
abstract class RadTestContextProvider : TestContextProvider { | ||
|
||
override fun getTestContext(context: ConfigurationContext): RunConfigurationContext? { | ||
val psiElement = context.psiLocation.asSafely<RadTestPsiElement>() ?: return null | ||
|
||
if (psiElement.test.framework != testFramework) { | ||
return null | ||
} | ||
|
||
val target = pluginProjectScope(context.project).async { | ||
chooseTargetForFile(context, findTargets(context).await()) | ||
}.asListenableFuture() | ||
|
||
return TestContext.builder(psiElement, ExecutorType.DEBUG_SUPPORTED_TYPES) | ||
.setTarget(target) | ||
.setTestFilter(createTestFilter(psiElement.test)) | ||
.build() | ||
} | ||
|
||
protected abstract val testFramework: RadTestFramework | ||
|
||
protected abstract fun createTestFilter(test: RadTestElementModel): String? | ||
} | ||
|
||
private fun findTargets(context: ConfigurationContext): ListenableFuture<Collection<TargetInfo>> { | ||
val virtualFile = context.location?.virtualFile ?: return Futures.immediateFuture(emptyList()) | ||
|
||
return SourceToTargetFinder.findTargetInfoFuture( | ||
context.project, | ||
virtualFile.toNioPath().toFile(), | ||
Optional.of(RuleType.TEST), | ||
) ?: Futures.immediateFuture(emptyList()) | ||
} | ||
|
||
private fun chooseTargetForFile(context: ConfigurationContext, targets: Collection<TargetInfo>): TargetInfo? { | ||
val psiFile = context.psiLocation?.containingFile ?: return null | ||
val virtualFile = psiFile.virtualFile ?: return null | ||
|
||
val ccTargets = targets.filter { it -> it.kind == RuleTypes.CC_TEST.kind } | ||
|
||
return TestTargetHeuristic.chooseTestTargetForSourceFile( | ||
context.project, | ||
psiFile, | ||
virtualFile.toNioPath().toFile(), | ||
ccTargets, | ||
null, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters