Skip to main content

sarif_export/
sarif_export.rs

1//! Build a sample `Report`, export it as SARIF 2.1.0, and print to stdout.
2//!
3//! Requires the `sarif` feature:
4//!
5//! ```text
6//! cargo run --example sarif_export --features sarif > findings.sarif.json
7//! ```
8//!
9//! Demonstrates the severity-to-level mapping and `Evidence::FileRef` →
10//! SARIF `physicalLocation` conversion. Pass and skip checks are absent
11//! from the output (SARIF reports defects, not test results).
12
13use dev_report::{CheckResult, Evidence, Report, Severity};
14
15fn main() {
16    let mut r = Report::new("sample-subject", "0.9.3").with_producer("dev-bench");
17
18    r.push(CheckResult::pass("compile"));
19    r.push(CheckResult::skip("network"));
20
21    r.push(
22        CheckResult::fail("test::round_trip", Severity::Error)
23            .with_detail("expected 42, got 41")
24            .with_evidence(Evidence::file_ref_lines("site", "src/math.rs", 10, 12)),
25    );
26
27    r.push(
28        CheckResult::fail("integration::startup", Severity::Critical)
29            .with_detail("service refused to start")
30            .with_evidence(Evidence::file_ref("source", "src/bin/server.rs")),
31    );
32
33    r.push(
34        CheckResult::warn("style::trailing_ws", Severity::Warning)
35            .with_detail("3 trailing-whitespace warnings"),
36    );
37
38    r.finish();
39
40    println!("{}", r.to_sarif());
41}