//! The `jcp` demo, run as a user runs it: the receipt it seals for its last //! allowed row is over a scripted cost no tool spent, so the line it prints //! for that receipt must grade it `Estimator`, never `HwShunt`. use std::process::Command; #[test] fn the_demo_receipt_is_graded_an_estimate() { let out = Command::new(env!("CARGO_BIN_EXE_jcp")).output().expect("run the jcp binary"); assert!(out.status.success(), "jcp failed: {}", String::from_utf8_lossy(&out.stderr)); let stdout = String::from_utf8(out.stdout).expect("utf-8 output"); eprintln!("{stdout}"); let receipt = stdout.lines().find(|l| l.trim_start().starts_with("receipt")).expect("a receipt line"); assert!(receipt.contains("· Estimator ·"), "the scripted cost's receipt is not graded an estimate: {receipt}"); assert!(!receipt.contains("HwShunt"), "the scripted cost's receipt claims a hardware reading: {receipt}"); assert!(receipt.ends_with("verified true"), "{receipt}"); assert!(stdout.contains("budget-exceeded"), "the script no longer runs the budget out:\n{stdout}"); } /// The `meter` line prints the probe's figure at the grade the meter gave /// that probe, and no other grade beside it: a hardware rung whose probe came /// back an estimate must not be labelled with the rung's best grade. #[test] fn the_meter_line_names_only_the_probes_grade() { let out = Command::new(env!("CARGO_BIN_EXE_jcp")).output().expect("run the jcp binary"); assert!(out.status.success(), "jcp failed: {}", String::from_utf8_lossy(&out.stderr)); let stdout = String::from_utf8(out.stdout).expect("utf-8 output"); let line = stdout.lines().find(|l| l.trim_start().starts_with("meter")).expect("a meter line"); eprintln!("{line}"); let grades: Vec<&str> = ["HwShunt", "ModelBased", "Estimator"].into_iter().filter(|g| line.contains(g)).collect(); assert_eq!(grades.len(), 1, "the meter line names {grades:?}: {line}"); let grade = grades[0]; assert!(line.contains(&format!("[{grade}]")), "the grade printed is not the probe's: {line}"); if grade != "HwShunt" { assert!(!line.contains("hardware-measured") && !line.contains("reading,"), "an estimate called a reading: {line}"); } }