Skip to content

Commit c6f916d

Browse files
authored
Sort input files in the test runner. (#168)
While the order of the input files _shouldn't_ affect behavior, it sometimes does. Let's use a consistent order so that we at least don't see behavior differences between local and CI runs: #165 (comment)
1 parent 75aa1de commit c6f916d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

conformance-test-framework/src/main/java/org/jspecify/conformance/ConformanceTestRunner.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
package org.jspecify.conformance;
1616

1717
import static com.google.common.base.Strings.nullToEmpty;
18-
import static com.google.common.collect.ImmutableList.toImmutableList;
18+
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
1919
import static com.google.common.collect.Lists.partition;
2020
import static com.google.common.io.MoreFiles.asCharSink;
2121
import static com.google.common.io.MoreFiles.asCharSource;
2222
import static com.google.common.truth.Truth.assertThat;
2323
import static java.nio.charset.StandardCharsets.UTF_8;
2424
import static java.nio.file.Files.walk;
2525
import static java.util.Arrays.stream;
26+
import static java.util.Comparator.naturalOrder;
2627
import static java.util.stream.Collectors.toList;
2728

2829
import com.google.common.base.Ascii;
2930
import com.google.common.collect.ImmutableList;
31+
import com.google.common.collect.ImmutableSortedSet;
3032
import java.io.IOException;
3133
import java.io.UncheckedIOException;
3234
import java.nio.file.Files;
@@ -48,7 +50,7 @@ public interface Analyzer {
4850
* @return the facts reported by the analysis
4951
*/
5052
Iterable<ReportedFact> analyze(
51-
Path testDirectory, ImmutableList<Path> files, ImmutableList<Path> testDeps);
53+
Path testDirectory, ImmutableSortedSet<Path> files, ImmutableList<Path> testDeps);
5254
}
5355

5456
private final Analyzer analyzer;
@@ -72,26 +74,28 @@ public ConformanceTestReport runTests(Path testDirectory, ImmutableList<Path> te
7274
.filter(path -> path.toFile().isDirectory())
7375
.flatMap(
7476
directory -> {
75-
Stream<ImmutableList<Path>> groups = javaFileGroups(directory);
77+
Stream<ImmutableSortedSet<Path>> groups = javaFileGroups(directory);
7678
return directory.equals(testDirectory)
77-
? groups.flatMap(files -> partition(files, 1).stream())
79+
? groups.flatMap(files -> partition(files.asList(), 1).stream())
7880
: groups;
7981
})
80-
.map(ImmutableList::copyOf)
82+
.map(ImmutableSortedSet::copyOf)
8183
.forEach(
8284
files -> report.addFiles(files, analyzer.analyze(testDirectory, files, testDeps)));
8385
return report.build();
8486
}
8587
}
8688

87-
private static Stream<ImmutableList<Path>> javaFileGroups(Path directory) {
88-
ImmutableList<Path> files = javaFilesInDirectory(directory);
89+
private static Stream<ImmutableSortedSet<Path>> javaFileGroups(Path directory) {
90+
ImmutableSortedSet<Path> files = javaFilesInDirectory(directory);
8991
return files.isEmpty() ? Stream.empty() : Stream.of(files);
9092
}
9193

92-
private static ImmutableList<Path> javaFilesInDirectory(Path directory) {
94+
private static ImmutableSortedSet<Path> javaFilesInDirectory(Path directory) {
9395
try (Stream<Path> files = Files.list(directory)) {
94-
return files.filter(f -> f.toString().endsWith(".java")).collect(toImmutableList());
96+
return files
97+
.filter(f -> f.toString().endsWith(".java"))
98+
.collect(toImmutableSortedSet(naturalOrder()));
9599
} catch (IOException e) {
96100
throw new UncheckedIOException(e);
97101
}

src/test/java/tests/ConformanceTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.common.base.Splitter;
2525
import com.google.common.collect.ImmutableList;
2626
import com.google.common.collect.ImmutableSet;
27+
import com.google.common.collect.ImmutableSortedSet;
2728
import com.google.jspecify.nullness.NullSpecChecker;
2829
import java.io.IOException;
2930
import java.nio.file.Path;
@@ -130,7 +131,7 @@ private static Path systemPropertyPath(String key, String description) {
130131
}
131132

132133
private static ImmutableSet<ReportedFact> analyze(
133-
Path testDirectory, ImmutableList<Path> files, ImmutableList<Path> testDeps) {
134+
Path testDirectory, ImmutableSortedSet<Path> files, ImmutableList<Path> testDeps) {
134135
TestConfiguration config =
135136
TestConfigurationBuilder.buildDefaultConfiguration(
136137
null,

0 commit comments

Comments
 (0)