use rong::*;
use std::path::PathBuf;
mod dir;
mod file;
mod misc;
mod rong_file;
mod sink;
mod stat;
mod write;
fn grant_file_access(path: &str) -> JSResult<PathBuf> {
Ok(PathBuf::from(path))
}
pub fn init(ctx: &JSContext) -> JSResult<()> {
rong_stream::init(ctx)?;
stat::init(ctx)?;
sink::init(ctx)?;
file::init(ctx)?;
rong_file::init(ctx)?;
write::init(ctx)?;
dir::init(ctx)?;
misc::init(ctx)?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use rong_test::*;
use std::env;
#[test]
fn test_filesystem() {
async_run!(|ctx: JSContext| async move {
rong_encoding::init(&ctx)?;
rong_console::init(&ctx)?;
rong_assert::init(&ctx)?;
rong_abort::init(&ctx)?;
rong_exception::init(&ctx)?;
init(&ctx)?;
let workspace_root = env::current_dir()
.map_err(|e| {
HostError::new(
rong::error::E_INTERNAL,
format!("Failed to get current dir: {}", e),
)
})?
.parent()
.and_then(|p| p.parent()) .ok_or_else(|| {
HostError::new(rong::error::E_INTERNAL, "Failed to get workspace root")
})?
.to_string_lossy()
.into_owned();
ctx.global().set("WORKSPACE_ROOT", workspace_root)?;
let passed_fs = UnitJSRunner::load_script(&ctx, "filesystem.js")
.await?
.run()
.await?;
assert!(passed_fs);
Ok(())
});
}
}