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:
committed by
Dmitry Jemerov
parent
9e3f866831
commit
539aed32d2
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user