use std::fmt::Write as _;
use std::path::{Path, PathBuf};
use std::process::{Command, ExitCode, Stdio};
use crate::build::BuildMessage;
use crate::doc::TestPlaces;
const IMAGE: &str = ".hexicon-test.hxg";
const RESULTS: &str = ".hexicon-test-results.txt";
const PRINTED: &str = ".hexicon-test-printed.md";
const CLOCK: &str = "2000-01-01T09:15:00";
#[derive(Default)]
struct Asked<'a> {
names: Vec<&'a str>,
walkthroughs: bool,
print: bool,
for_players: bool,
}
pub(crate) fn run(args: &[&str], usage: &str) -> ExitCode {
let mut manifest: Option<&str> = None;
let mut transcript: Option<&str> = None;
let mut report_file: Option<&str> = None;
let mut library_dirs: Vec<&str> = Vec::new();
let mut asked = Asked::default();
let mut rest = args;
while let Some((first, tail)) = rest.split_first() {
match (*first, tail) {
("-f", [path, tail @ ..]) => {
manifest = Some(path);
rest = tail;
}
("--library-path", [dir, tail @ ..]) => {
library_dirs.push(dir);
rest = tail;
}
("--transcript", [path, tail @ ..]) => {
transcript = Some(path);
rest = tail;
}
("--report", [path, tail @ ..]) => {
report_file = Some(path);
rest = tail;
}
("--walkthroughs", _) => {
asked.walkthroughs = true;
rest = tail;
}
("--for-players", _) => {
asked.for_players = true;
rest = tail;
}
("--print", [name, tail @ ..]) => {
asked.print = true;
asked.names = vec![name];
rest = tail;
}
(option, _) if option.starts_with('-') => {
eprint!("{usage}");
return ExitCode::from(2);
}
(name, _) => {
asked.names.push(name);
rest = tail;
}
}
}
if (asked.print && asked.names.len() != 1) || (asked.for_players && !asked.print) {
eprint!("{usage}");
return ExitCode::from(2);
}
let folder = match manifest {
Some(path) if Path::new(path).is_dir() => PathBuf::from(path),
Some(path) => Path::new(path)
.parent()
.map(Path::to_path_buf)
.unwrap_or_default(),
None => PathBuf::from("."),
};
let folder = if folder.as_os_str().is_empty() {
PathBuf::from(".")
} else {
folder
};
let image = folder.join(IMAGE);
let results = folder.join(RESULTS);
let printed = folder.join(PRINTED);
let _ = std::fs::remove_file(&results);
let _ = std::fs::remove_file(&printed);
let mut project_args = vec!["-d".to_owned()];
if let Some(path) = manifest {
project_args.push("-f".to_owned());
project_args.push(path.to_owned());
}
for dir in &library_dirs {
project_args.push("--library-path".to_owned());
project_args.push((*dir).to_owned());
}
let write_report = |text: String| {
if let Some(path) = report_file
&& let Err(error) = std::fs::write(path, text)
{
eprintln!("hexicon test: {path}: {error}");
}
};
let mut messages = Vec::new();
let built = crate::build::build_project(
&project_args,
usage,
None,
Some(&image.to_string_lossy()),
report_file.map(|_| &mut messages),
);
if built != ExitCode::SUCCESS {
eprintln!("hexicon test: the game could not be built");
write_report(json_report(&Reported::NotBuilt(&messages)));
return ExitCode::from(2);
}
let places = if report_file.is_some() {
crate::doc::test_places(&project_args)
} else {
TestPlaces {
problems: crate::doc::choice_problems(&project_args)
.into_iter()
.map(|problem| (problem, None))
.collect(),
..TestPlaces::default()
}
};
let problems: Vec<&str> = places.problems.iter().map(|(p, _)| p.as_str()).collect();
let played = play(&folder, &asked);
let _ = std::fs::remove_file(&image);
let said = match played {
Ok(said) => said,
Err(error) => {
eprintln!("hexicon test: the game could not be played: {error}");
write_report(json_report(&Reported::NotPlayed {
messages: &messages,
problem: format!("the game could not be played: {error}"),
}));
return ExitCode::from(2);
}
};
if let Some(path) = transcript
&& let Err(error) = std::fs::write(path, &said)
{
eprintln!("hexicon test: {path}: {error}");
}
let lines = std::fs::read_to_string(&results).unwrap_or_default();
let document = std::fs::read_to_string(&printed).unwrap_or_default();
let _ = std::fs::remove_file(&results);
let _ = std::fs::remove_file(&printed);
let Some(results) = parse(&lines) else {
eprintln!(
"hexicon test: the game did not play its scenarios: does its \
manifest include Hexad's extensions/scenarios? What it printed \
ends:"
);
let tail: Vec<&str> = said.lines().rev().take(12).collect();
for line in tail.iter().rev() {
eprintln!(" {line}");
}
write_report(json_report(&Reported::NotPlayed {
messages: &messages,
problem: "the game did not play its scenarios: does its manifest include \
Hexad's extensions/scenarios?"
.to_owned(),
}));
return ExitCode::from(2);
};
let (mut text, status) = text_report(&results, transcript.is_some());
write_report(json_report(&Reported::Played {
messages: &messages,
results: &results,
places: &places,
status: if status == ExitCode::SUCCESS { 0 } else { 1 },
}));
if !problems.is_empty() {
text.push_str("\nThe game's choices, read:\n");
for problem in &problems {
let _ = writeln!(text, " {problem}");
}
}
if asked.print {
eprint!("{text}");
if status == ExitCode::SUCCESS {
print!("{document}");
}
} else {
print!("{text}");
}
status
}
fn play(folder: &Path, asked: &Asked<'_>) -> std::io::Result<String> {
let mut command = Command::new(std::env::current_exe()?);
command
.args([
"run",
"--no-random",
"--clock",
CLOCK,
"--plain",
"--no-pause",
IMAGE,
])
.arg(format!("-hexicon-test={RESULTS}"))
.args(asked.names.iter().map(|name| format!("-scenario={name}")))
.current_dir(folder)
.env("TZ", "Etc/UTC")
.stdin(Stdio::null());
if asked.walkthroughs {
command.arg("-walkthroughs");
}
if asked.print {
command.arg(format!("-hexicon-print={PRINTED}"));
}
if asked.for_players {
command.arg("-for-players");
}
let done = command.output()?;
let mut said = String::from_utf8_lossy(&done.stdout).replace('\r', "");
said.push_str(&String::from_utf8_lossy(&done.stderr).replace('\r', ""));
Ok(said)
}
struct Outcome {
walkthrough: bool,
name: String,
outcome: String,
steps: String,
after: String,
notes: Vec<String>,
failure: Option<Failure>,
}
struct Failure {
step: String,
command: String,
why: String,
what: String,
place: String,
said: String,
kind: String,
scenario: String,
step_in: String,
}
enum Covered {
Moment {
name: String,
state: String,
symbol: String,
},
Choice {
moment: String,
label: String,
state: String,
symbol: String,
},
}
struct Results {
outcomes: Vec<Outcome>,
covered: Vec<Covered>,
passed: usize,
failed: usize,
not_run: usize,
}
fn parse(lines: &str) -> Option<Results> {
let mut outcomes: Vec<Outcome> = Vec::new();
let mut covered = Vec::new();
let mut done: Option<(usize, usize, usize)> = None;
let owned = |s: &&str| (*s).to_owned();
for line in lines.lines() {
let fields: Vec<&str> = line.split('\t').collect();
match fields.as_slice() {
[
kind @ ("scenario" | "walkthrough"),
name,
outcome,
steps,
after,
] => {
outcomes.push(Outcome {
walkthrough: *kind == "walkthrough",
name: (*name).to_owned(),
outcome: (*outcome).to_owned(),
steps: (*steps).to_owned(),
after: (*after).to_owned(),
notes: Vec::new(),
failure: None,
});
}
["note", name, note] => {
if let Some(found) = outcomes.iter_mut().rfind(|o| o.name == *name) {
found.notes.push((*note).to_owned());
}
}
["failure", name, rest @ ..] if rest.len() == 6 || rest.len() == 9 => {
let more = |n: usize| rest.get(n).map(owned).unwrap_or_default();
if let Some(found) = outcomes.iter_mut().rfind(|o| o.name == *name) {
found.failure = Some(Failure {
step: more(0),
command: more(1),
why: more(2),
what: more(3),
place: more(4),
said: more(5),
kind: more(6),
scenario: more(7),
step_in: more(8),
});
}
}
["choice-moment", name, state, symbol @ ..] if symbol.len() <= 1 => {
covered.push(Covered::Moment {
name: (*name).to_owned(),
state: (*state).to_owned(),
symbol: symbol.first().map(owned).unwrap_or_default(),
});
}
["choice", moment, label, state, symbol @ ..] if symbol.len() <= 1 => {
covered.push(Covered::Choice {
moment: (*moment).to_owned(),
label: (*label).to_owned(),
state: (*state).to_owned(),
symbol: symbol.first().map(owned).unwrap_or_default(),
});
}
["done", passed, failed, not_run] => {
done = match (passed.parse(), failed.parse(), not_run.parse()) {
(Ok(p), Ok(f), Ok(n)) => Some((p, f, n)),
_ => None,
};
}
_ => {}
}
}
let (passed, failed, not_run) = done?;
Some(Results {
outcomes,
covered,
passed,
failed,
not_run,
})
}
impl Covered {
fn unplayed(&self) -> Option<String> {
match self {
Covered::Moment { name, state, .. } => {
(state != "begun").then(|| format!("{name}: never begun"))
}
Covered::Choice {
moment,
label,
state,
..
} => match state.as_str() {
"chosen" => None,
"listed" => Some(format!("{moment}: \"{label}\", listed, never chosen")),
_ => Some(format!("{moment}: \"{label}\", never listed")),
},
}
}
}
fn text_report(results: &Results, kept: bool) -> (String, ExitCode) {
let mut out = String::new();
if results.outcomes.is_empty() {
out.push_str("There are no scenarios.\n");
return (out, ExitCode::SUCCESS);
}
for outcome in &results.outcomes {
let name = if outcome.walkthrough {
format!("walkthrough: {}", outcome.name)
} else {
outcome.name.clone()
};
match outcome.outcome.as_str() {
"passed" => {
let s = if outcome.steps == "1" { "" } else { "s" };
let _ = writeln!(out, "passed {name} ({} step{s})", outcome.steps);
}
"not run" => {
let _ = writeln!(
out,
"not run {name}, since \"{}\" did not pass",
outcome.after
);
}
_ => {
let _ = writeln!(out, "FAILED {name}");
if let Some(failure) = &outcome.failure {
let step = &failure.step;
if step == "0" {
} else if failure.command.is_empty() {
let _ = writeln!(out, " at step {step}");
} else {
let _ = writeln!(out, " at step {step}: {}", failure.command);
}
if !failure.why.is_empty() {
let _ = writeln!(out, " why: {}", failure.why);
}
if failure.place.is_empty() {
let _ = writeln!(out, " failed: {}", failure.what);
} else {
let _ = writeln!(
out,
" failed: {}, at {}",
failure.what, failure.place
);
}
if !failure.said.is_empty() {
let _ = writeln!(out, " the game said: {}", failure.said);
}
}
}
}
for note in &outcome.notes {
let _ = writeln!(out, " note: {note}");
}
}
let (passed, failed, not_run) = (results.passed, results.failed, results.not_run);
let _ = writeln!(out, "\n{passed} passed, {failed} failed, {not_run} not run");
let choices = results
.covered
.iter()
.filter(|c| matches!(c, Covered::Choice { .. }))
.count();
let unplayed: Vec<String> = results
.covered
.iter()
.filter_map(Covered::unplayed)
.collect();
if choices > 0 {
if unplayed.is_empty() {
let _ = writeln!(out, "Every choice was chosen in a scenario.");
} else {
let _ = writeln!(out, "\nWhat the scenarios did not play of the choices:");
for line in &unplayed {
let _ = writeln!(out, " {line}");
}
}
}
if failed + not_run == 0 {
return (out, ExitCode::SUCCESS);
}
if !kept {
out.push_str("(--transcript <file> keeps the whole of what the game said)\n");
}
(out, ExitCode::FAILURE)
}
enum Reported<'a> {
NotBuilt(&'a [BuildMessage]),
NotPlayed {
messages: &'a [BuildMessage],
problem: String,
},
Played {
messages: &'a [BuildMessage],
results: &'a Results,
places: &'a TestPlaces,
status: u8,
},
}
enum Json {
Null,
Bool(bool),
Number(usize),
Text(String),
List(Vec<Json>),
Object(Vec<(&'static str, Json)>),
}
impl Json {
fn text(s: &str) -> Json {
Json::Text(s.to_owned())
}
fn text_or_null(s: &str) -> Json {
if s.is_empty() {
Json::Null
} else {
Json::text(s)
}
}
fn count_or_null(s: &str) -> Json {
match s.parse::<usize>() {
Ok(n) if n > 0 => Json::Number(n),
_ => Json::Null,
}
}
fn write(&self, out: &mut String, depth: usize) {
let pad = |out: &mut String, depth: usize| out.push_str(&" ".repeat(depth));
match self {
Json::Null => out.push_str("null"),
Json::Bool(b) => out.push_str(if *b { "true" } else { "false" }),
Json::Number(n) => out.push_str(&n.to_string()),
Json::Text(s) => {
out.push('"');
for c in s.chars() {
match c {
'"' => out.push_str("\\\""),
'\\' => out.push_str("\\\\"),
'\n' => out.push_str("\\n"),
'\r' => out.push_str("\\r"),
'\t' => out.push_str("\\t"),
c if (c as u32) < 0x20 => {
let _ = write!(out, "\\u{:04x}", c as u32);
}
c => out.push(c),
}
}
out.push('"');
}
Json::List(items) if items.is_empty() => out.push_str("[]"),
Json::List(items) => {
out.push_str("[\n");
for (n, item) in items.iter().enumerate() {
pad(out, depth + 1);
item.write(out, depth + 1);
out.push_str(if n + 1 < items.len() { ",\n" } else { "\n" });
}
pad(out, depth);
out.push(']');
}
Json::Object(fields) => {
out.push_str("{\n");
for (n, (key, value)) in fields.iter().enumerate() {
pad(out, depth + 1);
let _ = write!(out, "\"{key}\": ");
value.write(out, depth + 1);
out.push_str(if n + 1 < fields.len() { ",\n" } else { "\n" });
}
pad(out, depth);
out.push('}');
}
}
}
}
fn report_file(file: &str) -> String {
let path = Path::new(file);
if file.starts_with('<') || path.is_absolute() {
return file.to_owned();
}
let file = file.strip_prefix("./").unwrap_or(file);
match std::env::current_dir() {
Ok(dir) => dir.join(file).to_string_lossy().into_owned(),
Err(_) => file.to_owned(),
}
}
fn place_json(file: &str, line: u32) -> Json {
Json::Object(vec![
("file", Json::Text(report_file(file))),
("line", Json::Number(line as usize)),
])
}
fn place_text_json(place: &str) -> Json {
match place.rsplit_once(':') {
Some((file, line)) if !file.is_empty() => match line.trim().parse::<u32>() {
Ok(line) => place_json(file, line),
Err(_) => Json::Null,
},
_ => Json::Null,
}
}
fn doc_place_json(place: Option<&hexicon_compiler::DocPlace>) -> Json {
place.map_or(Json::Null, |p| place_json(&p.file, p.line))
}
fn json_report(reported: &Reported<'_>) -> String {
let (status, built, played, problem, messages) = match reported {
Reported::NotBuilt(messages) => (2, false, false, None, *messages),
Reported::NotPlayed { messages, problem } => (2, true, false, Some(problem), *messages),
Reported::Played {
messages, status, ..
} => (*status, true, true, None, *messages),
};
let messages = messages
.iter()
.map(|m| {
Json::Object(vec![
("severity", Json::text(m.severity)),
(
"file",
if m.file.is_empty() {
Json::Null
} else {
Json::Text(report_file(&m.file))
},
),
(
"line",
if m.line == 0 {
Json::Null
} else {
Json::Number(m.line as usize)
},
),
("message", Json::text(&m.message)),
])
})
.collect();
let mut fields = vec![
("version", Json::Number(1)),
("status", Json::Number(usize::from(status))),
("built", Json::Bool(built)),
("played", Json::Bool(played)),
("problem", problem.map_or(Json::Null, |p| Json::text(p))),
("buildMessages", Json::List(messages)),
];
let (results, places) = match reported {
Reported::Played {
results, places, ..
} => (Some(*results), Some(*places)),
_ => (None, None),
};
let count = |n: Option<usize>| Json::Number(n.unwrap_or(0));
fields.push(("passed", count(results.map(|r| r.passed))));
fields.push(("failed", count(results.map(|r| r.failed))));
fields.push(("notRun", count(results.map(|r| r.not_run))));
let empty = TestPlaces::default();
let places = places.unwrap_or(&empty);
let outcomes = results.map_or(&[][..], |r| &r.outcomes[..]);
let outcomes = outcomes
.iter()
.map(|o| {
let scenario_of = |name: &str| places.scenarios.iter().find(|(n, ..)| n == name);
let place = scenario_of(&o.name).map(|(_, place, _)| place);
let failure = o.failure.as_ref().map_or(Json::Null, |f| {
let step = if f.scenario.is_empty() {
Json::count_or_null(&f.step)
} else {
match (o.steps.parse::<usize>(), f.step_in.parse::<usize>()) {
(Ok(before), Ok(n)) => Json::Number(before + n),
_ => Json::Null,
}
};
let (scenario, n) = if f.scenario.is_empty() {
(o.name.as_str(), f.step.parse::<usize>().ok())
} else {
(f.scenario.as_str(), f.step_in.parse::<usize>().ok())
};
let step_place = n
.filter(|n| *n > 0)
.and_then(|n| scenario_of(scenario)?.2.get(n - 1));
Json::Object(vec![
("step", step),
("scenario", Json::text_or_null(&f.scenario)),
("stepInScenario", Json::count_or_null(&f.step_in)),
("command", Json::text(&f.command)),
("why", Json::text(&f.why)),
("kind", Json::text_or_null(&f.kind)),
("description", Json::text(&f.what)),
("place", place_text_json(&f.place)),
("stepPlace", doc_place_json(step_place)),
("gameSaid", Json::text(&f.said)),
])
});
Json::Object(vec![
("name", Json::text(&o.name)),
("walkthrough", Json::Bool(o.walkthrough)),
("outcome", Json::text(&o.outcome)),
("steps", Json::Number(o.steps.parse().unwrap_or(0))),
("after", Json::text_or_null(&o.after)),
("place", doc_place_json(place)),
(
"notes",
Json::List(o.notes.iter().map(|n| Json::text(n)).collect()),
),
("failure", failure),
])
})
.collect();
fields.push(("results", Json::List(outcomes)));
let covered = results.map_or(&[][..], |r| &r.covered[..]);
let choices = covered
.iter()
.filter(|c| matches!(c, Covered::Choice { .. }))
.count();
let unplayed = covered
.iter()
.filter(|c| c.unplayed().is_some())
.map(|c| match c {
Covered::Moment {
name,
state,
symbol,
} => Json::Object(vec![
("moment", Json::text(name)),
("label", Json::Null),
("state", Json::text(state)),
("place", doc_place_json(places.objects.get(symbol))),
]),
Covered::Choice {
moment,
label,
state,
symbol,
} => {
let place = places
.choices
.iter()
.find(|(owner, l, _)| owner == symbol && l == label)
.map(|(_, _, place)| place)
.or_else(|| places.objects.get(symbol));
Json::Object(vec![
("moment", Json::text(moment)),
("label", Json::text(label)),
("state", Json::text(state)),
("place", doc_place_json(place)),
])
}
})
.collect();
let problems = places
.problems
.iter()
.map(|(message, place)| {
Json::Object(vec![
("message", Json::text(message)),
("place", doc_place_json(place.as_ref())),
])
})
.collect();
fields.push((
"choices",
Json::Object(vec![
("count", Json::Number(choices)),
("unplayed", Json::List(unplayed)),
("problems", Json::List(problems)),
]),
));
let mut out = String::new();
Json::Object(fields).write(&mut out, 0);
out.push('\n');
out
}
#[cfg(test)]
mod tests {
use super::{parse, text_report};
fn report(lines: &str, kept: bool) -> Option<(String, std::process::ExitCode)> {
parse(lines).map(|results| text_report(&results, kept))
}
#[test]
fn what_the_scenarios_did_not_play_of_the_choices_is_said() {
let lines = "scenario\tsaving it\tpassed\t2\t\n\
choice-moment\tsnap\tbegun\n\
choice\tsnap\tGrab it\tchosen\n\
choice\tsnap\tShout\tlisted\n\
choice-moment\toffer\tnever begun\n\
choice\toffer\tBuy\tnever listed\n\
done\t1\t0\t0\n";
let (text, _) = report(lines, false).expect("a report");
assert!(text.contains("What the scenarios did not play of the choices:"));
assert!(text.contains("snap: \"Shout\", listed, never chosen"));
assert!(text.contains("offer: never begun"));
assert!(text.contains("offer: \"Buy\", never listed"));
assert!(!text.contains("Grab it"));
let all = "scenario\tsaving it\tpassed\t2\t\n\
choice-moment\tsnap\tbegun\n\
choice\tsnap\tGrab it\tchosen\n\
done\t1\t0\t0\n";
let (text, _) = report(all, false).expect("a report");
assert!(text.contains("Every choice was chosen in a scenario."));
let none = "scenario\tsaving it\tpassed\t2\t\ndone\t1\t0\t0\n";
let (text, _) = report(none, false).expect("a report");
assert!(!text.contains("choice"));
}
const FAILED: &str = "scenario\tgetting in\tpassed\t2\t\n\
walkthrough\tthe way\tfailed\t2\t\n\
note\tthe way\tringing has given conditions\n\
failure\tthe way\t1 of \u{201c}ringing\u{201d}\tpull rope\tIt rings.\t\
expect is not true\ttests.hxn:41\tNothing.\texpect\tringing\t1\n\
scenario\tnothing\tfailed\t0\t\n\
failure\tnothing\t0\t\t\tthere is no scenario or walkthrough of that name\t\t\tmissing\t\t\n\
choice-moment\tsnap\tbegun\tsnap\n\
choice\tsnap\tShout \"hey\"\tlisted\tsnap\n\
done\t1\t2\t0\n";
#[test]
fn the_text_report_is_as_it_was_with_the_new_fields() {
let (text, status) = report(FAILED, true).expect("a report");
assert_eq!(status, std::process::ExitCode::FAILURE);
assert!(text.contains(
"FAILED walkthrough: the way\n \
at step 1 of \u{201c}ringing\u{201d}: pull rope\n why: It rings.\n \
failed: expect is not true, at tests.hxn:41\n the game said: Nothing.\n \
note: ringing has given conditions\n"
));
assert!(text.contains(
"FAILED nothing\n failed: there is no scenario or walkthrough of that name\n"
));
let old = "scenario\tx\tfailed\t1\t\n\
failure\tx\t1\tlook\t\tit does not mention \u{201c}y\u{201d}\t\tDark.\n\
done\t0\t1\t0\n";
let (text, _) = report(old, true).expect("a report");
assert!(text.contains("at step 1: look\n failed: it does not mention"));
}
#[test]
fn the_json_report_says_where_and_what_failed() {
use super::{Reported, json_report};
use crate::doc::TestPlaces;
use hexicon_compiler::DocPlace;
let at = |line| DocPlace {
file: "<hexicon>/tests.hxn".to_owned(),
line,
};
let places = TestPlaces {
scenarios: vec![
("ringing".to_owned(), at(30), vec![at(31), at(35)]),
("the way".to_owned(), at(50), Vec::new()),
],
objects: [("snap".to_owned(), at(70))].into_iter().collect(),
choices: vec![("snap".to_owned(), "Shout \"hey\"".to_owned(), at(72))],
problems: vec![("snap: it has no way out".to_owned(), Some(at(70)))],
};
let results = parse(FAILED).expect("results");
let json = json_report(&Reported::Played {
messages: &[],
results: &results,
places: &places,
status: 1,
});
for wanted in [
"\"version\": 1,\n",
"\"status\": 1,\n",
"\"passed\": 1,\n \"failed\": 2,\n \"notRun\": 0,\n",
"\"step\": 3,\n \"scenario\": \"ringing\",\n \"stepInScenario\": 1,\n",
"\"kind\": \"expect\",\n \"description\": \"expect is not true\",\n \
\"place\": {\n \"file\": ",
"\"stepPlace\": {\n \"file\": \"<hexicon>/tests.hxn\",\n \"line\": 31\n",
"\"place\": {\n \"file\": \"<hexicon>/tests.hxn\",\n \"line\": 50\n",
"\"notes\": [\n \"ringing has given conditions\"\n ],\n",
"\"step\": null,",
"\"kind\": \"missing\",",
"\"count\": 1,\n",
"\"label\": \"Shout \\\"hey\\\"\",\n \"state\": \"listed\",\n \"place\": {\n \
\"file\": \"<hexicon>/tests.hxn\",\n \"line\": 72\n",
"\"message\": \"snap: it has no way out\",",
] {
assert!(json.contains(wanted), "no {wanted:?} in:\n{json}");
}
let messages = [crate::build::BuildMessage {
severity: "error",
file: "<hexicon>/start.hxn".to_owned(),
line: 3,
message: "a\tb".to_owned(),
}];
let json = json_report(&Reported::NotBuilt(&messages));
assert!(json.contains("\"status\": 2,\n \"built\": false,\n \"played\": false,\n"));
assert!(
json.contains("\"line\": 3,\n \"message\": \"a\\tb\"\n"),
"{json}"
);
}
}