Testing infra: Assert that there are no unused 'after' files

GitOrigin-RevId: 6d3a515b318ab0ff7d036e21765473e772d0a5c0
This commit is contained in:
Roman.Ivanov
2019-10-14 12:32:51 +00:00
committed by intellij-monorepo-bot
parent 56836fb0f6
commit 74ebe249a6
6 changed files with 30 additions and 24 deletions
@@ -1,11 +0,0 @@
// "Unwrap 'else' branch (changes semantics)" "true"
class T {
String f(boolean b) {
if (b)
System.out.println("When true");
else
return "Otherwise";
return "Default";
}
}
@@ -7,5 +7,5 @@ import java.util.Set;
public class Test {
static final String CONST = "b";
public static final Set<String> MY_SET = Set.of("a", "b", "c", CONST);
public static final Set<String> MY_SET = Set.o<caret>f("a", "b", "c", CONST);
}
@@ -1,9 +0,0 @@
// "Replace condition with Objects.requireNonNullElse" "true"
import java.util.*;
class Test {
public void test(Object o) {
o = Objects.requireNonNullElse(o, "");
}
}
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon.quickFix;
import com.intellij.testFramework.FileBasedTestCaseHelperEx;
import com.intellij.testFramework.Parameterized;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,6 +36,13 @@ public abstract class LightQuickFixParameterizedTestCase extends LightQuickFixTe
return fileName.substring(BEFORE_PREFIX.length());
}
@Nullable
@Override
public String getFileAfterSuffix(@NotNull String fileName) {
if (!fileName.startsWith(AFTER_PREFIX)) return null;
return fileName.substring(AFTER_PREFIX.length());
}
@Test
public void runSingle() throws Throwable {
runSingleTest(() -> doSingleTest(myFileSuffix, myTestDataPath));
@@ -15,6 +15,7 @@
*/
package com.intellij.testFramework;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -33,4 +34,12 @@ public interface FileBasedTestCaseHelper {
*/
@Nullable
String getFileSuffix(String fileName);
/**
* @return for 'after' files should return core file name or null otherwise
*/
@Nullable
default String getFileAfterSuffix(@NotNull String fileName) {
return null;
}
}
@@ -55,9 +55,7 @@ import org.junit.runners.Parameterized;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTestCase {
private Editor myEditor;
@@ -716,13 +714,24 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
fail("Test files not found in " + testDir.getPath());
}
final Set<String> beforeFileSuffixes = new HashSet<>();
final Set<String> afterFileSuffixes = new HashSet<>();
final List<Object[]> result = new ArrayList<>();
for (File file : files) {
final String fileSuffix = fileBasedTestCase.getFileSuffix(file.getName());
String fileAfterSuffix = fileBasedTestCase.getFileAfterSuffix(file.getName());
if (fileAfterSuffix != null) {
afterFileSuffixes.add(fileAfterSuffix);
}
if (fileSuffix != null) {
beforeFileSuffixes.add(fileSuffix);
result.add(new Object[] {fileSuffix, testDataPath});
}
}
afterFileSuffixes.removeAll(beforeFileSuffixes);
if (!afterFileSuffixes.isEmpty()) {
fail("'After' file has no corresponding 'before' file: " + String.join(", ", afterFileSuffixes));
}
return result;
}