Skip to content

Commit

Permalink
test(compiler-plugin-test): migrate a couple of tests to kotlin.test
Browse files Browse the repository at this point in the history
also makes the project compatible with Kotest 6.0.0.M2
  • Loading branch information
DanySK committed Feb 10, 2025
1 parent 9217f20 commit 196af2b
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 307 deletions.
1 change: 1 addition & 0 deletions compiler-plugin-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ kotlinJvm {
dependencies {
implementation(project(":dsl"))
implementation(project(":compiler-embeddable"))
implementation(kotlin("test"))
implementation(rootProject.libs.kotest.runner.junit5.jvm)
implementation(libs.javap)
implementation(libs.kotlinpoet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package it.unibo.collektive.test

import io.kotest.core.spec.style.FreeSpec
import it.unibo.collektive.test.util.CompileUtils.asTestingProgram
import it.unibo.collektive.test.util.CompileUtils.warning
import it.unibo.collektive.test.util.CompileUtils.warningMessage
import it.unibo.collektive.utils.common.AggregateFunctionNames
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi

Expand All @@ -12,7 +12,7 @@ class ExplicitAlignTest : FreeSpec({
val code = codeTemplate.format("align(null)").asTestingProgram("ExplicitAlign.kt")
"should produce a warning when used explicitly" - {
code shouldCompileWith
warning(
warningMessage(
EXPECTED_WARNING_MESSAGE.format(AggregateFunctionNames.ALIGN_FUNCTION_FQ_NAME),
)
}
Expand All @@ -21,7 +21,7 @@ class ExplicitAlignTest : FreeSpec({
val code = codeTemplate.format("dealign()").asTestingProgram("ExplicitDeAlign.kt")
"should produce a warning when used explicitly" - {
code shouldCompileWith
warning(
warningMessage(
EXPECTED_WARNING_MESSAGE.format(AggregateFunctionNames.DEALIGN_FUNCTION_FQ_NAME),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.kotest.data.row
import io.kotest.data.table
import it.unibo.collektive.test.util.CompileUtils.getTestingProgram
import it.unibo.collektive.test.util.CompileUtils.noWarning
import it.unibo.collektive.test.util.CompileUtils.warning
import it.unibo.collektive.test.util.CompileUtils.warningMessage

class ImproperConstructSpec : FreeSpec({

Expand Down Expand Up @@ -46,7 +46,7 @@ class ImproperConstructSpec : FreeSpec({

"should compile producing a warning" - {
code shouldCompileWith
warning(
warningMessage(
expectedWarning(construct),
)
}
Expand All @@ -58,7 +58,7 @@ class ImproperConstructSpec : FreeSpec({

"should compile producing a warning" - {
code shouldCompileWith
warning(
warningMessage(
expectedWarning(construct),
)
}
Expand All @@ -70,7 +70,7 @@ class ImproperConstructSpec : FreeSpec({

"should compile producing a warning" - {
code shouldCompileWith
warning(
warningMessage(
expectedWarning(construct),
)
}
Expand All @@ -82,7 +82,7 @@ class ImproperConstructSpec : FreeSpec({

"should compile producing a warning" - {
code shouldCompileWith
warning(
warningMessage(
expectedWarning(construct),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024, Danilo Pianini, Nicolas Farabegoli, Elisa Tronetti,
* and all authors listed in the `build.gradle.kts` and the generated `pom.xml` file.
*
* This file is part of Collektive, and is distributed under the terms of the Apache License 2.0,
* as described in the LICENSE file in this project's repository's top directory.
*/

package it.unibo.collektive.test

import io.github.subjekt.Subjekt.subjekt
import io.github.subjekt.generators.FilesGenerator.toTempFiles
import it.unibo.collektive.test.util.CompileUtils.formsOfIteration
import it.unibo.collektive.test.util.CompileUtils.`iteration with warning`
import it.unibo.collektive.test.util.CompileUtils.`iteration without warning`
import it.unibo.collektive.test.util.CompileUtils.testedAggregateFunctions
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import java.io.File
import kotlin.test.Test

@OptIn(ExperimentalCompilerApi::class)
class IterationUsingDelegatesWithoutAlign {
private val testSubjects: Map<String, File> =
subjekt {
addSource("src/test/resources/subjekt/IterationWithDelegatedAggregate.yaml")
}.toTempFiles()

@Test
fun `test iterations using delegates`() {
for (functionCall in testedAggregateFunctions) {
val functionName = functionCall.substringBefore("(")
for ((iteration, _) in formsOfIteration) {
with(testSubjects) {
`iteration with warning`("IterationDelegate", functionName, iteration, expectedWarning)
`iteration without warning`("IterationAlignDelegate", functionName, iteration)
`iteration without warning`("IterationDelegateAlign", functionName, iteration)
`iteration without warning`("IterationDelegateWithNestedFun", functionName, iteration)
`iteration with warning`("IterationRecursiveDelegate", functionName, iteration, expectedWarning)
`iteration without warning`("IterationAlignRecursiveDelegate", functionName, iteration)
`iteration without warning`("IterationRecursiveDelegateAlign", functionName, iteration)
// Disabled tests
// `iteration with warning`("IterationDelegatedNestedFun", functionName, iteration, expectedWarning)
// `iteration without warning`("IterationAlignDelegatedNestedFun", functionName, iteration)
// `iteration without warning`("IterationDelegatedNestedFunAlign", functionName, iteration)
}
}
}
}

companion object {
private val expectedWarning: String =
"""
Function 'delegate', that accepts and uses an aggregate argument, has been called inside a loop construct
without explicit alignment.
The same path may generate interactions more than once, leading to ambiguous alignment.
Consider to wrap the function into the 'alignedOn' method with a unique element, either at the call site
or inside the 'delegate' function declaration, wrapping the involved aggregate calls.
""".trimIndent()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package it.unibo.collektive.test

import io.github.subjekt.Subjekt.subjekt
import io.github.subjekt.generators.FilesGenerator.toTempFiles
import it.unibo.collektive.test.util.CompileUtils.formsOfIteration
import it.unibo.collektive.test.util.CompileUtils.`iteration with warning`
import it.unibo.collektive.test.util.CompileUtils.`iteration without warning`
import it.unibo.collektive.test.util.CompileUtils.testedAggregateFunctions
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import kotlin.test.Test

@OptIn(ExperimentalCompilerApi::class)
class IterationWithoutAlign {
private val testSubjects =
subjekt {
addSource("src/test/resources/subjekt/IterationWithAggregate.yaml")
}.toTempFiles()

@Test
fun `test iterations without align`() {
for (functionCall in testedAggregateFunctions) {
val functionName = functionCall.substringBefore("(")
for ((iteration, _) in formsOfIteration) {
with(testSubjects) {
`iteration with warning`("Iteration", functionName, iteration, expectedWarn(functionName))
`iteration without warning`("IterationAlign", functionName, iteration)
`iteration with warning`("IterationExtAlign", functionName, iteration, expectedWarn(functionName))
`iteration without warning`("IterationWithNestedFun", functionName, iteration)
`iteration without warning`("OutsideAggregate", functionName, iteration)
}
}
}
}

private companion object {
private fun expectedWarn(functionName: String): String =
"""
Aggregate function '$functionName' has been called inside a loop construct without explicit alignment.
The same path may generate interactions more than once, leading to ambiguous alignment.
Consider to wrap the function into the 'alignedOn' method with a unique element.
""".trimIndent()
}
}
Loading

0 comments on commit 196af2b

Please sign in to comment.