|
root / tests / integration / ui_tests.sh
ui_tests.sh Bash 77 lines 2.5 KB
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
# Snapshot tests for the ui.reef renderer.
# Each scenario invokes `zyginit --ui-demo <name>` and diffs against a golden file.
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
ZYGINIT="$PROJECT_DIR/build/zyginit"
SNAP_DIR="$SCRIPT_DIR/snapshots"

mkdir -p "$SNAP_DIR"
PASS=0
FAIL=0

check_scenario() {
    name=$1
    env_prefix=$2
    expected="$SNAP_DIR/$name.txt"
    got=$(mktemp)
    eval "$env_prefix $ZYGINIT --ui-demo $name" > "$got" 2>&1 || true
    if [ ! -f "$expected" ]; then
        cp "$got" "$expected"
        echo "  [created]  $name"
        PASS=$((PASS+1))
        rm -f "$got"
        return
    fi
    if diff -u "$expected" "$got" > /dev/null; then
        echo "  [pass]     $name"
        PASS=$((PASS+1))
    else
        echo "  [FAIL]     $name"
        diff -u "$expected" "$got" || true
        FAIL=$((FAIL+1))
    fi
    rm -f "$got"
}

echo "ui snapshot tests"
# ZYGINIT_FORCE_80x25=1 locks the TIOCGWINSZ path to 80x25 regardless
# of the host terminal size, keeping snapshot output deterministic.
F80="ZYGINIT_FORCE_80x25=1"
check_scenario skeleton "ZYGINIT_NO_UI=1 $F80"
check_scenario plain_boot "ZYGINIT_NO_UI=1 $F80"
check_scenario detect_no_color "NO_COLOR=1 TERM=xterm-256color $F80"
check_scenario detect_dumb "TERM=dumb $F80"
check_scenario detect_sun "TERM=sun $F80"
check_scenario detect_sun_color "TERM=sun-color $F80"

check_scenario palette_true "TERM=xterm-256color $F80"
check_scenario palette_16   "TERM=sun $F80"
check_scenario glyphs_unicode "TERM=xterm-256color $F80"
check_scenario glyphs_ascii   "TERM=xterm-256color ZYGINIT_ASCII=1 $F80"
check_scenario sigil_rich   "TERM=sun-color $F80"

check_scenario boot_tape_rich  "TERM=xterm-256color $F80"
check_scenario boot_tape_ascii "TERM=xterm ZYGINIT_ASCII=1 $F80"
check_scenario boot_tape_plain "ZYGINIT_NO_UI=1 $F80"

check_scenario progress_rich  "TERM=xterm-256color $F80"
check_scenario progress_ascii "TERM=xterm ZYGINIT_ASCII=1 $F80"
check_scenario progress_full  "TERM=xterm-256color $F80"

check_scenario spinner_forward  "TERM=xterm-256color $F80"
check_scenario spinner_reverse  "TERM=xterm-256color $F80"
check_scenario spinner_in_tape  "TERM=xterm-256color $F80"

check_scenario final_card_ok      "TERM=xterm-256color $F80"
check_scenario final_card_failed  "TERM=xterm-256color $F80"

check_scenario shutdown_mirror   "TERM=xterm-256color $F80"
check_scenario shutdown_final    "TERM=xterm-256color $F80"

echo
echo "passed: $PASS  failed: $FAIL"
[ "$FAIL" -eq 0 ]