[Test] Use rethrow for checked exception in java-written tests

In 9b5a9ccb `throws Exception` was removed from java test sources and
  all checked exceptions were wrapped with `RuntimeException`

But it was forgotten that there is a `rethrow` utility, which doesn't
  wrap exception but makes the javac happy at the same time
This commit is contained in:
Dmitriy Novozhilov
2024-03-14 10:02:48 +02:00
committed by Space Team
parent 09c27d78b8
commit f288163cbc
9 changed files with 32 additions and 25 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.test.KtAssert; import org.jetbrains.kotlin.test.KtAssert;
import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata; import org.jetbrains.kotlin.test.TestMetadata;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -94,16 +95,16 @@ public class KtTestUtil {
* This clarifies the exception by showing the full path. * This clarifies the exception by showing the full path.
*/ */
String messageWithFullPath = file.getAbsolutePath() + " (No such file or directory)"; String messageWithFullPath = file.getAbsolutePath() + " (No such file or directory)";
throw new RuntimeException( throw ExceptionUtilsKt.rethrow(
new IOException( new IOException(
"Ensure you have your 'Working Directory' configured correctly as the root " + "Ensure you have your 'Working Directory' configured correctly as the root " +
"Kotlin project directory in your test configuration\n\t" + "Kotlin project directory in your test configuration\n\t" +
messageWithFullPath, messageWithFullPath,
fileNotFoundException fileNotFoundException
) )
); );
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.test.ConfigurationKind; import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.KotlinTestWithEnvironmentManagement; import org.jetbrains.kotlin.test.KotlinTestWithEnvironmentManagement;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -53,7 +54,7 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironmentMa
try { try {
doTestWithEnvironment(fileName, createEnvironmentWithMockJdk(ConfigurationKind.NO_KOTLIN_REFLECT)); doTestWithEnvironment(fileName, createEnvironmentWithMockJdk(ConfigurationKind.NO_KOTLIN_REFLECT));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -61,7 +62,7 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironmentMa
try { try {
doTestWithEnvironment(fileName, createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)); doTestWithEnvironment(fileName, createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -526,7 +526,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
try { try {
doMultiFileTest(file, testFiles); doMultiFileTest(file, testFiles);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.CodegenTestCase; import org.jetbrains.kotlin.codegen.CodegenTestCase;
import org.jetbrains.kotlin.test.ConfigurationKind; import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -41,7 +42,7 @@ public abstract class AbstractDefaultArgumentsReflectionTest extends CodegenTest
doTestImpl(path); doTestImpl(path);
} }
catch (IOException e) { catch (IOException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestCaseWithTmpdir; import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
import org.jetbrains.kotlin.test.WithMutedInDatabaseRunTest; import org.jetbrains.kotlin.test.WithMutedInDatabaseRunTest;
import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import org.jetbrains.kotlin.utils.KotlinPaths; import org.jetbrains.kotlin.utils.KotlinPaths;
import org.jetbrains.kotlin.utils.PathUtil; import org.jetbrains.kotlin.utils.PathUtil;
@@ -63,7 +64,7 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
try { try {
exitCode = runProcess(commandLine, executionLog); exitCode = runProcess(commandLine, executionLog);
} catch (ExecutionException e) { } catch (ExecutionException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
if (logName == null) { if (logName == null) {
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.test.util.DescriptorValidator;
import org.jetbrains.kotlin.test.util.JUnit4Assertions; import org.jetbrains.kotlin.test.util.JUnit4Assertions;
import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.Configuration; import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.Configuration;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import org.junit.Assert; import org.junit.Assert;
import java.io.File; import java.io.File;
@@ -66,7 +67,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
try { try {
doTestCompiledJava(javaFileName, COMPARATOR_CONFIGURATION); doTestCompiledJava(javaFileName, COMPARATOR_CONFIGURATION);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -130,7 +131,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
try { try {
doTestCompiledKotlin(ktFileName, ConfigurationKind.ALL, false); doTestCompiledKotlin(ktFileName, ConfigurationKind.ALL, false);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -140,7 +141,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
try { try {
doTestCompiledKotlinImpl(ktFileName, configurationKind, useTypeTableInSerializer); doTestCompiledKotlinImpl(ktFileName, configurationKind, useTypeTableInSerializer);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -223,7 +224,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
doTestJavaAgainstKotlinImpl(expectedFileName); doTestJavaAgainstKotlinImpl(expectedFileName);
} }
catch (Exception e) { catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -256,7 +257,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
try { try {
doTestKotlinAgainstCompiledJavaWithKotlinImpl(expectedFileName); doTestKotlinAgainstCompiledJavaWithKotlinImpl(expectedFileName);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -320,7 +321,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
); );
} }
catch (IOException e) { catch (IOException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -333,7 +334,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
try { try {
fileContent = FileUtil.loadFile(new File(javaFileName)); fileContent = FileUtil.loadFile(new File(javaFileName));
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
List<File> srcFiles = TestFiles.createTestFiles( List<File> srcFiles = TestFiles.createTestFiles(
@@ -387,7 +388,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
usePsiClassFilesReading(), useJavacWrapper(), withForeignAnnotations(), explicitLanguageVersionSettings, usePsiClassFilesReading(), useJavacWrapper(), withForeignAnnotations(), explicitLanguageVersionSettings,
getExtraClasspath(), this::configureEnvironment); getExtraClasspath(), this::configureEnvironment);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
@@ -554,7 +554,7 @@ public class KotlinTestUtils {
try { try {
FileUtil.writeToFile(testDataFile, newText); FileUtil.writeToFile(testDataFile, newText);
} catch (IOException ioException) { } catch (IOException ioException) {
throw new RuntimeException(ioException); throw ExceptionUtilsKt.rethrow(e);
} }
} }
} }
@@ -585,7 +585,7 @@ public class KotlinTestUtils {
try { try {
FileUtil.writeToFile(testDataFile, newText); FileUtil.writeToFile(testDataFile, newText);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }
} }
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.cli.common.modules.ModuleChunk;
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser; import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser;
import org.jetbrains.kotlin.modules.Module; import org.jetbrains.kotlin.modules.Module;
import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -69,7 +70,7 @@ public abstract class AbstractModuleXmlParserTest extends TestCase {
FileUtil.writeToFile(txtFile, actual); FileUtil.writeToFile(txtFile, actual);
} }
catch (IOException e) { catch (IOException e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
fail("Expected data file does not exist. A new file created: " + txtFile); fail("Expected data file does not exist. A new file created: " + txtFile);
} }
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.TestsCompilerError;
import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.test.testFramework.KtParsingTestCase; import org.jetbrains.kotlin.test.testFramework.KtParsingTestCase;
import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@@ -98,7 +99,7 @@ public abstract class AbstractParsingTest extends KtParsingTestCase {
try { try {
doBaseTestImpl(filePath, fileType, contentFilter); doBaseTestImpl(filePath, fileType, contentFilter);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw ExceptionUtilsKt.rethrow(e);
} }
} }