aboutsummaryrefslogtreecommitdiff
path: root/src/test/groovy
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-10-26 21:16:40 +0800
committershedaniel <daniel@shedaniel.me>2021-10-26 21:16:40 +0800
commitb23636065e55e2d80dcf4d821ef53ccbfbbf9059 (patch)
treefccd1c2cfed488ed0f5fe8cd152e6cbb83021f6a /src/test/groovy
parent4d170687f48e3e15e716c7e6dd91e4f8d669ecb1 (diff)
parent5c190cc3ef99507bbb38525c0f6a24480a7ec65c (diff)
downloadarchitectury-loom-b23636065e55e2d80dcf4d821ef53ccbfbbf9059.tar.gz
architectury-loom-b23636065e55e2d80dcf4d821ef53ccbfbbf9059.tar.bz2
architectury-loom-b23636065e55e2d80dcf4d821ef53ccbfbbf9059.zip
Merge remote-tracking branch 'FabricMC/dev/0.10' into dev/0.10.0
# Conflicts: # build.gradle # src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java # src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java # src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java # src/main/java/net/fabricmc/loom/task/RemapJarTask.java # src/main/java/net/fabricmc/loom/util/FileSystemUtil.java # src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java
Diffstat (limited to 'src/test/groovy')
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy2
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/integration/AccessWidenerTest.groovy24
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/integration/RunConfigTest.groovy1
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/integration/UnpickTest.groovy5
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/unit/RunConfigUnitTest.groovy38
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy124
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/util/GradleProjectTestTrait.groovy8
7 files changed, 192 insertions, 10 deletions
diff --git a/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy b/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy
index d1985600..5329c9fe 100644
--- a/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy
+++ b/src/test/groovy/net/fabricmc/loom/test/LoomTestConstants.groovy
@@ -28,7 +28,7 @@ import org.gradle.util.GradleVersion
class LoomTestConstants {
public final static String DEFAULT_GRADLE = GradleVersion.current().getVersion()
- public final static String PRE_RELEASE_GRADLE = "7.4-20211011231946+0000"
+ public final static String PRE_RELEASE_GRADLE = "7.4-20211023222429+0000"
public final static String[] STANDARD_TEST_VERSIONS = [DEFAULT_GRADLE, PRE_RELEASE_GRADLE]
}
diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/AccessWidenerTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/AccessWidenerTest.groovy
index 43c793cb..87bd96a2 100644
--- a/src/test/groovy/net/fabricmc/loom/test/integration/AccessWidenerTest.groovy
+++ b/src/test/groovy/net/fabricmc/loom/test/integration/AccessWidenerTest.groovy
@@ -25,7 +25,7 @@
package net.fabricmc.loom.test.integration
import net.fabricmc.loom.test.util.GradleProjectTestTrait
-import org.zeroturnaround.zip.ZipUtil
+import net.fabricmc.loom.util.ZipUtils
import spock.lang.Specification
import spock.lang.Unroll
@@ -54,7 +54,7 @@ class AccessWidenerTest extends Specification implements GradleProjectTestTrait
def "transitive accesswidener (gradle #version)"() {
setup:
def gradle = gradleProject(project: "transitiveAccesswidener", version: version)
- ZipUtil.pack(new File(gradle.projectDir, "dummyDependency"), new File(gradle.projectDir, "dummy.jar"))
+ ZipUtils.pack(new File(gradle.projectDir, "dummyDependency").toPath(), new File(gradle.projectDir, "dummy.jar").toPath())
when:
def result = gradle.run(task: "build")
@@ -65,4 +65,24 @@ class AccessWidenerTest extends Specification implements GradleProjectTestTrait
where:
version << STANDARD_TEST_VERSIONS
}
+
+ @Unroll
+ def "invalid (#awLine)"() {
+ setup:
+ def gradle = gradleProject(project: "accesswidener", version: version)
+ new File(gradle.projectDir, "src/main/resources/modid.accesswidener").append(awLine)
+ def errorPrefix = "Failed to validate access-widener file modid.accesswidener on line 10: java.lang.RuntimeException: "
+
+ when:
+ def result = gradle.run(task: "check", expectFailure: true)
+
+ then:
+ result.output.contains(errorPrefix + error)
+
+ where:
+ awLine | error | version
+ 'accessible\tclass\tnet/minecraft/DoesntExists' | "Could not find class (net/minecraft/DoesntExists)" | DEFAULT_GRADLE
+ 'accessible\tfield\tnet/minecraft/screen/slot/Slot\tabc\tI' | "Could not find field (abcI) in class (net/minecraft/screen/slot/Slot)" | DEFAULT_GRADLE
+ 'accessible\tmethod\tnet/minecraft/client/main/Main\tmain\t([Ljava/lang/NotAString;)V' | "Could not find method (main([Ljava/lang/NotAString;)V) in class (net/minecraft/client/main/Main)" | DEFAULT_GRADLE
+ }
}
diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/RunConfigTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/RunConfigTest.groovy
index e893c352..46d8b3a3 100644
--- a/src/test/groovy/net/fabricmc/loom/test/integration/RunConfigTest.groovy
+++ b/src/test/groovy/net/fabricmc/loom/test/integration/RunConfigTest.groovy
@@ -42,6 +42,7 @@ class RunConfigTest extends Specification implements GradleProjectTestTrait {
then:
result.task(":${task}").outcome == SUCCESS
+ result.output.contains("This contains a space")
where:
task | _
diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/UnpickTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/UnpickTest.groovy
index 2b285fb6..dbe37f99 100644
--- a/src/test/groovy/net/fabricmc/loom/test/integration/UnpickTest.groovy
+++ b/src/test/groovy/net/fabricmc/loom/test/integration/UnpickTest.groovy
@@ -25,8 +25,7 @@
package net.fabricmc.loom.test.integration
import net.fabricmc.loom.test.util.GradleProjectTestTrait
-
-import org.zeroturnaround.zip.ZipUtil
+import net.fabricmc.loom.util.ZipUtils
import spock.lang.Specification
import java.nio.charset.StandardCharsets
@@ -66,6 +65,6 @@ class UnpickTest extends Specification implements GradleProjectTestTrait {
private static String getClassSource(GradleProject gradle, String classname, String mappings = MAPPINGS) {
File sourcesJar = gradle.getGeneratedSources(mappings)
- return new String(ZipUtil.unpackEntry(sourcesJar, classname), StandardCharsets.UTF_8)
+ return new String(ZipUtils.unpack(sourcesJar.toPath(), classname), StandardCharsets.UTF_8)
}
}
diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/RunConfigUnitTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/RunConfigUnitTest.groovy
new file mode 100644
index 00000000..8a804d71
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/unit/RunConfigUnitTest.groovy
@@ -0,0 +1,38 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2021 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.unit
+
+import net.fabricmc.loom.configuration.ide.RunConfig
+import spock.lang.Specification
+
+class RunConfigUnitTest extends Specification {
+ def "escape arguments"() {
+ when:
+ def args = RunConfig.joinArguments(["-Dfabric.test=123", "-Dfabric.test=abc 123"])
+
+ then:
+ args == '"-Dfabric.test=123" "-Dfabric.test=abc 123"'
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy
new file mode 100644
index 00000000..921edff8
--- /dev/null
+++ b/src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy
@@ -0,0 +1,124 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2021 FabricMC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.fabricmc.loom.test.unit
+
+import net.fabricmc.loom.util.Pair
+import net.fabricmc.loom.util.ZipUtils
+import spock.lang.Specification
+
+import java.nio.charset.StandardCharsets
+import java.nio.file.Files
+
+class ZipUtilsTest extends Specification {
+ def "pack"() {
+ given:
+ def dir = File.createTempDir()
+ def zip = File.createTempFile("loom-zip-test", ".zip").toPath()
+ new File(dir, "test.txt").text = "This is a test of packing"
+
+ when:
+ ZipUtils.pack(dir.toPath(), zip)
+
+ then:
+ Files.exists(zip)
+ ZipUtils.contains(zip, "test.txt")
+ !ZipUtils.contains(zip, "nope.txt")
+ new String( ZipUtils.unpack(zip, "test.txt"), StandardCharsets.UTF_8) == "This is a test of packing"
+ }
+
+ def "transform string"() {
+ given:
+ def dir = File.createTempDir()
+ def zip = File.createTempFile("loom-zip-test", ".zip").toPath()
+ new File(dir, "test.txt").text = "This is a test of transforming"
+
+ when:
+ ZipUtils.pack(dir.toPath(), zip)
+ def transformed = ZipUtils.transformString(zip, [
+ new Pair<String, ZipUtils.UnsafeUnaryOperator<String>>("test.txt", new ZipUtils.UnsafeUnaryOperator<String>() {
+ @Override
+ String apply(String arg) throws IOException {
+ return arg.toUpperCase()
+ }
+ })
+ ])
+
+ then:
+ transformed == 1
+ ZipUtils.contains(zip, "test.txt")
+ new String( ZipUtils.unpack(zip, "test.txt"), StandardCharsets.UTF_8) == "THIS IS A TEST OF TRANSFORMING"
+ }
+
+ def "replace string"() {
+ given:
+ def dir = File.createTempDir()
+ def zip = File.createTempFile("loom-zip-test", ".zip").toPath()
+ new File(dir, "test.txt").text = "This has not been replaced"
+
+ when:
+ ZipUtils.pack(dir.toPath(), zip)
+ ZipUtils.replace(zip, "test.txt", "This has been replaced".bytes)
+
+ then:
+ ZipUtils.contains(zip, "test.txt")
+ new String(ZipUtils.unpack(zip, "test.txt"), StandardCharsets.UTF_8) == "This has been replaced"
+ }
+
+ def "add file"() {
+ given:
+ def dir = File.createTempDir()
+ def zip = File.createTempFile("loom-zip-test", ".zip").toPath()
+ new File(dir, "test.txt").text = "This is original"
+
+ when:
+ ZipUtils.pack(dir.toPath(), zip)
+ ZipUtils.add(zip, "test2.txt", "This has been added".bytes)
+
+ then:
+ ZipUtils.contains(zip, "test.txt")
+ ZipUtils.contains(zip, "test2.txt")
+ new String(ZipUtils.unpack(zip, "test.txt"), StandardCharsets.UTF_8) == "This is original"
+ new String(ZipUtils.unpack(zip, "test2.txt"), StandardCharsets.UTF_8) == "This has been added"
+ }
+
+ def "unpack all"() {
+ given:
+ def input = File.createTempDir()
+ def output = File.createTempDir()
+
+ def zip = File.createTempFile("loom-zip-test", ".zip").toPath()
+ new File(input, "test.txt").text = "This is a test of unpacking all"
+
+ def outputFile = new File(output, "test.txt")
+
+ when:
+ ZipUtils.pack(input.toPath(), zip)
+ ZipUtils.unpackAll(zip, output.toPath())
+
+ then:
+ outputFile.exists()
+ outputFile.text == "This is a test of unpacking all"
+ }
+}
diff --git a/src/test/groovy/net/fabricmc/loom/test/util/GradleProjectTestTrait.groovy b/src/test/groovy/net/fabricmc/loom/test/util/GradleProjectTestTrait.groovy
index 91a19b91..6380992e 100644
--- a/src/test/groovy/net/fabricmc/loom/test/util/GradleProjectTestTrait.groovy
+++ b/src/test/groovy/net/fabricmc/loom/test/util/GradleProjectTestTrait.groovy
@@ -26,9 +26,9 @@ package net.fabricmc.loom.test.util
import groovy.transform.Immutable
import net.fabricmc.loom.test.LoomTestConstants
+import net.fabricmc.loom.util.ZipUtils
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
-import org.zeroturnaround.zip.ZipUtil
import spock.lang.Shared
trait GradleProjectTestTrait {
@@ -156,7 +156,7 @@ trait GradleProjectTestTrait {
runner.withArguments(args as String[])
- return runner.build()
+ return options.expectFailure ? runner.buildAndFail() : runner.build()
}
private GradleRunner getRunner() {
@@ -192,7 +192,7 @@ trait GradleProjectTestTrait {
String getOutputZipEntry(String filename, String entryName) {
def file = getOutputFile(filename)
- def bytes = ZipUtil.unpackEntry(file, entryName)
+ def bytes = ZipUtils.unpackNullable(file.toPath(), entryName)
if (bytes == null) {
throw new FileNotFoundException("Could not find ${entryName} in ${entryName}")
@@ -203,7 +203,7 @@ trait GradleProjectTestTrait {
boolean hasOutputZipEntry(String filename, String entryName) {
def file = getOutputFile(filename)
- return ZipUtil.unpackEntry(file, entryName) != null
+ return ZipUtils.unpackNullable(file.toPath(), entryName) != null
}
File getGeneratedSources(String mappings) {