aboutsummaryrefslogtreecommitdiff
path: root/tests/common.sh
blob: 7c8b5ae6d7fa5c7b12154f352d51f068fcf00694 (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
44
45
46
47
#!/bin/bash

function assemble() {
    # Note: macOS only for now, abstract this out later
    nasm -f macho64 -o output.o output.nasm
    ld -lSystem output.o
}

function assert_exit_status() {
    ./cupcc -c "$1"
    assemble

    set +e
    ./a.out
    res=$?
    if [ $res -ne $2 ]
    then
        echo ""
        echo "----------------------------------" 
        echo "Test failed: expected $2, got $res"
        echo "- Input was:"
        echo "     \`$1\`"
        exit 1
    fi
    set -e
    echo -n "."
}

function assert_exit_status_stdin() {
    ./cupcc -
    assemble

    set +e
    ./a.out
    res=$?
    if [ $res -ne $1 ]
    then
        echo ""
        echo "----------------------------------" 
        echo "Test failed: expected $2, got $res"
        echo "- Input was:"
        echo "     \`$1\`"
        exit 1
    fi
    set -e
    echo -n "."
}