~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to ftsh/test/expr.ftsh

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
a=10
 
3
b=21
 
4
c=171
 
5
 
 
6
#
 
7
# string comparison
 
8
#
 
9
 
 
10
if foo .eq. foo
 
11
        echo "ok"
 
12
else
 
13
        failure
 
14
end
 
15
 
 
16
if foo .ne. baz
 
17
        echo "ok"
 
18
else
 
19
        failure
 
20
end
 
21
 
 
22
#
 
23
# integer comparison
 
24
#
 
25
 
 
26
if $a .eql. 10
 
27
        echo "ok"
 
28
else
 
29
        failure
 
30
end
 
31
 
 
32
try
 
33
        if $a .eql. crap
 
34
                echo "shouldn't return true"
 
35
        else
 
36
                echo "shouldn't return false"
 
37
        end
 
38
catch
 
39
        echo "not a number"
 
40
end
 
41
 
 
42
#
 
43
#
 
44
# add sub mul div to eq
 
45
#
 
46
 
 
47
for x in (0 .sub. $a) .to. $a
 
48
        y=$x .mul. $b .add. $c
 
49
        z=( $y .sub. $c ) .div. $b
 
50
        if $x .eq. $z
 
51
                echo $x $y $z ok
 
52
        else
 
53
                failure
 
54
        end
 
55
end
 
56
 
 
57
#
 
58
# mod lt eq to
 
59
#
 
60
 
 
61
for x in 1 .to. 19
 
62
        y=$x .mod. 10
 
63
        if $x .lt. 10
 
64
                if $y .eq. $x
 
65
                        echo $x $y ok
 
66
                else
 
67
                        failure
 
68
                end
 
69
        else
 
70
                if $y .eq. ( $x .sub. 10 )
 
71
                        echo $x $y ok
 
72
                else
 
73
                        failure
 
74
                end
 
75
        end
 
76
end
 
77
 
 
78
# gt lt and not
 
79
 
 
80
for x in -10 .to. 10
 
81
        y=$x .add. 1
 
82
        z=$x .sub. 1
 
83
        if ( $y .gt. $x ) .and. ( $z .lt. $x )
 
84
                echo $x $y $z ok
 
85
        else
 
86
                failure
 
87
        end
 
88
        if .not. (( $y .gt. $x ) .and. ( $z .lt. $x ))
 
89
                failure
 
90
        else
 
91
                echo not $x $y $x ok
 
92
        end
 
93
end
 
94
 
 
95
for a in true false
 
96
        for b in true false
 
97
                x=($a .and. $b)
 
98
                y=($a .or. $b)
 
99
                z=(.not. $a)
 
100
                w=(.not. $b)
 
101
 
 
102
                echo "$a and $b = $x"
 
103
                echo "$a or $b = $y"
 
104
                echo "not $a = $z"
 
105
                echo "not $b = $w"
 
106
        end
 
107
end
 
108
 
 
109
function testall
 
110
        if .exists. $1
 
111
                echo "$1 exists"
 
112
        end
 
113
        if .isr. $1
 
114
                echo "$1 readable"
 
115
        end
 
116
        if .isw. $1
 
117
                echo "$1 writeable"
 
118
        end
 
119
        if .isx. $1
 
120
                echo "$1 executable"
 
121
        end
 
122
 
 
123
        if .islink. $1
 
124
                echo "$1 is a link"
 
125
        else if .isdir. $1
 
126
                echo "$1 is a dir"
 
127
        else if .issock. $1
 
128
                echo "$1 is a socket"
 
129
        else if .ispipe. $1
 
130
                echo "$1 is a pipe"
 
131
        else if .isfile. $1
 
132
                echo "$1 is a file"
 
133
        else if .isblock. $1
 
134
                echo "$1 is a block device"
 
135
        else if .ischar. $1
 
136
                echo "$1 is a char device"
 
137
        else
 
138
                echo "$1 is unknown type"
 
139
        end
 
140
end
 
141
 
 
142
rm -rf a
 
143
testall a
 
144
touch a
 
145
 
 
146
chmod 000 a
 
147
testall a
 
148
 
 
149
chmod 400 a
 
150
testall a
 
151
 
 
152
chmod 200 a
 
153
testall a
 
154
 
 
155
chmod 100 a
 
156
testall a
 
157
 
 
158
rm -rf g
 
159
mkdir g
 
160
chmod 700 g
 
161
testall g
 
162
 
 
163
rm -rf h
 
164
touch h
 
165
chmod 700 h
 
166
testall h
 
167
 
 
168
rm -rf i
 
169
ln -s h i
 
170
testall i
 
171
 
 
172
#
 
173
# Skip fifos because they can't be tested everywhere.
 
174
#
 
175
 
 
176
#rm -rf /tmp/k
 
177
#mkfifo /tmp/k
 
178
#testall /tmp/k