From ef058cebb735d114f94e147cadc0e2e8ec4a1bbb Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Wed, 15 Sep 2021 15:04:45 -0700 Subject: [PATCH] Added option to write errcov report to file or stdout --- test-framework/src/bin/errcov.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test-framework/src/bin/errcov.rs b/test-framework/src/bin/errcov.rs index 98f8e7b7a3..3881f9a7ea 100644 --- a/test-framework/src/bin/errcov.rs +++ b/test-framework/src/bin/errcov.rs @@ -26,19 +26,19 @@ use leo_test_framework::{ use regex::Regex; use serde_yaml::Value; use std::collections::{BTreeMap, HashSet}; -use std::{ - error::Error, - fs, - io::Write, - path::{Path, PathBuf}, -}; +use std::{error::Error, fs, io, path::PathBuf}; use structopt::{clap::AppSettings, StructOpt}; #[derive(StructOpt)] #[structopt(name = "error-coverage", author = "The Aleo Team ", setting = AppSettings::ColoredHelp)] struct Opt { - #[structopt(short, long, help = "Path to the output file", parse(from_os_str))] - output: PathBuf, + #[structopt( + short, + long, + help = "Path to the output file, defaults to stdout.", + parse(from_os_str) + )] + output: Option, } fn main() { @@ -198,10 +198,13 @@ fn run_with_args(opt: Opt) -> Result<(), Box> { ); results.insert(Value::String(String::from("covered")), Value::Mapping(covered_errors)); results.insert(Value::String(String::from("unknown")), Value::Mapping(unknown_errors)); - //let results_str = serde_yaml::to_string(&results).expect("serialization failed for error coverage report"); - let mut file = fs::File::create(opt.output)?; - serde_yaml::to_writer(file, &results).expect("serialization failed for error coverage report"); + if let Some(pathbuf) = opt.output { + let file = fs::File::create(pathbuf).expect("error creating output file"); + serde_yaml::to_writer(file, &results).expect("serialization failed for error coverage report"); + } else { + serde_yaml::to_writer(io::stdout(), &results).expect("serialization failed for error coverage report"); + } Ok(()) }