Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip C++ neo4j tests if C++ frontend is not enabled #1918

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fun createTranslationResult(file: String = "client.cpp"): Pair<Application, Tran
class ApplicationTest {

@Test
@SkipIfLanguageIsNotAvailable("de.fraunhofer.aisec.cpg.frontends.cxx.CPPLanguage")
fun testSerializeCpgViaOGM() {
val (application, translationResult) = createTranslationResult()

Expand Down Expand Up @@ -94,6 +95,7 @@ class ApplicationTest {
}

@Test
@SkipIfLanguageIsNotAvailable("de.fraunhofer.aisec.cpg.frontends.cxx.CPPLanguage")
fun testExportToJson() {
val (application, translationResult) = createTranslationResult()
// 22 inferred functions, 1 inferred method, 2 inferred constructors, 11 regular functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.junit.jupiter.api.Tag
@Tag("integration")
class Neo4JTest {
@Test
@SkipIfLanguageIsNotAvailable("de.fraunhofer.aisec.cpg.frontends.cxx.CPPLanguage")
fun testPush() {
val (application, result) = createTranslationResult()

Expand All @@ -49,6 +50,7 @@ class Neo4JTest {
}

@Test
@SkipIfLanguageIsNotAvailable("de.fraunhofer.aisec.cpg.frontends.cxx.CPPLanguage")
fun testPushVeryLong() {
val (application, result) = createTranslationResult("very_long.cpp")

Expand All @@ -62,6 +64,7 @@ class Neo4JTest {
}

@Test
@SkipIfLanguageIsNotAvailable("de.fraunhofer.aisec.cpg.frontends.cxx.CPPLanguage")
fun testPushConcepts() {
val (application, result) = createTranslationResult()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2025, Fraunhofer AISEC. 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 de.fraunhofer.aisec.cpg_vis_neo4j

import de.fraunhofer.aisec.cpg.frontends.Language
import kotlin.reflect.full.createInstance
import org.junit.jupiter.api.extension.ConditionEvaluationResult
import org.junit.jupiter.api.extension.ExecutionCondition
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.ExtensionContext

/** This annotation can be used to skip a test if a certain language is not available. */
@ExtendWith(LanguageAvailability::class)
annotation class SkipIfLanguageIsNotAvailable(
/** The fully qualified name of the language that must be available. */
val language: String
)

/** This condition checks if a [Language] is available by trying to instantiate it. */
class LanguageAvailability : ExecutionCondition {
override fun evaluateExecutionCondition(
context: ExtensionContext?
): ConditionEvaluationResult? {
val annotation =
context?.element?.get()?.getAnnotation(SkipIfLanguageIsNotAvailable::class.java)

if (annotation == null) {
return ConditionEvaluationResult.enabled("No language annotation found")
}

try {
Class.forName(annotation.language).kotlin.createInstance() as? Language<*>
} catch (_: ClassNotFoundException) {
return ConditionEvaluationResult.disabled(
"Language ${annotation.language} is not available"
)
}

return ConditionEvaluationResult.enabled("Language ${annotation.language} is available")
}
}
Loading