Policy Coverage (#149)

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2024-02-19 19:10:13 -08:00
committed by GitHub
parent f3d9652a73
commit d3d5367fd4
14 changed files with 141 additions and 104 deletions
+4 -17
View File
@@ -17,6 +17,9 @@ fn rego_eval(
engine.set_strict_builtin_errors(!non_strict);
#[cfg(feature = "coverage")]
engine.set_enable_coverage(coverage);
// Load files from given bundles.
for dir in bundles.iter() {
let entries =
@@ -73,24 +76,8 @@ fn rego_eval(
#[cfg(feature = "coverage")]
if coverage {
println!("\n\nCOVERAGE REPORT");
// Fetch coverage report.
let report = engine.get_coverage_report()?;
for file in report.files.into_iter() {
if file.uncovered.is_empty() {
println!("{} has full coverage", file.path);
continue;
}
println!("{}:", file.path);
for (line, code) in file.code.split('\n').enumerate() {
if file.uncovered.contains(&(line as u32 + 1)) {
println!("\x1b[31m {line:4} {code}\x1b[0m");
} else {
println!(" {line:4} {code}");
}
}
}
println!("{}", report.to_colored_string()?);
}
Ok(())