about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2022-10-12T06·18-0700
committerAdam Joseph <adam@westernsemico.com>2022-10-13T02·49+0000
commite83609a06195642f472b112ffa95f001fde8ef60 (patch)
tree6bacd989b4c2d7600e2d3b5c8b81f6891c737760 /tvix/eval
parent7c99e9e8e300e10e8c81856fa9a094ce22876f8d (diff)
feat(tvix/eval): allow to disable warnings r/5117
The nix_tests test suite produces lots of warnings.  We can't fix
these, since they are kept in sync with upstream, so there's little
point in cluttering up the console with them every time the tests
are run.

Let's add a clap flag "warnings" and TVIX_WARNINGS environment
variable.  The default is "true".  The test runner overrides this
default and mutes the warnings.

Signed-off-by: Adam Joseph <adam@westernsemico.com>
Change-Id: I4b065f96fe15838afcca6970491a54e248ae4df7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6985
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/src/eval.rs30
-rw-r--r--tvix/eval/src/tests/mod.rs5
2 files changed, 28 insertions, 7 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index 8973c1a95c19..4787b55fe475 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -25,11 +25,28 @@ pub struct Options {
     #[cfg_attr(feature = "repl", clap(long, env = "TVIX_TRACE_RUNTIME"))]
     trace_runtime: bool,
 
+    /// Print warnings
+    #[cfg_attr(
+        feature = "repl",
+        clap(long, env = "TVIX_WARNINGS", default_value = "true")
+    )]
+    warnings: bool,
+
     /// A colon-separated list of directories to use to resolve `<...>`-style paths
     #[cfg_attr(feature = "repl", clap(long, short = 'I', env = "NIX_PATH"))]
     nix_search_path: Option<NixSearchPath>,
 }
 
+impl Options {
+    #[cfg(test)]
+    pub(crate) fn test_options() -> Options {
+        Options {
+            warnings: false,
+            ..Options::default()
+        }
+    }
+}
+
 pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> EvalResult<Value> {
     let source = SourceCode::new();
     let file = source.add_file(
@@ -97,8 +114,10 @@ pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> Eva
         )
     }?;
 
-    for warning in result.warnings {
-        warning.fancy_format_stderr(&source);
+    if options.warnings {
+        for warning in result.warnings {
+            warning.fancy_format_stderr(&source);
+        }
     }
 
     for error in &result.errors {
@@ -128,10 +147,11 @@ pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> Eva
     }
 
     result.map(|r| {
-        for warning in r.warnings {
-            warning.fancy_format_stderr(&source);
+        if options.warnings {
+            for warning in r.warnings {
+                warning.fancy_format_stderr(&source);
+            }
         }
-
         r.value
     })
 }
diff --git a/tvix/eval/src/tests/mod.rs b/tvix/eval/src/tests/mod.rs
index 8540a5641bcf..03e6f9f0220d 100644
--- a/tvix/eval/src/tests/mod.rs
+++ b/tvix/eval/src/tests/mod.rs
@@ -1,4 +1,5 @@
 use crate::eval::interpret;
+use crate::eval::Options;
 use pretty_assertions::assert_eq;
 
 use test_generator::test_resources;
@@ -12,7 +13,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 exp = std::fs::read_to_string(exp_path).expect("should be able to read test expectation");
 
-    let result = interpret(&code, Some(code_path.into()), Default::default())
+    let result = interpret(&code, Some(code_path.into()), Options::test_options())
         .expect("evaluation of eval-okay test should succeed");
     let result_str = format!("{}", result);
 
@@ -29,7 +30,7 @@ fn eval_okay_test(code_path: &str) {
 fn identity(code_path: &str) {
     let code = std::fs::read_to_string(code_path).expect("should be able to read test code");
 
-    let result = interpret(&code, None, Default::default())
+    let result = interpret(&code, None, Options::test_options())
         .expect("evaluation of identity test should succeed");
     let result_str = format!("{}", result);