You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "ILuffZhe (via GitHub)" <gi...@apache.org> on 2023/06/08 01:11:56 UTC

[GitHub] [calcite] ILuffZhe commented on a diff in pull request #3250: [CALCITE-5706] Add class PairList (and other changes)

ILuffZhe commented on code in PR #3250:
URL: https://github.com/apache/calcite/pull/3250#discussion_r1222330296


##########
testkit/src/main/java/org/apache/calcite/util/TestUtil.java:
##########
@@ -310,6 +315,38 @@ public static String getJavaVirtualMachineVendor() {
     return System.getProperty("java.vm.vendor");
   }
 
+  /** Returns the root directory of the source tree. */
+  public static File getBaseDir(Class<?> klass) {
+    // Algorithm:
+    // 1) Find location of TestUtil.class
+    // 2) Climb via getParentFile() until we detect pom.xml
+    // 3) It means we've got BASE/testkit/pom.xml, and we need to get BASE
+    final URL resource = klass.getResource(klass.getSimpleName() + ".class");
+    final File testUtilClass =
+        Sources.of(requireNonNull(resource, "resource")).file();
+
+    File file = testUtilClass.getAbsoluteFile();
+    for (int i = 0; i < 42; i++) {
+      if (isProjectDir(file)) {
+        // Ok, file == BASE/testkit/
+        break;
+      }
+      file = file.getParentFile();
+    }
+    if (!isProjectDir(file)) {
+      fail("Could not find either testkit/pom.xml or testkit/build.gradle.kts. "
+          + "Started with " + testUtilClass.getAbsolutePath()
+          + ", the current path is " + file.getAbsolutePath());
+    }
+    return file.getParentFile();
+  }
+
+  private static boolean isProjectDir(File dir) {
+    return new File(dir, "pom.xml").isFile()

Review Comment:
   Do we still need to find a pom.xml?



##########
testkit/src/main/java/org/apache/calcite/util/TestUtil.java:
##########
@@ -310,6 +315,38 @@ public static String getJavaVirtualMachineVendor() {
     return System.getProperty("java.vm.vendor");
   }
 
+  /** Returns the root directory of the source tree. */
+  public static File getBaseDir(Class<?> klass) {
+    // Algorithm:
+    // 1) Find location of TestUtil.class
+    // 2) Climb via getParentFile() until we detect pom.xml
+    // 3) It means we've got BASE/testkit/pom.xml, and we need to get BASE
+    final URL resource = klass.getResource(klass.getSimpleName() + ".class");
+    final File testUtilClass =
+        Sources.of(requireNonNull(resource, "resource")).file();
+
+    File file = testUtilClass.getAbsoluteFile();
+    for (int i = 0; i < 42; i++) {
+      if (isProjectDir(file)) {
+        // Ok, file == BASE/testkit/
+        break;
+      }
+      file = file.getParentFile();
+    }
+    if (!isProjectDir(file)) {
+      fail("Could not find either testkit/pom.xml or testkit/build.gradle.kts. "

Review Comment:
   The message should alse include "gradle.properties" since we find it in isProjectDir().



##########
core/src/test/java/org/apache/calcite/sql/test/LintTest.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.test;
+
+import org.apache.calcite.util.Puffin;
+import org.apache.calcite.util.Source;
+import org.apache.calcite.util.Sources;
+import org.apache.calcite.util.TestUnsafe;
+import org.apache.calcite.util.TestUtil;
+import org.apache.calcite.util.Util;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.empty;
+
+/** Various automated checks on the documentation. */
+class LintTest {
+  @SuppressWarnings("Convert2MethodRef") // JDK 8 requires lambdas
+  private Puffin.Program<GlobalState> makeProgram() {
+    return Puffin.builder(GlobalState::new, global -> new FileState(global))
+        .add(line -> line.fnr() == 1,
+            line -> line.globalState().fileCount++)
+
+        // Javadoc does not require '</p>', so we do not allow '</p>'
+        .add(line -> line.state().inJavadoc()
+                && line.contains("</p>"),
+            line -> line.state().message("no '</p>'", line))
+
+        // No "**/"
+        .add(line -> line.contains("**/")
+                && line.state().inJavadoc(),
+            line ->
+                line.state().message("no '**/'; use '*/'",
+                    line))
+
+        // A Javadoc paragraph '<p>' must not be on its own line.
+        .add(line -> line.matches("^ *\\* <p>"),
+            line ->
+                line.state().message("<p> must not be on its own line",
+                    line))
+
+        // A Javadoc paragraph '<p>' must be preceded by a blank Javadoc
+        // line.
+        .add(line -> line.matches("^ *\\*"),
+            line -> line.state().starLine = line.fnr())
+        .add(line -> line.matches("^ *\\* <p>.*")
+                && line.fnr() - 1 != line.state().starLine,
+            line ->
+                line.state().message("<p> must be preceded by blank line",
+                    line))
+
+        // The first "@param" of a javadoc block must be preceded by a blank
+        // line.
+        .add(line -> line.matches("^ */\\*\\*.*"),
+            line -> line.state().javadocStartLine = line.fnr())
+        .add(line -> line.matches(".*\\*/"),
+            line -> line.state().javadocEndLine = line.fnr())
+        .add(line -> line.matches("^ *\\* @.*"),
+            line -> {
+              if (line.state().inJavadoc()
+                  && line.state().atLine < line.state().javadocStartLine
+                  && line.fnr() - 1 != line.state().starLine) {
+                line.state().message(
+                    "First @tag must be preceded by blank line",
+                    line);
+              }
+              line.state().atLine = line.fnr();
+            })
+        .build();
+  }
+
+  @Test void testProgramWorks() {
+    final String code = "class {\n"

Review Comment:
   Nitpick:This is a great test that shows how the javadoc is checked in a java file, and it's better for me to understand if we change the first line to "class A {\n"(whatever with a class name). But I'm OK with it if it remains still.



##########
core/src/test/java/org/apache/calcite/util/TestUnsafe.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.util;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * Unsafe methods to be used by tests.
+ *
+ * <p>Contains methods that call JDK methods that the
+ * <a href="https://github.com/policeman-tools/forbidden-apis">forbidden
+ * APIs checker</a> does not approve of.

Review Comment:
   Minor: do not approve of.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org