Runfiles { public static Runfiles create() throws IOException { return create(System.getenv()); } private  Runfiles(); static Runfiles create(); static Runfiles create(Map<String, String> env); final String rlocation(String path); abstract Map<String, String> getEnvVars();  }
@Test public void testRlocationArgumentValidation() throws Exception { Path dir = Files.createTempDirectory( FileSystems.getDefault().getPath(System.getenv("TEST_TMPDIR")), null); Runfiles r = Runfiles.create(ImmutableMap.of("RUNFILES_DIR", dir.toString())); assertRlocationArg(r, null, null); assertRlocationArg(r, "", null); assertRlocationArg(r, "../foo", "is not normalized"); assertRlocationArg(r, "foo/..", "is not normalized"); assertRlocationArg(r, "foo/../bar", "is not normalized"); assertRlocationArg(r, "./foo", "is not normalized"); assertRlocationArg(r, "foo/.", "is not normalized"); assertRlocationArg(r, "foo/./bar", "is not normalized"); assertRlocationArg(r, " assertRlocationArg(r, "foo assertRlocationArg(r, "foo assertRlocationArg(r, "\\foo", "path is absolute without a drive letter"); }
@Test public void testIgnoresTestSrcdirWhenJavaRunfilesIsUndefinedAndJustFails() throws Exception { Path dir = Files.createTempDirectory( FileSystems.getDefault().getPath(System.getenv("TEST_TMPDIR")), null); Runfiles.create( ImmutableMap.of( "RUNFILES_DIR", dir.toString(), "RUNFILES_MANIFEST_FILE", "ignored when RUNFILES_MANIFEST_ONLY is not set to 1", "TEST_SRCDIR", "should always be ignored")); Runfiles.create( ImmutableMap.of( "JAVA_RUNFILES", dir.toString(), "RUNFILES_MANIFEST_FILE", "ignored when RUNFILES_MANIFEST_ONLY is not set to 1", "TEST_SRCDIR", "should always be ignored")); try { Runfiles.create( ImmutableMap.of( "RUNFILES_DIR", "", "JAVA_RUNFILES", "", "RUNFILES_MANIFEST_FILE", "ignored when RUNFILES_MANIFEST_ONLY is not set to 1", "TEST_SRCDIR", "should always be ignored")); fail(); } catch (IOException e) { assertThat(e).hasMessageThat().contains("$RUNFILES_DIR and $JAVA_RUNFILES"); } }
@Test public void testFailsToCreateManifestBasedBecauseManifestDoesNotExist() throws Exception { try { Runfiles.create( ImmutableMap.of( "RUNFILES_MANIFEST_ONLY", "1", "RUNFILES_MANIFEST_FILE", "non-existing path")); fail(); } catch (IOException e) { assertThat(e).hasMessageThat().contains("non-existing path"); } }