Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
52696436a3c348d7b92c95c3b5eafecaf4472c5c
[simgrid.git] / tools / tesh2 / examples / var.tesh
1 #! ./tesh
2 # This file describes the usage of the Tesh variables and contains all the tests connected.
3
4 # Description of this tesh suite
5 D Usage of tesh variables
6
7 # Declare and define the variable include-file
8 ! include-file=catch-signal.tesh
9
10 # include the tesh file specified by the value (catch-signal.tesh) of the variable include-file
11 ! include $include-file
12
13 # set a new value to the variable include-file
14 ! include-file=basic.tesh
15
16 # this line throws a warning (you assign the same value to the variable)
17 ! include-file=basic.tesh
18
19 # include the tesh file specified by the value (basic.tesh) of the variable include-file
20 ! include $include-file
21
22 # Undefined variable
23 ! expect return $ESYNTAX
24 < ! include-file=
25 < ! include $include-file
26 $ ./tesh --log="log.thresh:info tesh.fmt:%m%n"
27 > Test unit from stdin
28 > [stdin:1] Undefined variable `(include-file)'
29 > Test unit `stdin': NOK (<stdin:1> syntax error)
30
31
32 # A single sample of the usage of the tesh variables
33 $ rm -rf temp_testdir
34 $ mkdir temp_testdir
35
36 $ cd temp_testdir
37
38 < #include <stdlib.h>
39 < #include <stdio.h>
40 < int main(int argc, char* argv[]) {    
41 <       return ( atoi(argv[1]) + atoi(argv[2]));
42 <       }  
43 $ cat > sum.c
44
45 $ gcc -o sum sum.c
46
47 ! x=2
48 ! y=2
49 ! sum=./sum
50 ! rv=4
51
52 ! expect return $rv
53 $ $sum $x $y
54
55 $ cd ..
56 $ rm -rf temp_testdir
57
58 # set metacommand usage
59
60 # This ligne add a new tesh variable DIR
61
62 ! set DIR=temp_testdir
63
64 $ rm -rf $DIR
65
66 $ mkdir $DIR
67
68 $ cd $DIR
69
70 $ cd ..
71
72 $ rm -rf $DIR
73
74 # This ligne change the value of the tesh variable DIR
75 ! set DIR=test_tempdir
76
77 # This ligne # this line throws a warning (you assign the same value to the variable)
78 ! set DIR=test_tempdir
79
80
81 # This ligne create a new variable CURRENT_DIR (setted with the content of the variable DIR)
82 ! CURRENT_DIR=$DIR
83 p CURRENT_DIR is $CURRENT_DIR (same value as DIR)
84
85 # This ligne use the metacommand `set' to update the content of the variable CURRENT_DIR
86 ! set CURRENT_DIR=temp_testdir
87 p Now CURRENT_DIR is $CURRENT_DIR
88
89 # This ligne unset the variable CURRENT_DIR (delete the tesh variable)
90 ! unset CURRENT_DIR
91 p $CURRENT_DIR does not exist
92
93 # This ligne displays the content of the environment variable TESH_PPID (which contains the PID of the tesh parent) 
94 p The Tesh parent PID is: $TESH_PPID
95
96 # This ligne displays the content of the value of the system variable ENOENT
97 p On this platform ENOENT is: $ENOENT
98
99 # Attempt to change the content of a system variable is a syntax error
100 ! expect return $ESYNTAX
101 < ! ENOENT=300
102 < $ echo $ENOENT
103 $ ./tesh --log="log.thresh:info tesh.fmt:%m%n"
104 > Test unit from stdin
105 > [stdin:1] A system variable named `(ENOENT)' already exists
106 > Test unit `stdin': NOK (<stdin:1> syntax error)
107
108 # Substitution usage
109
110 ! new=1
111
112 p new is `$new ' or `${new}'
113
114 p the len of new is : ${#new}
115
116 ! unset new
117
118 p new is empty <$new> and is len is <${#new}>
119
120 # display 66 and assign 66 to the value 66 of the variable new
121
122 p ${new:=66}
123
124 p new is `$new ' or `${new}'
125
126 p the len of new is : ${#new}
127
128 # display 66 and do not assign the value 69 to the variable
129
130 p ${new:=69}
131
132 p new is `$new ' or `${new}'
133
134 p the len of new is : ${#new}
135
136 ! unset new
137
138 # display 79 and do not assigne the value 79 to the variable
139 # new is empty
140 p ${new:-79}
141
142 p new is `$new ' or `${new}'
143
144 p the len of new is : ${#new}
145
146 # display nothing and do not assigne the value 89 to the variable
147 # new is empty
148 p is empty ${new:+89}
149
150 p new is `$new ' or `${new}'
151
152 p the len of new is : ${#new}
153
154 ! set new=999
155
156 # display 99 and do not assigne the value 99 to the variable (do not dispaly the value of new)
157 # new is empty
158 p is empty ${new:+99}
159
160 p new is `$new ' or `${new}'
161
162 p the len of new is : ${#new}
163
164 ! unset new
165
166 # p ${new:?new is empty}