Skip to content

Commit e4fd3f6

Browse files
committed
test: add some tests
Signed-off-by: melodicore <datafox@datafox.me>
1 parent 99a5c2f commit e4fd3f6

8 files changed

Lines changed: 187 additions & 24 deletions

File tree

.github/workflows/job.build.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ jobs:
5252
- name: "Build: Elide Plugin"
5353
run: ./mvnw clean install -pl elide-plugin
5454
- name: "Test: Java Compiler"
55-
run: ./mvnw clean package exec:java -f sample-java
55+
run:
56+
./mvnw test -pl java-compiler
57+
./mvnw clean package exec:java -f sample-java
5658
- name: "Test: Kotlin Plugin"
57-
run: ./mvnw clean package exec:java -f sample-kotlin
58-
- name: "Test: Mixed source"
59-
run: ./mvnw clean package exec:java -f sample-mixed
59+
run:
60+
./mvnw test -pl kotlin-plugin
61+
./mvnw clean package exec:java -f sample-kotlin
62+
- name: "Test: Elide Plugin"
63+
run:
64+
./mvnw clean package exec:java -f sample-mixed

Makefile

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
all: clean install samples
1+
all: clean all-java all-kotlin all-plugin
22

33
clean:
44
./mvnw clean
55

6-
install: java kotlin plugin
6+
all-java: build-java test-java install-java sample-java
77

8-
java:
8+
all-kotlin: build-kotlin test-kotlin install-kotlin sample-kotlin
9+
10+
all-plugin: build-plugin test-plugin install-plugin sample-plugin
11+
12+
build-java:
13+
./mvnw compile -pl java-compiler
14+
15+
build-kotlin:
16+
./mvnw compile -pl kotlin-plugin
17+
18+
build-plugin:
19+
./mvnw compile -pl elide-plugin
20+
21+
test-java:
22+
./mvnw test -pl java-compiler
23+
24+
test-kotlin:
25+
./mvnw test -pl kotlin-plugin
26+
27+
test-plugin:
28+
./mvnw test -pl elide-plugin
29+
30+
install-java:
931
./mvnw install -pl java-compiler
1032

11-
kotlin:
33+
install-kotlin:
1234
./mvnw install -pl kotlin-plugin
1335

14-
plugin:
36+
install-plugin:
1537
./mvnw install -pl elide-plugin
1638

17-
samples: sample-java sample-kotlin sample-plugin
18-
1939
sample-java:
2040
./mvnw clean package exec:java -f sample-java
2141

java-compiler/pom.xml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
<junitVersion>6.0.3</junitVersion>
5353
<mavenTestPluginVersion>3.5.5</mavenTestPluginVersion>
5454
<plexusUtilsVersion>4.0.3</plexusUtilsVersion>
55+
<plexusTestingVersion>1.5.0</plexusTestingVersion>
56+
<guavaVersion>33.6.0-jre</guavaVersion>
5557
</properties>
5658

5759
<repositories>
@@ -90,22 +92,17 @@
9092
<artifactId>plexus-utils</artifactId>
9193
<version>${plexusUtilsVersion}</version>
9294
</dependency>
95+
<!-- transitive dependency of plexus-testing, updated manually because of a CVE -->
96+
<dependency>
97+
<groupId>com.google.guava</groupId>
98+
<artifactId>guava</artifactId>
99+
<version>${guavaVersion}</version>
100+
<scope>test</scope>
101+
</dependency>
93102
</dependencies>
94103
</dependencyManagement>
95104

96105
<dependencies>
97-
<dependency>
98-
<groupId>org.jetbrains.kotlin</groupId>
99-
<artifactId>kotlin-test-junit5</artifactId>
100-
<version>${kotlinVersion}</version>
101-
<scope>test</scope>
102-
</dependency>
103-
<dependency>
104-
<groupId>org.junit.jupiter</groupId>
105-
<artifactId>junit-jupiter</artifactId>
106-
<version>${junitVersion}</version>
107-
<scope>test</scope>
108-
</dependency>
109106
<dependency>
110107
<groupId>org.jetbrains.kotlin</groupId>
111108
<artifactId>kotlin-stdlib</artifactId>
@@ -126,5 +123,23 @@
126123
<artifactId>plexus-compiler-javac</artifactId>
127124
<version>${plexusVersion}</version>
128125
</dependency>
126+
<dependency>
127+
<groupId>org.jetbrains.kotlin</groupId>
128+
<artifactId>kotlin-test-junit5</artifactId>
129+
<version>${kotlinVersion}</version>
130+
<scope>test</scope>
131+
</dependency>
132+
<dependency>
133+
<groupId>org.junit.jupiter</groupId>
134+
<artifactId>junit-jupiter</artifactId>
135+
<version>${junitVersion}</version>
136+
<scope>test</scope>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.codehaus.plexus</groupId>
140+
<artifactId>plexus-testing</artifactId>
141+
<version>${plexusTestingVersion}</version>
142+
<scope>test</scope>
143+
</dependency>
129144
</dependencies>
130145
</project>

