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
This commit is contained in:
Jonathan Leitschuh
2017-09-21 05:20:49 -04:00
committed by Dmitry Jemerov
parent 9e3f866831
commit 539aed32d2
2 changed files with 21 additions and 1 deletions
+5
View File
@@ -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. 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 ## 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 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
@@ -90,6 +90,7 @@ import org.junit.Assert;
import javax.tools.*; import javax.tools.*;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@@ -438,7 +439,21 @@ public class KotlinTestUtils {
} }
public static String doLoadFile(@NotNull File file) throws IOException { 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) { public static String getFilePath(File file) {