Skip to content

Commit bf77815

Browse files
committed
Let Gradle select snapshot cases
1 parent f4bc39c commit bf77815

2 files changed

Lines changed: 44 additions & 46 deletions

File tree

scip-snapshots/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ val snapshotTargetroots =
3838
// The case list, expected-golden layout and per-case indexing flags are fixed test metadata defined
3939
// in MinimizedSnapshotScipGenerator; the build only supplies the build-time paths it owns.
4040
val snapshotProperties =
41-
mutableMapOf("snapshot.sourceroot" to rootProject.rootDir.absolutePath)
41+
mutableMapOf(
42+
"snapshot.sourceroot" to rootProject.rootDir.absolutePath,
43+
"snapshot.case.ids" to snapshotCaseInputs.joinToString(",") { it.id },
44+
"snapshot.enabledCases" to enabledSnapshotCaseInputs.joinToString(",") { it.id },
45+
)
4246
.apply {
4347
snapshotTargetroots.forEach { (snapshotCase, targetroot) ->
4448
put(snapshotCase.targetrootProperty, targetroot.singleFile.absolutePath)

scip-snapshots/src/main/java/tests/MinimizedSnapshotScipGenerator.java

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import java.util.ArrayList;
1111
import java.util.Arrays;
1212
import java.util.Comparator;
13+
import java.util.LinkedHashSet;
1314
import java.util.List;
15+
import java.util.Set;
1416
import java.util.stream.Collectors;
1517
import java.util.stream.Stream;
1618
import org.scip_code.scip.Document;
@@ -23,25 +25,10 @@
2325
public class MinimizedSnapshotScipGenerator {
2426
private static final List<SnapshotCaseSpec> SNAPSHOT_CASES =
2527
Arrays.asList(
28+
new SnapshotCaseSpec("java-common", "scip-snapshots/expected/java/common", false, "17"),
29+
new SnapshotCaseSpec("java-25", "scip-snapshots/expected/java-25", false, "25"),
2630
new SnapshotCaseSpec(
27-
"java-common",
28-
"scip-snapshots/expected/java/common",
29-
"snapshot.case.java-common.targetroot",
30-
false,
31-
"17"),
32-
new SnapshotCaseSpec(
33-
"java-25",
34-
"scip-snapshots/expected/java-25",
35-
"snapshot.case.java-25.targetroot",
36-
false,
37-
"25",
38-
25),
39-
new SnapshotCaseSpec(
40-
"kotlin-common",
41-
"scip-snapshots/expected/kotlin/common",
42-
"snapshot.case.kotlin-common.targetroot",
43-
true,
44-
"17"));
31+
"kotlin-common", "scip-snapshots/expected/kotlin/common", true, "17"));
4532

4633
public static final class SnapshotCase {
4734
public final String id;
@@ -71,50 +58,25 @@ public SnapshotContext context() {
7158
private static final class SnapshotCaseSpec {
7259
private final String id;
7360
private final String expectDirectory;
74-
private final String targetrootProperty;
7561
private final boolean aggregateNoEmitInverseRelationships;
7662
private final String jdkVersion;
77-
private final int minimumJavaFeature;
7863

7964
private SnapshotCaseSpec(
8065
String id,
8166
String expectDirectory,
82-
String targetrootProperty,
8367
boolean aggregateNoEmitInverseRelationships,
8468
String jdkVersion) {
85-
this(
86-
id,
87-
expectDirectory,
88-
targetrootProperty,
89-
aggregateNoEmitInverseRelationships,
90-
jdkVersion,
91-
0);
92-
}
93-
94-
private SnapshotCaseSpec(
95-
String id,
96-
String expectDirectory,
97-
String targetrootProperty,
98-
boolean aggregateNoEmitInverseRelationships,
99-
String jdkVersion,
100-
int minimumJavaFeature) {
10169
this.id = id;
10270
this.expectDirectory = expectDirectory;
103-
this.targetrootProperty = targetrootProperty;
10471
this.aggregateNoEmitInverseRelationships = aggregateNoEmitInverseRelationships;
10572
this.jdkVersion = jdkVersion;
106-
this.minimumJavaFeature = minimumJavaFeature;
107-
}
108-
109-
private boolean isEnabled() {
110-
return Runtime.version().feature() >= minimumJavaFeature;
11173
}
11274

11375
private SnapshotCase toSnapshotCase(Path sourceroot) {
11476
return new SnapshotCase(
11577
id,
11678
sourceroot.resolve(expectDirectory),
117-
requiredPathProperty(targetrootProperty),
79+
requiredPathProperty(targetrootProperty(id)),
11880
aggregateNoEmitInverseRelationships,
11981
jdkVersion);
12082
}
@@ -204,16 +166,48 @@ public void onTargetroot(
204166
*/
205167
public static List<SnapshotCase> snapshotCases() {
206168
Path sourceroot = requiredPathProperty("snapshot.sourceroot");
169+
Set<String> buildCaseIds = requiredCsvProperty("snapshot.case.ids");
170+
Set<String> enabledCaseIds = requiredCsvProperty("snapshot.enabledCases");
171+
Set<String> specCaseIds =
172+
SNAPSHOT_CASES.stream()
173+
.map(snapshotCase -> snapshotCase.id)
174+
.collect(Collectors.toCollection(LinkedHashSet::new));
175+
if (!buildCaseIds.equals(specCaseIds)) {
176+
throw new IllegalStateException(
177+
"Snapshot case metadata mismatch. Gradle cases="
178+
+ buildCaseIds
179+
+ ", Java specs="
180+
+ specCaseIds);
181+
}
182+
if (!specCaseIds.containsAll(enabledCaseIds)) {
183+
throw new IllegalStateException(
184+
"Enabled snapshot cases must be a subset of known cases. Enabled="
185+
+ enabledCaseIds
186+
+ ", Java specs="
187+
+ specCaseIds);
188+
}
207189
return SNAPSHOT_CASES.stream()
208-
.filter(SnapshotCaseSpec::isEnabled)
190+
.filter(snapshotCase -> enabledCaseIds.contains(snapshotCase.id))
209191
.map(snapshotCase -> snapshotCase.toSnapshotCase(sourceroot))
210192
.collect(Collectors.toList());
211193
}
212194

195+
private static String targetrootProperty(String id) {
196+
return "snapshot.case." + id + ".targetroot";
197+
}
198+
213199
public static Path requiredPathProperty(String name) {
214200
return Paths.get(requiredProperty(name));
215201
}
216202

203+
private static Set<String> requiredCsvProperty(String name) {
204+
String value = requiredProperty(name);
205+
return Arrays.stream(value.split(","))
206+
.map(String::trim)
207+
.filter(entry -> !entry.isEmpty())
208+
.collect(Collectors.toCollection(LinkedHashSet::new));
209+
}
210+
217211
private static String requiredProperty(String name) {
218212
String value = System.getProperty(name);
219213
if (value == null || value.trim().isEmpty()) {

0 commit comments

Comments
 (0)