aboutsummaryrefslogtreecommitdiff
path: root/tests/test/script/runner/regex.testscript
blob: ee4b25e4127c894c405969cd47561c9d060d66cb (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# file      : tests/test/script/runner/regex.testscript
# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

# Here we test that regex objects are properly created by the parser/runner
# venture. The unit test approach is not of much use as regex object is not
# serializable back to string. The only way we can test their proper creation
# is via matching.
#
# Note that such a tests are separated from ones that check regex matching
# specifically (in particular matching failures), The latest ones are located
# in redirect.testscript.
#
# Also note that the following tests are grouped by features: basic
# functionality, flags, portable-path modifier.
#

.include ../common.testscript

: basic
:
{
  : str
  :
  {
    $c <'cat <foo >~/fo./' && $b       : out
    $c <'cat <foo 1>&2 2>~/fo./' && $b : err
    $c <'cat <:foo >:~/fo./' && $b     : no-newline

    : malformed
    :
    : Note that old versions of libc++ (for example 1.1) do not detect some
    : regex errors. For example '*' is parsed successfully.
    :
    $c <'cat <foo >~/foo[/' && $b 2>>~/EOE/ != 0
    /testscript:1:12: error: invalid stdout regex redirect.*/
      info: regex: '/foo[/'
      info: test id: 1
    EOE

    : no-match
    :
    $c <'cat <foo >~/bar/' && $b 2>>/EOE != 0
    testscript:1:1: error: cat stdout doesn't match regex
      info: stdout: test/1/stdout
      info: stdout regex: test/1/stdout.regex
      info: stdin: test/1/stdin
    foo
      info: test id: 1
    EOE
  }

  : doc
  :
  {
    : out
    :
    $c <<EOI && $b
    cat <foo >>~/EOO/
    /foo/
    EOO
    EOI

    : err
    :
    $c <<EOI && $b
    cat <foo 1>&2 2>>~/EOO/
    /fo./
    EOO
    EOI

    : no-newline
    :
    $c <<EOI && $b
    cat <:foo >>:~/EOO/
    /fo./
    EOO
    EOI

    : line-char
    :
    $c <<EOI && $b
    cat <<EOF >>~/EOO/
    foo
    bar
    baz
    baz
    Biz
    Fox
    fox




    EOF
    foo
    /?
    /bar/
    /baz/+
    /biz/i
    /fox/i+

    //
    //{2}
    EOO
    EOI

    : expansion
    :
    $c <<EOI && $b
    s="O*/i
    bar
    ";
    cat <<EOF >>~"/EOO/"
    foo
    bar

    baz
    EOF
    /f$(s)
    baz
    EOO
    EOI

    : invalid-syntax-char
    :
    $c <<EOI && $b 2>>EOE != 0
    cat <foo >>~/EOO/
    /x
    EOO
    EOI
    testscript:2:1: error: invalid syntax character 'x' in stdout regex redirect
      info: regex line: '/x'
      info: test id: 1
    EOE

    : invalid-char-regex
    :
    $c <<EOI && $b 2>>~/EOE/ != 0
    cat <foo >>~/EOO/
    /foo[/
    EOO
    EOI
    /testscript:2:1: error: invalid char-regex in stdout regex redirect.*/
      info: regex line: '/foo[/'
      info: test id: 1
    EOE

    : invalid-line-regex
    :
    $c <<EOI && $b 2>>/~%EOE% != 0
    cat <foo >>~/EOO/
    a
    /{
    EOO
    EOI
    %testscript:4:1: error: invalid stdout regex redirect.*%
      info: stdout regex: test/1/stdout.regex
      info: test id: 1
    EOE

    : no-match
    :
    {
      : leading-blank
      :
      $c <<EOI && $b 2>>/EOE != 0
      cat <foo >>~/EOO/

      foo
      EOO
      EOI
      testscript:1:1: error: cat stdout doesn't match regex
        info: stdout: test/1/stdout
        info: stdout regex: test/1/stdout.regex
        info: stdin: test/1/stdin
      foo
        info: test id: 1
      EOE
    }
  }
}

:flags
:
{
  : str
  :
  {
    : i
    :
    $c <'cat <Foo >~/foo/i' && $b

    : d
    :
    {
      : escaped-dot
      :
      : Escaped dot becomes syntax dot and matches any character ('i' in our
      : case).
      :
      $c <'cat <fio >~/f\\.o/d' && $b

      : syntax-dot
      :
      : Syntax dot becomes escaped dot and matches only '.' and so we fail.
      :
      $c <'cat <fio >~/f.o/d' && $b 2>>~/EOE/ != 0
      testscript:1:1: error: cat stdout doesn't match regex
      /.+
      EOE
    }
  }

  : doc
  {
    : i
    :
    $c <<EOI && $b
    cat <Foo >>~/EOO/
    /foo/i
    EOO
    EOI

    : d
    :
    : All the reasonings for the /flags/str/d test group are valid for the
    : current one.
    :
    {
      : escaped-dot
      :
      $c <<EOI && $b
      cat <fio >>~/EOO/
      /f\.o/d
      EOO
      EOI

      : syntax-dot
      :
      $c <<EOI && $b 2>>~/EOE/ != 0
      cat <fio >>~/EOO/
      /f.o/d
      EOO
      EOI
      testscript:1:1: error: cat stdout doesn't match regex
      /.+
      EOE
    }

    : global
    :
    {
      : i
      :
      $c <<EOI && $b
      cat <Foo >>~/EOO/i
      /foo/
      EOO
      EOI

      : d
      :
      {
        : escaped-dot
        :
        $c <<EOI && $b
        cat <fio >>~/EOO/d
        /f\.o/
        EOO
        EOI

        : syntax-dot
        :
        $c <<EOI && $b 2>>~/EOE/ != 0
        cat <fio >>~/EOO/d
        /f.o/
        EOO
        EOI
        testscript:1:1: error: cat stdout doesn't match regex
        /.+
        EOE
      }
    }
  }
}

: portable-path
:
{
  ps = ($cxx.target.class != 'windows' ? '/' : '\')

  : str
  :
  {
    $c <"cat <'foo$ps' >/~%foo/%" && $b       : out
    $c <"cat <'foo$ps' 1>&2 2>/~%foo/%" && $b : err
  }

  : doc
  {
    : out
    :
    $c <<"EOI" && $b
    cat <'foo$ps' >>/~%EOO%
    foo/
    EOO
    EOI

    : err
    :
    $c <<"EOI" && $b
    cat <'foo$ps' 1>&2 2>>/~%EOO%
    foo/
    EOO
    EOI
  }
}