aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/interactive.fish
blob: 369b8546dabc0203c8e6866ec33263df66755252 (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
#!/usr/local/bin/fish
#
# Interactive tests using `expect`

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

for i in *.expect
    rm -Rf tmp.interactive.config; or die "Couldn't remove tmp.interactive.config"
    mkdir -p tmp.interactive.config/fish; or die "Couldn't create tmp.interactive.config/fish"
    cp interactive.config tmp.interactive.config/fish/config.fish; or die "Couldn't create tmp.interactive.config/fish/config.fish"

    begin
        set -lx XDG_CONFIG_HOME $PWD/tmp.interactive.config
        set -lx TERM dumb
        expect -n -c 'source interactive.expect.rc' -f $i >$i.tmp.out ^$i.tmp.err
    end
    set -l tmp_status $status
    set res ok
    mv -f interactive.tmp.log $i.tmp.log
    if not diff $i.tmp.out $i.out >/dev/null
        set res fail
        echo "Output differs for file $i. Diff follows:"
        diff -u $i.tmp.out $i.out
    end

    if not diff $i.tmp.err $i.err >/dev/null
        set res fail
        echo "Error output differs for file $i. Diff follows:"
        diff -u $i.tmp.err $i.err
    end

    if test $tmp_status != (cat $i.status)
        set res fail
        echo "Exit status differs for file $i."
    end

    if test $res = ok
        echo "File $i tested ok"
        # clean up tmp files
        rm -f $i.tmp.{err,out,log}
    else
        echo "File $i failed tests"
    end
end