1
//! The snapshot's text form: one `==` block per (fixture, mode, hosts, world)
2
//! holding the whole [`Behaviour`], preceded by the compilation's measured
3
//! counters, so a reviewer reads a transition as a diff of plain lines.
4

            
5
use super::super::CompileMode;
6
use super::super::behaviour_oracle::{Behaviour, Logged};
7
use super::super::stats::CompileStats;
8

            
9
pub(super) struct Row {
10
    pub(super) id: String,
11
    pub(super) mode: CompileMode,
12
    pub(super) hosts: &'static str,
13
    pub(super) behaviours: Vec<Behaviour>,
14
    pub(super) stats: CompileStats,
15
}
16

            
17
1189
fn logged(message: &Logged) -> String {
18
1189
    match message {
19
1189
        Logged::Text(text) => format!("{text:?}"),
20
        Logged::InvalidUtf8(bytes) => format!("invalid utf-8 {bytes:?}"),
21
        Logged::Unreadable => "unreadable".to_string(),
22
    }
23
1189
}
24

            
25
11050
fn render_behaviour(out: &mut String, row: &Row, behaviour: &Behaviour) {
26
11050
    out.push_str(&format!(
27
11050
        "== {} | {:?} | hosts={} | {}\n",
28
11050
        row.id, row.mode, row.hosts, behaviour.world
29
11050
    ));
30
11050
    out.push_str(&format!("outcome: {:?}\n", behaviour.outcome));
31
11050
    out.push_str(&format!("applies: {:?}\n", behaviour.applies));
32
11050
    for (severity, message) in &behaviour.output {
33
1189
        out.push_str(&format!("log: {severity} {}\n", logged(message)));
34
    }
35
11050
    for effect in &behaviour.effects {
36
7429
        out.push_str(&format!("effect: {effect}\n"));
37
    }
38
11050
}
39

            
40
3
pub(super) fn render_rows(rows: &[Row]) -> String {
41
3
    let mut out = String::new();
42
3
    for row in rows {
43
5525
        out.push_str(&format!(
44
5525
            "== {} | {:?} | hosts={} | stats\nfolds: {}\nmacro_bodies_reading_globals: {}\n\
45
5525
             stored_globals: {}\npossibly_storing: {}\nopaque_macro_uses: {}\n",
46
5525
            row.id,
47
5525
            row.mode,
48
5525
            row.hosts,
49
5525
            row.stats.folds,
50
5525
            row.stats.macro_bodies_reading_globals,
51
5525
            row.stats.stored_globals,
52
5525
            row.stats.possibly_storing,
53
5525
            row.stats.opaque_macro_uses
54
5525
        ));
55
5525
        for behaviour in &row.behaviours {
56
11050
            render_behaviour(&mut out, row, behaviour);
57
        }
58
    }
59
3
    out
60
3
}