aboutsummaryrefslogtreecommitdiff
path: root/tests/command/testscript
blob: 12ddd7942630105a62ca0f1caf5b4d90b5aa3a1c (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# file      : tests/command/testscript
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

cmd="'$0' -C -A" # Command that prints its arguments to stdout.

# Note that when cross-testing the driver may not be able to run the command
# due to the meaningless program path.
#
+if ($test.target != $build.host)
  exit
end

: quioting
:
{
  $* "$cmd 'abc def'" >~'%.+ "abc def"%'
}

: substitution
:
{
  test.options += -s v1=abc -s v2=def

  : program
  :
  {
    $* -s "program=$0" '@program@ -C -A abc' >~'%.+driver.* abc%'
  }

  : args
  :
  {
    $* "$cmd abc"         >~'%.+ abc%'       : none
    $* "$cmd x@v1@"       >~'%.+ xabc%'      : single
    $* "$cmd x@v1@y@v2@z" >~'%.+ xabcydefz%' : multiple
    $* "$cmd @v1@@v2@"    >~'%.+ abcdef%'    : adjacent
  }

  : redirect
  :
  {
    $* -s v=f "$cmd abc >@v@" &f;
    cat f >~'%.+ abc%'
  }
}

: redirect
:
{
  : overwrite
  :
  {
    $* -p "$cmd abc >f" >~'%.+driver.* -C -A abc >f%' &f;
    cat f >~'%.+ abc%'
  }

  : append
  :
  {
    echo 'xyz' >=f;
    $* -p "$cmd abc >>f" >~'%.+driver.* -C -A abc >>f%';

    cat f >>~%EOO%
      xyz
      %.+ abc%
      EOO
  }

  : space-separated
  :
  {
    : overwrite
    :
    {
      $* "$cmd abc > f" &f;
      cat f >~'%.+ abc%'
    }

    : append
    :
    {
      echo 'xyz' >=f;
      $* "$cmd abc >> f";

      cat f >>~%EOO%
        xyz
        %.+ abc%
        EOO
    }
  }

  : not-redirect
  :
  $* -s v='>f' "$cmd abc @v@" >~'%.+ abc >f%'

  : errors
  :
  {
    $* "$cmd >d/f" 2>~"%unable to open stdout redirect file 'd/f'.*%" != 0 : io-failure
    $* "$cmd > ''" 2>  'empty stdout redirect file path'              != 0 : empty-path
  }
}

: invalid-argument
:
{
  $* ""           2>'no program path specified'         != 0 : no-prog
  $* "p 'abc def" 2>'unterminated quoted string'        != 0 : unterminated
  $* "p >"        2>'no stdout redirect file specified' != 0 : no-redirect-file
  $* "p >>"       2>'no stdout redirect file specified' != 0 : no-append-file

  : substitution
  :
  {
    test.options += -s v=a

    $* 'p @a b@'   2>"unmatched substitution character '@' in '@a'" != 0 : unterm-var
    $* "p '@a b@'" 2>"whitespace in variable name 'a b'"            != 0 : ws-var
    $* 'p @x@'     2>"unknown variable 'x'"                         != 0 : unknown-var
  }
}

: process
:
{
  : cwd
  :
  {
    mkdir abc;
    $* -d abc "$cmd -D" >>/~%EOO%
      %.+/driver.*%
      %.+/abc%
      EOO
  }

  : env-var
  :
  {
    $* -v test=abc "$cmd -V test" >>/~%EOO%
      %.+/driver.*%
      abc
      EOO
  }

  : error
  :
  {
    $* "''" 2>'no such file or directory' != 0 : empty-prog
  }

  : non-zero-status
  :
  $* "'$0' -C -S 10" 2>/~'%.+ exited with code 10%' == 10
}

: builtin
:
{
  : no-cwd
  :
  {
    $* 'touch a' &a;
    test -f a
  }

  : cwd
  :
  {
    mkdir a;
    $* -d a 'touch b' &a/b;
    test -f a/b
  }

  : redirect
  :
  {
    $* 'echo abc >a' &a;
    cat a >'abc'
  }

  : callback
  :
  {
    $* -p 'echo abc >a' >'echo abc >a' &a
  }

  : escape
  :
  : Note that the sed builtin doesn't support multiple scripts.
  :
  if ($cxx.target.class != 'windows')
  {
    echo 'abc' >=f;
    $* '^sed -e s/a/b/ -e s/c/b/ f' >'bbb'
  }
}