Consider this example repository.
It has a simple App.java:
public class App
{
public String readFile(String path) throws Exception {
File file = new File(path);
FileInputStream fis = new FileInputStream(file);
return new java.util.Scanner(fis).useDelimiter("\\A").next();
}
}
And it has an AppTest.java.
public class AppTest
extends TestCase
{
public void testApp() throws Exception
{
String path = AppTest.class.getResource("hello.txt").getFile();
System.out.println(path);
App app = new App();
assertEquals("hello", app.readFile(path));
}
}
The repository includes a Maven pom.xml and Bazel WORKSPACE/BUILD files. The test passes when I run "mvn test", but fails when I "bazel test //:test"
In Maven, the classpath contains the exploded target/test-classes directory, so getResource("hello.txt").getFile() returns an absolute file path, suitable for use with App.java.
In Bazel, the resources are first zipped into a jar, so getResource("hello.txt').getFile() returns a jar URL string, like this:
file:/private/var/tmp/_bazel_dfabulich/dea6568d2b91f5e0663b4131b12cb24c/file-resources-example/bazel-out/local_darwin-fastbuild/bin/test.jar!/com/redfin/hello.txt
Note the exclamation point in that path: file:/path/to/test.jar!/com/redfin/hello.txt
I suppose it was inappropriate for the test to assume that it would be run with an exploded directory on the classpath (though that assumption was correct when the test was originally written, in Maven). Nonetheless, I would like Bazel to do what Maven does, and run the tests against an exploded directory, rather than jarring the test resources up.
Is it possible to run Bazel tests in that way?
-Dan