Skip to content

Commit 6e2fd21

Browse files
authored
test: add tests asserting on Java bytecode version (#2070)
Part of #1699. Useful to ensure that we don't accidentally produce JARs with different bytecode version.
1 parent d8dc647 commit 6e2fd21

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.typesafegithub.workflows
2+
3+
import io.github.typesafegithub.workflows.domain.Workflow
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.matchers.shouldBe
6+
import java.io.DataInputStream
7+
8+
class JavaBytecodeVersionTest :
9+
FunSpec(
10+
{
11+
test("library is built with desired Java bytecode version") {
12+
Workflow::class.java.classLoader
13+
.getResourceAsStream(
14+
"io/github/typesafegithub/workflows/domain/Workflow.class",
15+
)!!
16+
.use { inputStream ->
17+
val dataInputStream = DataInputStream(inputStream)
18+
require(dataInputStream.readInt() == 0xCAFEBABE.toInt()) { "Invalid class header" }
19+
val minor = dataInputStream.readUnsignedShort()
20+
val major = dataInputStream.readUnsignedShort()
21+
22+
// Corresponds to JDK 11
23+
// See https://javaalmanac.io/bytecode/versions/
24+
major shouldBe 55
25+
minor shouldBe 0
26+
}
27+
}
28+
},
29+
)

0 commit comments

Comments
 (0)