aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test_util.fish
blob: b81e17f69919f77a1935037465a98a130ae6adf0 (plain)
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
# Utilities for the test runners

function die
    echo $argv[1] >&2
    exit 1
end

if not tty 0>&1 >/dev/null
    function set_color
        # do nothing
        return 0
    end
end

function say
    set -l color_flags
    while set -q argv[1]
        switch $argv[1]
            case -b -o -u
                set color_flags $color_flags $argv[1]
            case --
                set -e argv[1]
                break
            case -\*
            case \*
                break
        end
        set -e argv[1]
    end

    if not set -q argv[1]
        echo 'usage: say [flags] color [string...]' >&2
        return 1
    end

    if set_color $color_flags $argv[1]
        set -e argv[1]
        echo $argv
        set -l stat $status
        set_color reset
        or return $stat
    end
end

function colordiff -d 'Colored diff output for unified diffs'
    diff $argv | while read -l line
        switch $line
            case '+*'
                say green $line
            case '-*'
                say red $line
            case '@*'
                say cyan $line
            case '*'
                echo $line
        end
    end
end