use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testGetCanonicalFile.
@Test
public void testGetCanonicalFile() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile canonical = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING).getCanonicalFile();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertNotNull(cfg.formatErrorMessage("Canonical file"), canonical);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testToUri.
@Test
public void testToUri() {
final Context ctx = cfg.getContext();
final Path userDir = cfg.getUserDir();
final boolean allowsUserDir = cfg.allowsUserDir();
if (cfg.needsURI()) {
// Nothing to test for URI path
return;
}
languageAction = (Env env) -> {
final TruffleFile file = env.getTruffleFile(FOLDER_EXISTING).resolve(FILE_EXISTING);
try {
final URI uri = file.toUri();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), allowsUserDir);
Assert.assertEquals(cfg.formatErrorMessage("URI"), userDir.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING).toUri(), uri);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), allowsUserDir);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testList.
@Test
public void testList() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final Path folderExisting = path.resolve(FOLDER_EXISTING);
final TruffleFile file = cfg.needsURI() ? env.getTruffleFile(folderExisting.toUri()) : env.getTruffleFile(folderExisting.toString());
try {
final String expected = path.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING).toString();
final Collection<? extends TruffleFile> children = file.list();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
final Optional<String> expectedFile = children.stream().map(TruffleFile::getAbsoluteFile).map(TruffleFile::getPath).filter(expected::equals).findAny();
Assert.assertTrue(cfg.formatErrorMessage("Expected child"), expectedFile.isPresent());
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method isReadable.
@Test
public void isReadable() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean readable = file.isReadable();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertTrue(cfg.formatErrorMessage("Is readable"), readable);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
use of com.oracle.truffle.api.TruffleFile in project graal by oracle.
the class VirtualizedFileSystemTest method testIsDirectory.
@Test
public void testIsDirectory() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final boolean isDir = file.isDirectory();
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertFalse(cfg.formatErrorMessage("Not directory"), isDir);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
}
};
ctx.eval(LANGAUGE_ID, "");
}
Aggregations