feat: init Rust VM
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use fix::context::Context;
|
||||
use fix::error::Source;
|
||||
use fix::runtime::Runtime;
|
||||
use fix::value::Value;
|
||||
|
||||
use crate::utils::{eval, eval_result};
|
||||
@@ -97,7 +97,7 @@ fn import_with_complex_dependency_graph() {
|
||||
|
||||
#[test_log::test]
|
||||
fn path_with_file() {
|
||||
let mut ctx = Context::new().unwrap();
|
||||
let mut ctx = Runtime::new().unwrap();
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let test_file = temp_dir.path().join("test.txt");
|
||||
std::fs::write(&test_file, "Hello, World!").unwrap();
|
||||
@@ -107,7 +107,7 @@ fn path_with_file() {
|
||||
|
||||
// Should return a store path string
|
||||
if let Value::String(store_path) = result {
|
||||
assert!(store_path.starts_with(ctx.get_store_dir()));
|
||||
assert!(store_path.starts_with("/nix/store"));
|
||||
assert!(store_path.contains("test.txt"));
|
||||
} else {
|
||||
panic!("Expected string, got {:?}", result);
|
||||
@@ -136,7 +136,7 @@ fn path_with_custom_name() {
|
||||
|
||||
#[test_log::test]
|
||||
fn path_with_directory_recursive() {
|
||||
let mut ctx = Context::new().unwrap();
|
||||
let mut ctx = Runtime::new().unwrap();
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let test_dir = temp_dir.path().join("mydir");
|
||||
std::fs::create_dir_all(&test_dir).unwrap();
|
||||
@@ -150,7 +150,7 @@ fn path_with_directory_recursive() {
|
||||
let result = ctx.eval(Source::new_eval(expr).unwrap()).unwrap();
|
||||
|
||||
if let Value::String(store_path) = result {
|
||||
assert!(store_path.starts_with(ctx.get_store_dir()));
|
||||
assert!(store_path.starts_with("/nix/store"));
|
||||
assert!(store_path.contains("mydir"));
|
||||
} else {
|
||||
panic!("Expected string, got {:?}", result);
|
||||
@@ -159,7 +159,7 @@ fn path_with_directory_recursive() {
|
||||
|
||||
#[test_log::test]
|
||||
fn path_flat_with_file() {
|
||||
let mut ctx = Context::new().unwrap();
|
||||
let mut ctx = Runtime::new().unwrap();
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let test_file = temp_dir.path().join("flat.txt");
|
||||
std::fs::write(&test_file, "Flat content").unwrap();
|
||||
@@ -171,7 +171,7 @@ fn path_flat_with_file() {
|
||||
let result = ctx.eval(Source::new_eval(expr).unwrap()).unwrap();
|
||||
|
||||
if let Value::String(store_path) = result {
|
||||
assert!(store_path.starts_with(ctx.get_store_dir()));
|
||||
assert!(store_path.starts_with("/nix/store"));
|
||||
} else {
|
||||
panic!("Expected string, got {:?}", result);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use fix::context::Context;
|
||||
use fix::error::Source;
|
||||
use fix::runtime::Runtime;
|
||||
use fix::value::Value;
|
||||
|
||||
fn get_lang_dir() -> PathBuf {
|
||||
@@ -16,7 +16,7 @@ fn eval_file(name: &str) -> Result<(Value, Source), String> {
|
||||
|
||||
let expr = format!(r#"import "{}""#, nix_path.display());
|
||||
|
||||
let mut ctx = Context::new().map_err(|e| e.to_string())?;
|
||||
let mut ctx = Runtime::new().map_err(|e| e.to_string())?;
|
||||
let source = Source {
|
||||
ty: fix::error::SourceType::File(nix_path.into()),
|
||||
src: expr.into(),
|
||||
@@ -247,7 +247,7 @@ eval_fail_test!(fail_abort);
|
||||
eval_fail_test!(fail_addDrvOutputDependencies_empty_context);
|
||||
eval_fail_test!(fail_addDrvOutputDependencies_multi_elem_context);
|
||||
eval_fail_test!(fail_addDrvOutputDependencies_wrong_element_kind);
|
||||
eval_fail_test!(fail_addErrorContext_example);
|
||||
eval_fail_test!(fail_addErrorRuntime_example);
|
||||
eval_fail_test!(fail_assert);
|
||||
eval_fail_test!(fail_assert_equal_attrs_names);
|
||||
eval_fail_test!(fail_assert_equal_attrs_names_2);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use fix::context::Context;
|
||||
use fix::runtime::Runtime;
|
||||
use fix::value::Value;
|
||||
|
||||
use crate::utils::eval_result;
|
||||
@@ -153,8 +153,8 @@ fn string_add_merges_context() {
|
||||
|
||||
#[test_log::test]
|
||||
fn context_in_derivation_args() {
|
||||
let mut ctx = Context::new().unwrap();
|
||||
let result = ctx
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let result = rt
|
||||
.eval(
|
||||
r#"
|
||||
let
|
||||
@@ -173,7 +173,7 @@ fn context_in_derivation_args() {
|
||||
.unwrap();
|
||||
match result {
|
||||
Value::String(s) => {
|
||||
assert!(s.starts_with(ctx.get_store_dir()), "Should be a store path");
|
||||
assert!(s.starts_with("/nix/store"), "Should be a store path");
|
||||
assert!(s.ends_with(".drv"), "Should be a .drv file");
|
||||
}
|
||||
_ => panic!("Expected String, got {:?}", result),
|
||||
@@ -182,8 +182,8 @@ fn context_in_derivation_args() {
|
||||
|
||||
#[test_log::test]
|
||||
fn context_in_derivation_env() {
|
||||
let mut ctx = Context::new().unwrap();
|
||||
let result = ctx
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let result = rt
|
||||
.eval(
|
||||
r#"
|
||||
let
|
||||
@@ -202,7 +202,7 @@ fn context_in_derivation_env() {
|
||||
.unwrap();
|
||||
match result {
|
||||
Value::String(s) => {
|
||||
assert!(s.starts_with(ctx.get_store_dir()), "Should be a store path");
|
||||
assert!(s.starts_with("/nix/store"), "Should be a store path");
|
||||
assert!(s.ends_with(".drv"), "Should be a .drv file");
|
||||
}
|
||||
_ => panic!("Expected String, got {:?}", result),
|
||||
@@ -224,8 +224,8 @@ fn tostring_preserves_context() {
|
||||
|
||||
#[test_log::test]
|
||||
fn interpolation_derivation_returns_outpath() {
|
||||
let mut ctx = Context::new().unwrap();
|
||||
let result = ctx
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let result = rt
|
||||
.eval(
|
||||
r#"
|
||||
let
|
||||
@@ -238,7 +238,7 @@ fn interpolation_derivation_returns_outpath() {
|
||||
.unwrap();
|
||||
match result {
|
||||
Value::String(s) => {
|
||||
assert!(s.starts_with(ctx.get_store_dir()), "Should be a store path");
|
||||
assert!(s.starts_with("/nix/store"), "Should be a store path");
|
||||
assert!(s.ends_with("-test"), "Should end with derivation name");
|
||||
}
|
||||
_ => panic!("Expected String, got {:?}", result),
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use fix::context::Context;
|
||||
use fix::error::{Result, Source};
|
||||
use fix::runtime::Runtime;
|
||||
use fix::value::Value;
|
||||
|
||||
pub fn eval(expr: &str) -> Value {
|
||||
Context::new()
|
||||
Runtime::new()
|
||||
.unwrap()
|
||||
.eval(Source::new_eval(expr.into()).unwrap())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn eval_deep(expr: &str) -> Value {
|
||||
Context::new()
|
||||
Runtime::new()
|
||||
.unwrap()
|
||||
.eval_deep(Source::new_eval(expr.into()).unwrap())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn eval_deep_result(expr: &str) -> Result<Value> {
|
||||
Context::new()
|
||||
Runtime::new()
|
||||
.unwrap()
|
||||
.eval_deep(Source::new_eval(expr.into()).unwrap())
|
||||
}
|
||||
|
||||
pub fn eval_result(expr: &str) -> Result<Value> {
|
||||
Context::new()
|
||||
Runtime::new()
|
||||
.unwrap()
|
||||
.eval(Source::new_eval(expr.into()).unwrap())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user