Use a filter based approach for KotlinTestParameters builder
This is similar to what we do for test-parameters.
Bug: 193765243
Change-Id: Ie5897e563cf68fc50deafe9aeb46d37076f253bb
diff --git a/src/test/java/com/android/tools/r8/KotlinCompilerTool.java b/src/test/java/com/android/tools/r8/KotlinCompilerTool.java
index 468c1e9..61efff1 100644
--- a/src/test/java/com/android/tools/r8/KotlinCompilerTool.java
+++ b/src/test/java/com/android/tools/r8/KotlinCompilerTool.java
@@ -13,6 +13,7 @@
import com.android.tools.r8.ToolHelper.KotlinTargetVersion;
import com.android.tools.r8.ToolHelper.ProcessResult;
import com.android.tools.r8.utils.FileUtils;
+import com.android.tools.r8.utils.structural.Ordered;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -28,7 +29,7 @@
public class KotlinCompilerTool {
- public enum KotlinCompilerVersion {
+ public enum KotlinCompilerVersion implements Ordered<KotlinCompilerVersion> {
KOTLINC_1_3_72("kotlin-compiler-1.3.72"),
KOTLINC_1_4_20("kotlin-compiler-1.4.20"),
KOTLINC_1_5_0("kotlin-compiler-1.5.0");
diff --git a/src/test/java/com/android/tools/r8/KotlinTestParameters.java b/src/test/java/com/android/tools/r8/KotlinTestParameters.java
index 7cfcc07..5c85355 100644
--- a/src/test/java/com/android/tools/r8/KotlinTestParameters.java
+++ b/src/test/java/com/android/tools/r8/KotlinTestParameters.java
@@ -3,13 +3,12 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8;
-import static org.junit.Assert.assertNotNull;
-
import com.android.tools.r8.KotlinCompilerTool.KotlinCompiler;
import com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion;
import com.android.tools.r8.ToolHelper.KotlinTargetVersion;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Predicate;
public class KotlinTestParameters {
@@ -55,13 +54,23 @@
public static class Builder {
- private KotlinCompiler[] compilers;
- private KotlinTargetVersion[] targetVersions;
+ private Predicate<KotlinCompilerVersion> compilerFilter = c -> false;
+ private Predicate<KotlinTargetVersion> targetVersionFilter = t -> false;
private Builder() {}
+ private Builder withCompilerFilter(Predicate<KotlinCompilerVersion> predicate) {
+ compilerFilter = compilerFilter.or(predicate);
+ return this;
+ }
+
+ private Builder withTargetVersionFilter(Predicate<KotlinTargetVersion> predicate) {
+ targetVersionFilter = targetVersionFilter.or(predicate);
+ return this;
+ }
+
public Builder withAllCompilers() {
- compilers = ToolHelper.getKotlinCompilers();
+ withCompilerFilter(compiler -> true);
return this;
}
@@ -69,41 +78,41 @@
return withAllCompilers().withAllTargetVersions();
}
- public Builder withCompiler(KotlinCompiler compiler) {
- compilers = new KotlinCompiler[] {compiler};
+ public Builder withCompiler(KotlinCompilerVersion compilerVersion) {
+ withCompilerFilter(c -> c.isEqualTo(compilerVersion));
return this;
}
public Builder withAllTargetVersions() {
- targetVersions = KotlinTargetVersion.values();
+ withTargetVersionFilter(t -> true);
return this;
}
public Builder withTargetVersion(KotlinTargetVersion targetVersion) {
- targetVersions = new KotlinTargetVersion[] {targetVersion};
+ withTargetVersionFilter(t -> t.equals(targetVersion));
return this;
}
public KotlinTestParametersCollection build() {
- validate();
List<KotlinTestParameters> testParameters = new ArrayList<>();
int index = 0;
- for (KotlinCompiler kotlinc : compilers) {
- for (KotlinTargetVersion targetVersion : targetVersions) {
+ for (KotlinCompilerVersion kotlinVersion : KotlinCompilerVersion.values()) {
+ for (KotlinTargetVersion targetVersion : KotlinTargetVersion.values()) {
// KotlinTargetVersion java 6 is deprecated from kotlinc 1.5 and forward, no need to run
// tests on that target.
- if (targetVersion != KotlinTargetVersion.JAVA_6
- || kotlinc.isNot(KotlinCompilerVersion.KOTLINC_1_5_0)) {
- testParameters.add(new KotlinTestParameters(kotlinc, targetVersion, index++));
+ if (targetVersion == KotlinTargetVersion.JAVA_6
+ && kotlinVersion.equals(KotlinCompilerVersion.KOTLINC_1_5_0)) {
+ continue;
+ }
+ if (compilerFilter.test(kotlinVersion) && targetVersionFilter.test(targetVersion)) {
+ testParameters.add(
+ new KotlinTestParameters(
+ new KotlinCompiler(kotlinVersion), targetVersion, index++));
}
}
}
+ assert !testParameters.isEmpty();
return new KotlinTestParametersCollection(testParameters);
}
-
- private void validate() {
- assertNotNull(compilers);
- assertNotNull(targetVersions);
- }
}
}
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataVersionNumberBumpTest.java b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataVersionNumberBumpTest.java
index 8fa6fee..b0ea3d9 100644
--- a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataVersionNumberBumpTest.java
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataVersionNumberBumpTest.java
@@ -5,11 +5,11 @@
package com.android.tools.r8.kotlin.metadata;
import static com.android.tools.r8.ToolHelper.getKotlinAnnotationJar;
-import static com.android.tools.r8.ToolHelper.getKotlinC_1_3_72;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.objectweb.asm.Opcodes.ASM7;
+import com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion;
import com.android.tools.r8.KotlinTestParameters;
import com.android.tools.r8.R8FullTestBuilder;
import com.android.tools.r8.TestParameters;
@@ -40,12 +40,12 @@
private final TestParameters parameters;
- @Parameters(name = "{0}")
+ @Parameters(name = "{0}, {1}")
public static List<Object[]> data() {
return buildParameters(
getTestParameters().withAllRuntimesAndApiLevels().build(),
getKotlinTestParameters()
- .withCompiler(getKotlinC_1_3_72())
+ .withCompiler(KotlinCompilerVersion.KOTLINC_1_3_72)
.withTargetVersion(KotlinTargetVersion.JAVA_8)
.build());
}
diff --git a/src/test/java/com/android/tools/r8/regress/b191296688/Regress191296688.java b/src/test/java/com/android/tools/r8/regress/b191296688/Regress191296688.java
index e5ed600..8410836 100644
--- a/src/test/java/com/android/tools/r8/regress/b191296688/Regress191296688.java
+++ b/src/test/java/com/android/tools/r8/regress/b191296688/Regress191296688.java
@@ -11,12 +11,12 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
+import com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion;
import com.android.tools.r8.KotlinTestBase;
import com.android.tools.r8.KotlinTestParameters;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestRuntime;
import com.android.tools.r8.TestRuntime.CfRuntime;
-import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ToolHelper.KotlinTargetVersion;
import com.android.tools.r8.utils.DescriptorUtils;
import com.android.tools.r8.utils.codeinspector.ClassSubject;
@@ -41,8 +41,8 @@
return buildParameters(
getTestParameters().withDexRuntimes().withAllApiLevels().build(),
getKotlinTestParameters()
+ .withCompiler(KotlinCompilerVersion.KOTLINC_1_5_0)
.withTargetVersion(KotlinTargetVersion.JAVA_8)
- .withCompiler(ToolHelper.getKotlinC_1_5_0())
.build());
}