Skip to main content

ruby_plan/
ruby_plan.rs

1//! Development tool: emit the Ruby probe plan for arbitrary files so the
2//! position sweep (`scripts/ruby-position-sweep.rb`) can check every plan key
3//! against what Ruby's `Coverage` module reports for the same source.
4//!
5//! Usage: `cargo run -p supercov-engine --example ruby_plan -- FILE...`
6//! Prints one JSON object: `{ "<path>": { "edits", "branches", "methods",
7//! "lines", "cases", "parseError" } }`.
8
9use std::{collections::BTreeMap, fs};
10
11use supercov_engine::ruby_instrumenter::build_ruby_obligations;
12
13fn main() {
14    let mut output = BTreeMap::new();
15    let mut probe = 0u64;
16    for path in std::env::args().skip(1) {
17        let Ok(source) = fs::read(&path) else {
18            continue;
19        };
20        match build_ruby_obligations(&path, &source, &mut probe) {
21            Ok(obligations) => {
22                output.insert(path, serde_json::to_value(obligations.plan).unwrap());
23            }
24            Err(error) => {
25                output.insert(path, serde_json::json!({ "parseError": error.to_string() }));
26            }
27        }
28    }
29    println!("{}", serde_json::to_string(&output).unwrap());
30}