cpoerschke commented on a change in pull request #1743:
URL: https://github.com/apache/lucene-solr/pull/1743#discussion_r516111173



##########
File path: 
lucene/test-framework/src/java/org/apache/lucene/util/VerifyTestClassNamingConvention.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.lucene.util;
+
+import com.carrotsearch.randomizedtesting.RandomizedContext;
+import org.junit.Assume;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UncheckedIOException;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+/**
+ * Enforce test naming convention.
+ */
+public class VerifyTestClassNamingConvention extends AbstractBeforeAfterRule {
+  public static final Pattern ALLOWED_CONVENTION = 
Pattern.compile("(.+?)\\.Test[^.]+");
+
+  private static Set<String> exceptions;
+  static {
+    try {
+      exceptions = new HashSet<>();
+      try (BufferedReader is =
+             new BufferedReader(
+                 new InputStreamReader(
+                   
VerifyTestClassNamingConvention.class.getResourceAsStream("test-naming-exceptions.txt"),
+                   StandardCharsets.UTF_8))) {
+        is.lines().forEach(exceptions::add);
+      }
+    } catch (IOException e) {
+      throw new UncheckedIOException(e);
+    }
+  }
+
+  @Override
+  protected void before() throws Exception {
+    if (TestRuleIgnoreTestSuites.isRunningNested()) {
+      // Ignore nested test suites that test the test framework itself.
+      return;
+    }
+
+    String suiteName = RandomizedContext.current().getTargetClass().getName();
+
+    // You can use this helper method to dump all suite names to a file.
+    // Run gradle with one worker so that it doesn't try to append to the same
+    // file from multiple processes:
+    //
+    // gradlew  test --max-workers 1 -Dtests.useSecurityManager=false
+    //
+    // dumpSuiteNamesOnly(suiteName);
+
+    if (!ALLOWED_CONVENTION.matcher(suiteName).matches()) {
+      // if this class exists on the exception list, leave it.

Review comment:
       Added a commit to the PR re: this.




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to