aboutsummaryrefslogtreecommitdiff
path: root/tests/test_macro_processor.sh
blob: daee5d2678c0c3855b951c7ec9c9113bc6b57023 (plain) (blame)
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
#!/bin/bash

ALL_OUTPUT=0

test () {
    file_content=$(<tests/smp/$1)
    readarray -t sections < <(awk -v RS="---" '{print}' <<< "$file_content")
    var1=$(echo "$file_content" | awk -v RS="\n---\n" 'NR==1')
    var2=$(echo "$file_content" | awk -v RS="\n---\n" 'NR==2')

    if [ "$ALL_OUTPUT" -eq 0 ]; then
        res=$(echo -n "$var1" | smp 2> /dev/null)
    else
        res=$(echo -n "$var1" | smp)
    fi
    if [ ! "$res" = "$var2" ]; then
        tput setaf 1
        echo "$1 NOT OK:"
        tput setaf 3
        echo "- Expected --"
        echo "$var2"
        tput setaf 1
        echo "- Result ----"
        echo "$res"
        echo "-------------"
        tput sgr0
        exit 1
    else
        tput setaf 2
        echo "$1 OK"
        tput sgr0
    fi
}

if [ "$#" -eq 1 ]; then
    ALL_OUTPUT=1
    test $1
else
    for file in tests/smp/*; do
        test "$(basename $file)"
    done
fi