Skip to content

Commit 539aed3

Browse files
JLLeitschuhyole
authored andcommitted
Improve information regarding running tests that load resources (JetBrains#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
1 parent 9e3f866 commit 539aed3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ReadMe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ Also the [JavaScript translation](https://github.com/JetBrains/kotlin/blob/maste
127127

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

130+
### Running specific generated tests
131+
132+
If you need to debug a specific generated test, ensure that you have the `Working directory` in your IntelliJ run configuration set
133+
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.
134+
130135
## Submitting patches
131136

132137
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

compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090

9191
import javax.tools.*;
9292
import java.io.File;
93+
import java.io.FileNotFoundException;
9394
import java.io.IOException;
9495
import java.io.StringWriter;
9596
import java.lang.reflect.Method;
@@ -438,7 +439,21 @@ public static String doLoadFile(String myFullDataPath, String name) throws IOExc
438439
}
439440

440441
public static String doLoadFile(@NotNull File file) throws IOException {
441-
return FileUtil.loadFile(file, CharsetToolkit.UTF8, true);
442+
try {
443+
return FileUtil.loadFile(file, CharsetToolkit.UTF8, true);
444+
}
445+
catch (FileNotFoundException fileNotFoundException) {
446+
/*
447+
* Unfortunately, the FileNotFoundException will only show the relative path in it's exception message.
448+
* This clarifies the exception by showing the full path.
449+
*/
450+
String messageWithFullPath = file.getAbsolutePath() + " (No such file or directory)";
451+
throw new IOException(
452+
"Ensure you have your 'Working Directory' configured correctly as the root " +
453+
"Kotlin project directory in your test configuration\n\t" +
454+
messageWithFullPath,
455+
fileNotFoundException);
456+
}
442457
}
443458

444459
public static String getFilePath(File file) {

0 commit comments

Comments
 (0)