From 539aed32d2381bc75b44c7bae1c014ef60be9ab6 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Thu, 21 Sep 2017 05:20:49 -0400 Subject: [PATCH] Improve information regarding running tests that load resources (#1298) * Improve information regarding running tests that load resources Figuring out how to run isolated generated tests is not imidiately straightforward. This clears up confusion by throwing a more helpful error in the tests and adding a section to the ReadMe. * Cleanup ReadMe and comments after review feedback --- ReadMe.md | 5 +++++ .../jetbrains/kotlin/test/KotlinTestUtils.java | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index 08d1c6d58a0..6bc7e7d5305 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -127,6 +127,11 @@ Also the [JavaScript translation](https://github.com/JetBrains/kotlin/blob/maste Some of the code in the standard library is created by generating code from templates. See the [README](libraries/stdlib/ReadMe.md) in the stdlib section for how run the code generator. The existing templates can be used as examples for creating new ones. +### Running specific generated tests + +If you need to debug a specific generated test, ensure that you have the `Working directory` in your IntelliJ run configuration set +to the root directory of this project. If you don't, every test you try to run will fail with a `No such file or directory` exception. + ## Submitting patches The best way to submit a patch is to [fork the project on github](https://help.github.com/articles/fork-a-repo/) then send us a diff --git a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java index 00164f1d785..324f4a42ad5 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -90,6 +90,7 @@ import org.junit.Assert; import javax.tools.*; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringWriter; import java.lang.reflect.Method; @@ -438,7 +439,21 @@ public class KotlinTestUtils { } public static String doLoadFile(@NotNull File file) throws IOException { - return FileUtil.loadFile(file, CharsetToolkit.UTF8, true); + try { + return FileUtil.loadFile(file, CharsetToolkit.UTF8, true); + } + catch (FileNotFoundException fileNotFoundException) { + /* + * Unfortunately, the FileNotFoundException will only show the relative path in it's exception message. + * This clarifies the exception by showing the full path. + */ + String messageWithFullPath = file.getAbsolutePath() + " (No such file or directory)"; + throw new IOException( + "Ensure you have your 'Working Directory' configured correctly as the root " + + "Kotlin project directory in your test configuration\n\t" + + messageWithFullPath, + fileNotFoundException); + } } public static String getFilePath(File file) {