feat(tvix/tests): Import default.nix inside directory

This requires actually passing the source directory into `interpret` in
the eval tests, but otherwise this is fairly straightforward - if we're
trying to import a directory, just push `default.nix` onto it and import
that instead.

Change-Id: I0b7d4234f81977e78d14dfa651bf0cf9721017e5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6893
Autosubmit: grfn <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2022-10-08 13:48:08 -04:00 committed by grfn
parent 278bccc1ea
commit b4d978cd6a
5 changed files with 11 additions and 2 deletions

View file

@ -52,7 +52,10 @@ pub fn builtins_import(
"import", "import",
&[true], &[true],
move |mut args: Vec<Value>, vm: &mut VM| { move |mut args: Vec<Value>, vm: &mut VM| {
let path = super::coerce_value_to_path(&args.pop().unwrap(), vm)?; let mut path = super::coerce_value_to_path(&args.pop().unwrap(), vm)?;
if path.is_dir() {
path.push("default.nix");
}
let contents = let contents =
std::fs::read_to_string(&path).map_err(|err| ErrorKind::ReadFileError { std::fs::read_to_string(&path).map_err(|err| ErrorKind::ReadFileError {

View file

@ -12,7 +12,7 @@ fn eval_okay_test(code_path: &str) {
let code = std::fs::read_to_string(code_path).expect("should be able to read test code"); let code = std::fs::read_to_string(code_path).expect("should be able to read test code");
let exp = std::fs::read_to_string(exp_path).expect("should be able to read test expectation"); let exp = std::fs::read_to_string(exp_path).expect("should be able to read test expectation");
let result = interpret(&code, None, Default::default()) let result = interpret(&code, Some(code_path.into()), Default::default())
.expect("evaluation of eval-okay test should succeed"); .expect("evaluation of eval-okay test should succeed");
let result_str = format!("{}", result); let result_str = format!("{}", result);

View file

@ -0,0 +1 @@
42

View file

@ -0,0 +1 @@
[ 42 42 ]

View file

@ -0,0 +1,4 @@
[
(import ./directory)
(import ./directory/default.nix)
]