Skip to content

Commit

Permalink
Add unit tests and update build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Nov 1, 2023
1 parent 3a1b3fb commit 776a356
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 74 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ jobs:
gradle:
strategy:
matrix:
java: [17, 20]
java: [17, 21]
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:${{ matrix.java }}
options: --user root
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'

- uses: actions/checkout@v3
- name: 'Build'
run: ./gradlew build publishMods --stacktrace --warning-mode=fail

- name: 'Upload artifacts'
if: ${{ matrix.java == '20' }}
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
java-version: 20
java-version: 21
distribution: 'temurin'
- uses: FabricMC/fabric-action-scripts@v2
id: changelog
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 18
java-version: 21
distribution: 'temurin'
- run: ./gradlew updateVersions
- run: ./gradlew processMDTemplates
Expand Down
57 changes: 29 additions & 28 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ buildscript {
}

plugins {
id 'fabric-loom' version '1.3.8'
id 'fabric-loom' version '1.4.4'
id 'maven-publish'
id "com.diffplug.spotless" version "6.19.0"
id 'me.modmuss50.mod-publish-plugin' version '0.3.4'
id 'me.modmuss50.mod-publish-plugin' version '0.4.1'
}

apply plugin: "org.jetbrains.kotlin.jvm"

group = project.group

def ENV = System.getenv()
def MINECRAFT_VERSIONS_FILE = "generated/minecraft_versions.txt"
def LIBRARY_VERSIONS_FILE = "generated/library_versions.json"
def KOTLIN_VERSION_FILE = "generated/kotlin_version.txt"

Expand Down Expand Up @@ -79,6 +78,8 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraftVersion}"
mappings "net.fabricmc:yarn:${project.mappingsVersion}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loaderVersion}"
testImplementation "net.fabricmc:fabric-loader-junit:${project.loaderVersion}"
testImplementation "org.jetbrains.kotlin:kotlin-test"

if (hasMissingLibVersion) {
println("Contains missing library version, run updateLibraryVersions task!")
Expand Down Expand Up @@ -125,6 +126,22 @@ jar {
}
}

test {
useJUnitPlatform()
afterEvaluate {
// See: https://github.com/FabricMC/fabric-loader/pull/585
def classPathGroups = loom.mods.stream()
.map { modSettings ->
net.fabricmc.loom.util.gradle.SourceSetHelper.getClasspath(modSettings, getProject()).stream()
.map(File.&getAbsolutePath)
.collect(java.util.stream.Collectors.joining(File.pathSeparator))
}
.collect(java.util.stream.Collectors.joining(File.pathSeparator+File.pathSeparator))

systemProperty("fabric.classPathGroups", classPathGroups)
}
}

task processMDTemplates(type: Copy) {
group = "documentation"
doFirst {
Expand Down Expand Up @@ -174,8 +191,6 @@ publishing {
}
}

def mcVersions = file(MINECRAFT_VERSIONS_FILE).text.readLines()

publishMods {
file = remapJar.archiveFile
changelog = ENV.CHANGELOG ?: "No changelog provided"
Expand All @@ -187,12 +202,18 @@ publishMods {
curseforge {
accessToken = providers.environmentVariable("CURSEFORGE_API_KEY")
projectId = "308769"
minecraftVersions = mcVersions
minecraftVersionRange {
start = "1.14"
end = "latest"
}
}
modrinth {
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
projectId = "Ha28R6CL"
minecraftVersions = mcVersions
minecraftVersionRange {
start = "1.14"
end = "latest"
}
}
github {
accessToken = providers.environmentVariable("GITHUB_TOKEN")
Expand Down Expand Up @@ -230,26 +251,6 @@ task checkVersion {
}
}

task updateMinecraftVersions {
group = "update"
doFirst {
def json = new URL("https://meta.fabricmc.net/v2/versions/game").text
def versions = new JsonSlurper().parseText(json)
def output = new StringBuilder()
def i = 0
for (def version : versions) {
if (version.stable) {
if (i > 0) {
output.append("\n")
}
output.append("${version.version}")
i++
}
}
file(MINECRAFT_VERSIONS_FILE).setText(output.toString(), StandardCharsets.UTF_8.name())
}
}

task updateLibraryVersions {
group = "update"
doFirst {
Expand Down Expand Up @@ -287,7 +288,7 @@ task updateLibraryVersions {

task updateVersions {
group = "update"
dependsOn(updateMinecraftVersions, updateLibraryVersions)
dependsOn(updateLibraryVersions)
}

tasks.publishMods.dependsOn checkVersion
Expand Down
27 changes: 0 additions & 27 deletions generated/minecraft_versions.txt

This file was deleted.

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"license": "Apache-2.0",
"icon": "assets/fabric-language-kotlin/icon500.png",
"depends": {
"fabricloader": ">=0.14.21"
"fabricloader": ">=0.14.24"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2016 FabricMC
*
* 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 net.fabricmc.language.kotlin.test

import net.fabricmc.api.ModInitializer
import net.fabricmc.language.kotlin.KotlinAdapter
import net.fabricmc.loader.api.FabricLoader
import kotlin.test.Test

class KotlinAdapterTest {
@Test
fun classEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.ClassEntrypoint")
}

@Test
fun objectClassEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.ObjectClassEntrypoint")
}

@Test
fun objectFunctionEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.ObjectFunctionEntrypoint::init")
}

@Test
fun objectFieldEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.ObjectFieldEntrypoint::initializer")
}

@Test
fun companionClassEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.CompanionClassEntrypoint\$Companion")
}

@Test
fun companionFunctionEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.CompanionFunctionEntrypoint\$Companion::init")
}

@Test
fun companionFieldEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.CompanionFieldEntrypoint\$Companion::initializer")
}

@Test
fun topLevelEntrypoint() {
testEntrypoint("net.fabricmc.language.kotlin.test.entrypoints.TopLevelEntrypointKt::init")
}

private fun testEntrypoint(value: String) {
FabricLoader.getInstance().objectShare.remove("fabric-language-kotlin:test")

val modContainer = FabricLoader.getInstance().getModContainer("fabric-language-kotlin").get()
val entrypoint = KotlinAdapter().create(modContainer, value, ModInitializer::class.java)
entrypoint.onInitialize()

assert(FabricLoader.getInstance().objectShare.get("fabric-language-kotlin:test") == "true")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2016 FabricMC
*
* 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 net.fabricmc.language.kotlin.test.entrypoints

import net.fabricmc.api.ModInitializer
import net.fabricmc.loader.api.FabricLoader

class ClassEntrypoint : ModInitializer {
override fun onInitialize() {
FabricLoader.getInstance().objectShare.put("fabric-language-kotlin:test", "true")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2016 FabricMC
*
* 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 net.fabricmc.language.kotlin.test.entrypoints

import net.fabricmc.api.ModInitializer
import net.fabricmc.loader.api.FabricLoader

class CompanionClassEntrypoint {
companion object: ModInitializer {
override fun onInitialize() {
FabricLoader.getInstance().objectShare.put("fabric-language-kotlin:test", "true")
}
}
}
Loading

0 comments on commit 776a356

Please sign in to comment.