From e83609a06195642f472b112ffa95f001fde8ef60 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 11 Oct 2022 23:18:25 -0700 Subject: feat(tvix/eval): allow to disable warnings 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 Change-Id: I4b065f96fe15838afcca6970491a54e248ae4df7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6985 Reviewed-by: tazjin Reviewed-by: grfn Tested-by: BuildkiteCI --- tvix/eval/src/eval.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'tvix/eval/src/eval.rs') 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, } +impl Options { + #[cfg(test)] + pub(crate) fn test_options() -> Options { + Options { + warnings: false, + ..Options::default() + } + } +} + pub fn interpret(code: &str, location: Option, options: Options) -> EvalResult { let source = SourceCode::new(); let file = source.add_file( @@ -97,8 +114,10 @@ pub fn interpret(code: &str, location: Option, 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, 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 }) } -- cgit 1.4.1