summaryrefslogtreecommitdiff
path: root/Shell/Tests/if.sh
blob: 598a9471bc03d78429a4c7b856a36b1bea601ee0 (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
#!/bin/sh

setopt --verbose

if test 1 -eq 1 {
    # Are comments ok?
    # Basic 'if' structure, empty block.
    if true {
    } else {
        echo "if true runs false branch"
        exit 2
    }
    if false {
        echo "if false runs true branch"
        exit 2
    } else {
    }

    # Basic 'if' structure, without 'else'
    if false {
        echo "Fail: 'if false' runs the branch"
        exit 2
    }

    # Extended 'cond' form.
    if false {
        echo "Fail: 'if false' with 'else if' runs first branch"
        exit 2
    } else if true {
    } else {
        echo "Fail: 'if false' with 'else if' runs last branch"
        exit 2
    }

    # FIXME: Some form of 'not' would be nice
    # &&/|| in condition
    if true || false {
    } else {
        echo "Fail: 'if true || false' runs false branch"
        exit 2
    }

    if true && false {
        echo "Fail: 'if true && false' runs true branch"
        exit 2
    }
} else {
    echo "Fail: 'if test 1 -eq 1' runs false branch"
    exit 1
}