java-compiler/src/main/kotlin/dev/elide/maven/compiler/ElideJavacCompiler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ open class ElideJavacCompiler : JavacCompiler() {
133133
private fun getElideExecutable(config: CompilerConfiguration): String =
134134
config.executable ?: ElideLocator.locate()?.absolutePathString() ?: ELIDE_EXECUTABLE
135135

136-
private fun getElideJavacVersion(executable: String): String? {
136+
internal fun getElideJavacVersion(executable: String): String? {
137137
val cli = Commandline()
138138
cli.setExecutable(executable)
139139
cli.addArguments(arrayOf("javac", "--", "-version"))

java-compiler/src/test/kotlin/.gitkeep

Whitespace-only changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2024-2026 Elide Technologies, Inc.
3+
*
4+
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
*
7+
* https://opensource.org/license/mit/
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under the License.
12+
*/
13+
package dev.elide.maven.compiler
14+
15+
import org.codehaus.plexus.testing.PlexusTest
16+
import org.codehaus.plexus.util.cli.CommandLineUtils
17+
import org.codehaus.plexus.util.cli.Commandline
18+
import org.junit.jupiter.api.BeforeAll
19+
import org.junit.jupiter.api.assertDoesNotThrow
20+
import java.nio.file.Path
21+
import kotlin.io.path.absolutePathString
22+
import kotlin.test.Test
23+
import kotlin.test.assertEquals
24+
import kotlin.test.assertNotNull
25+
import kotlin.test.assertTrue
26+
27+
/**
28+
* Tests for the Elide Java Plexus Compiler.
29+
*
30+
* @author Lauri Heino <datafox>
31+
*/
32+
@PlexusTest
33+
class ElideJavacCompilerTest {
34+
@Test
35+
fun `can retrieve elide javac version`() {
36+
val compiler = ElideJavacCompiler()
37+
val version = assertNotNull(compiler.getElideJavacVersion(ELIDE_PATH.absolutePathString()), "Elide javac version could not be retrieved")
38+
val versionInt = assertDoesNotThrow("Retrieved version should be an integer") { version.toInt() }
39+
assertTrue(versionInt >= 25, "Retrieved version should be 25 or higher")
40+
}
41+
42+
companion object {
43+
private lateinit var elidePath: Path
44+
45+
val ELIDE_PATH by lazy { elidePath }
46+
47+
val ELIDE_VERSION_RE = "\\d+\\.\\d+\\.\\d+(-.*)?".toRegex()
48+
49+
@BeforeAll
50+
@JvmStatic
51+
fun `elide should be present for tests`() {
52+
elidePath = assertNotNull(ElideLocator.locate(), "Elide binary was not found")
53+
val cli = Commandline()
54+
cli.executable = elidePath.absolutePathString()
55+
cli.addArguments(arrayOf("--version"))
56+
val out = CommandLineUtils.StringStreamConsumer()
57+
assertDoesNotThrow("Could not run elide binary") {
58+
val code = CommandLineUtils.executeCommandLine(cli, out, out)
59+
assertEquals(0, code, "Elide binary produced an error: ${out.output}")
60+
}
61+
val lines = out.output.lineSequence().filter(String::isNotBlank).toList()
62+
assertEquals(1, lines.size, "Output should contain a single non-blank line")
63+
assertTrue(lines.first().trim().matches(ELIDE_VERSION_RE), "Output should be a valid Elide version")
64+
}
65+
}
66+
}

kotlin-plugin/src/test/kotlin/.gitkeep

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024-2026 Elide Technologies, Inc.
3+
*
4+
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
*
7+
* https://opensource.org/license/mit/
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under the License.
12+
*/
13+
package dev.elide.maven.plugin.kotlin
14+
15+
import org.apache.maven.project.MavenProject
16+
import org.jetbrains.kotlin.cli.common.arguments.Argument
17+
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
18+
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArgumentsConfigurator
19+
import kotlin.test.Test
20+
import kotlin.test.assertContains
21+
import kotlin.test.assertEquals
22+
import kotlin.test.assertNotEquals
23+
24+
/**
25+
* Tests for the Elide Kotlin Maven Plugin.
26+
*
27+
* @author Lauri Heino <datafox>
28+
*/
29+
class ElideKotlinPluginTest {
30+
@Test
31+
fun `argument parser should parse arguments`() {
32+
val arguments = MockCompilerArguments(CommonCompilerArgumentsConfigurator())
33+
arguments.someSpecialArgument = "gargantuan"
34+
val project = MavenProject()
35+
project.build.outputDirectory = "output/directory"
36+
val parsedArguments = ArgumentParser.parseArguments("test", arguments, project)
37+
assertEquals("test", parsedArguments[0])
38+
assertEquals("--", parsedArguments[1])
39+
assertContains(parsedArguments, "-XXspecial-argument=gargantuan")
40+
val dIndex = parsedArguments.indexOf("-d")
41+
assertNotEquals(-1, dIndex)
42+
assertEquals("output/directory", parsedArguments[dIndex + 1])
43+
}
44+
45+
class MockCompilerArguments(override val configurator: CommonCompilerArgumentsConfigurator) : CommonCompilerArguments() {
46+
@Argument(
47+
value = "-XXspecial-argument",
48+
valueDescription = "<str>",
49+
description = "This is just for testing.",
50+
)
51+
var someSpecialArgument: String? = null
52+
set(value) {
53+
checkFrozen()
54+
field = if (value.isNullOrEmpty()) null else value
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)