summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dhall/build.rs18
-rw-r--r--dhall/src/semantics/parse.rs5
-rw-r--r--dhall/src/semantics/resolve/resolve.rs21
-rw-r--r--dhall/tests/import/failure/alternativeEnv.txt1
-rw-r--r--dhall/tests/import/failure/alternativeEnvMissing.txt1
-rw-r--r--dhall/tests/import/failure/unit/EnvUnsetAsText.txt1
-rw-r--r--dhall/tests/import/success/unit/EnvSetAsTextB.dhall2
7 files changed, 33 insertions, 16 deletions
diff --git a/dhall/build.rs b/dhall/build.rs
index 0ff5acc..29219ff 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -249,18 +249,15 @@ fn generate_tests() -> std::io::Result<()> {
too_slow_path: Box::new(|_path: &str| false),
exclude_path: Box::new(|path: &str| {
false
- || path == "alternativeEnvNatural"
- || path == "alternativeEnvSimple"
+ // TODO: import hash
|| path == "alternativeHashMismatch"
+ || path == "hashFromCache"
+ || path == "unit/AlternativeHashMismatch"
+ // TODO: remote imports
|| path == "asLocation"
- || path == "asText"
|| path == "customHeaders"
- || path == "hashFromCache"
|| path == "headerForwarding"
|| path == "noHeaderForwarding"
- || path == "unit/AlternativeHashMismatch"
- || path == "unit/AsText"
- || path == "unit/EnvSetAsText"
|| path == "unit/SimpleRemote"
|| path == "unit/asLocation/Remote"
}),
@@ -274,12 +271,11 @@ fn generate_tests() -> std::io::Result<()> {
too_slow_path: Box::new(|_path: &str| false),
exclude_path: Box::new(|path: &str| {
false
- || path == "alternativeEnv"
- || path == "alternativeEnvMissing"
- || path == "customHeadersUsingBoundVariable"
+ // TODO: import hash
|| path == "hashMismatch"
+ // TODO: remote imports
+ || path == "customHeadersUsingBoundVariable"
|| path == "referentiallyInsane"
- || path == "unit/EnvUnsetAsText"
}),
input_type: FileType::Text,
output_type: Some(FileType::UI),
diff --git a/dhall/src/semantics/parse.rs b/dhall/src/semantics/parse.rs
index ee35536..ffd5eca 100644
--- a/dhall/src/semantics/parse.rs
+++ b/dhall/src/semantics/parse.rs
@@ -9,9 +9,8 @@ use crate::syntax::parse_expr;
use crate::Parsed;
pub(crate) fn parse_file(f: &Path) -> Result<Parsed, Error> {
- let mut buffer = String::new();
- File::open(f)?.read_to_string(&mut buffer)?;
- let expr = parse_expr(&*buffer)?;
+ let text = std::fs::read_to_string(f)?;
+ let expr = parse_expr(&text)?;
let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned());
Ok(Parsed(expr, root))
}
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs
index ad2cd75..f419858 100644
--- a/dhall/src/semantics/resolve/resolve.rs
+++ b/dhall/src/semantics/resolve/resolve.rs
@@ -99,7 +99,26 @@ fn resolve_one_import(
let typed = resolve_with_env(env, parsed)?.typecheck()?;
Ok((typed.normalize().to_hir(), typed.ty().clone()))
}
- ImportMode::RawText => unimplemented!("{:?}", import),
+ ImportMode::RawText => {
+ let text = match &import.location {
+ ImportLocation::Local(prefix, path) => {
+ let path = compute_relative_path(root, prefix, path);
+ std::fs::read_to_string(path)?
+ }
+ ImportLocation::Env(var_name) => match env::var(var_name) {
+ Ok(val) => val,
+ Err(_) => Err(ImportError::MissingEnvVar)?,
+ },
+ ImportLocation::Missing => Err(ImportError::Missing)?,
+ _ => unimplemented!("{:?}", import),
+ };
+
+ let hir = Hir::new(
+ HirKind::Expr(ExprKind::TextLit(text.into())),
+ Span::Artificial,
+ );
+ Ok((hir, Type::from_builtin(Builtin::Text)))
+ }
ImportMode::Location => {
let (field_name, arg) = match &import.location {
ImportLocation::Local(prefix, path) => {
diff --git a/dhall/tests/import/failure/alternativeEnv.txt b/dhall/tests/import/failure/alternativeEnv.txt
new file mode 100644
index 0000000..482b68c
--- /dev/null
+++ b/dhall/tests/import/failure/alternativeEnv.txt
@@ -0,0 +1 @@
+MissingEnvVar
diff --git a/dhall/tests/import/failure/alternativeEnvMissing.txt b/dhall/tests/import/failure/alternativeEnvMissing.txt
new file mode 100644
index 0000000..4666330
--- /dev/null
+++ b/dhall/tests/import/failure/alternativeEnvMissing.txt
@@ -0,0 +1 @@
+Missing
diff --git a/dhall/tests/import/failure/unit/EnvUnsetAsText.txt b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt
new file mode 100644
index 0000000..482b68c
--- /dev/null
+++ b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt
@@ -0,0 +1 @@
+MissingEnvVar
diff --git a/dhall/tests/import/success/unit/EnvSetAsTextB.dhall b/dhall/tests/import/success/unit/EnvSetAsTextB.dhall
index 192548e..a79bb82 100644
--- a/dhall/tests/import/success/unit/EnvSetAsTextB.dhall
+++ b/dhall/tests/import/success/unit/EnvSetAsTextB.dhall
@@ -1 +1 @@
-"42"
+"6 * 7"