Skip to content

Commit

Permalink
[CALCITE-6385] LintTest fails when run in source distribution
Browse files Browse the repository at this point in the history
The testContributorsFileIsSorted and testMailmapFile tests fail cause
they rely on git and there is no git info available in source
distribution.

In fact the tests don't really need git and the paths to the .mailmap
and contributor.yml files can be specified explicitly. This removes
the git requirement and also makes the tests more efficient since there
is no process calls and lookup involved.
  • Loading branch information
zabetak committed Apr 25, 2024
1 parent 1566663 commit f78dd94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ allprojects {
passProperty("user.country", "tr")
passProperty("user.timezone", "UTC")
passProperty("calcite.avatica.version", props.string("calcite.avatica.version"))
passProperty("gradle.rootDir", rootDir.toString())
val props = System.getProperties()
for (e in props.propertyNames() as `java.util`.Enumeration<String>) {
if (e.startsWith("calcite.") || e.startsWith("avatica.")) {
Expand Down
19 changes: 6 additions & 13 deletions core/src/test/java/org/apache/calcite/test/LintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
Expand All @@ -46,10 +48,6 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static com.google.common.collect.Iterables.getOnlyElement;

import static org.apache.calcite.util.Util.filter;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
Expand All @@ -64,6 +62,7 @@ class LintTest {
* space. */
private static final Pattern CALCITE_PATTERN =
Pattern.compile("^(\\[CALCITE-[0-9]{1,4}][ ]).*");
private static final Path ROOT_PATH = Paths.get(System.getProperty("gradle.rootDir"));

@SuppressWarnings("Convert2MethodRef") // JDK 8 requires lambdas
private Puffin.Program<GlobalState> makeProgram() {
Expand Down Expand Up @@ -397,10 +396,7 @@ private static void checkMessage(String subject, String body,
/** Ensures that the {@code contributors.yml} file is sorted by name. */
@Test void testContributorsFileIsSorted() throws IOException {
final ObjectMapper mapper = new YAMLMapper();
final List<File> files = TestUnsafe.getTextFiles();
final File contributorsFile =
getOnlyElement(
filter(files, f -> f.getName().equals("contributors.yml")));
final File contributorsFile = ROOT_PATH.resolve("site/_data/contributors.yml").toFile();
JavaType listType =
mapper.getTypeFactory()
.constructCollectionType(List.class, Contributor.class);
Expand All @@ -416,12 +412,9 @@ private static void checkMessage(String subject, String body,

/** Ensures that the {@code .mailmap} file is sorted. */
@Test void testMailmapFile() {
final List<File> files = TestUnsafe.getTextFiles();
final File contributorsFile =
getOnlyElement(
filter(files, f -> f.getName().equals(".mailmap")));
final File mailmapFile = ROOT_PATH.resolve(".mailmap").toFile();
final List<String> lines = new ArrayList<>();
forEachLineIn(contributorsFile, line -> {
forEachLineIn(mailmapFile, line -> {
if (!line.startsWith("#")) {
lines.add(line);
}
Expand Down

0 comments on commit f78dd94

Please sign in to comment.