aboutsummaryrefslogtreecommitdiff
path: root/tests/name/pattern.testscript
blob: 68c674527421f2f22cb2cb6e63a012e98b6bf181 (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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# file      : tests/name/pattern.testscript
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

.include ../common.testscript

+cat <<EOI >=build/root.build
define txt: file
txt{*}: extension = txt
EOI

$* <'print pp%*.txt'       >'pp%*.txt'        : project-simple
$* <'print pp%{*.txt -x*}' >'pp%*.txt pp%-x*' : project-group

$* <"print '*.txt'" >'*.txt' : quoted-single
$* <'print "*.txt"' >'*.txt' : quoted-double
$* <<EOI            >'*.txt' : quoted-expansion
pat = '*'
print "$(pat).txt"
EOI

: detect
:
: Test pattern_mode parsing logic.
{
  : second-pattern
  :
  touch foo.txt;
  $* <'print {foo *.txt}' >'foo foo.txt'

  : independent-patterns
  :
  touch foo.txt -bar;
  $* <'print {*.txt foo* -b*}' >'foo.txt foo.txt -bar'

  : second-inclusion
  :
  touch foo.txt bar.txt;
  $* <'print {f*.txt +b*.txt}' >'foo.txt bar.txt'
}

: diagnostics
:
{
  : simple
  :
  $* <'print {*.txt +foo file{bar}}' 2>>EOE != 0
  <stdin>:1:19: error: expected name pattern inclusion or exclusion
  EOE

  : inclusion-exclusion-sign
  :
  $* <'print {*.txt -foo bar}' 2>>EOE != 0
  <stdin>:1:19: error: expected name pattern inclusion or exclusion
  EOE

  : inclusion-quoted
  :
  $* <'print {*.txt -foo "+bar"}' 2>>EOE != 0
  <stdin>:1:19: error: expected name pattern inclusion or exclusion
  EOE

  : empty-inclusion-exclusion
  :
  $* <'print {*.txt -}' 2>>EOE != 0
  <stdin>:1:8: error: empty name pattern
  EOE

  : inconsistent-result
  :
  $* <'print {*.txt +foo/}' 2>>EOE != 0
  <stdin>:1:8: error: inconsistent file/directory result in name pattern
  EOE
}

: basics
:
{
  touch foo.txt;
  $* <'print *.txt' >'foo.txt'                     : simple-file

  mkdir foo;
  $* <'print */' >/'foo/'                          : simple-dir

  touch foo.txt;
  $* <'print {*.txt}' >'foo.txt'                   : group

  touch foo.txt;
  $* <'print {+*.txt}' >'foo.txt'                  : plus-prefixed

  mkdir dir && touch dir/foo.txt;
  $* <'print dir/{*.txt}' >'dir/foo.txt'           : dir

  touch foo.txt;
  $* <'print file{*.txt}' >'file{foo.txt}'         : type

  touch foo.txt;
  $* <'print x@{*.txt}' >'x@foo.txt'               : pair

  touch bar.txt;
  $* <'print x@dir/file{f*.txt}' >''               : empty

  mkdir dir && touch dir/foo.txt;
  $* <'print **.txt' >/'dir/foo.txt'               : recursive

  mkdir dir && touch dir/foo.txt;
  $* <'print d*/*.txt' >/'dir/foo.txt'             : multi-pattern

  touch foo.txt bar.txt;
  $* <'print {*.txt -bar.txt}' >'foo.txt'          : exclude-non-pattern

  mkdir baz;
  touch foo.txt bar.txt baz/fox.txt baz/box.txt;
  $* <'print {**.txt -b*.txt -b*/*}' >'foo.txt'    : exclude-pattern

  touch foo.txt bar.txt baz.txt;
  $* <'print {*.txt -{*z.txt bar.txt}}' >'foo.txt' : exclude-group

  touch bar.txt;
  $* <'print {f*.txt +bar.txt}' >'bar.txt'         : include-non-wildcard

  touch bar.txt;
  $* <'print {f*.txt +b*.txt}' >'bar.txt'          : include-pattern

  mkdir bar;
  $* <'print {f*/ +{b*/}}' >/'bar/'                : include-group

  touch foo.txt fox.txt;
  $* <'print {*.txt -f*.txt +*x.txt}' >'fox.txt'   : include-exclude-order

  touch foo.txt;
  $* <'print {+foo.txt} {+bar.txt}' >'foo.txt'      : non-wildcard
}

: target-type
:
: Test target type-specific pattern amendment logic.
{
  : append-extension
  :
  touch foo.txt bar.txt;
  $* <'print txt{* -bar}' >'txt{foo}'

  : existing-extension
  :
  touch foo.txt bar.txt;
  $* <'print txt{*.txt -bar.txt}' >'txt{foo.txt}'

  : append-slash
  :
  mkdir foo bar;
  $* <'print dir{* -bar}' >/'dir{foo/}'

  : existing-slash
  :
  mkdir foo bar;
  $* <'print dir{*/ -bar/}' >/'dir{foo/}'
}

: dot
:
: Test filtering of hidden files/directories.
{
  touch foo.txt .foo.txt;
  $* <'print *.txt' >'foo.txt'                       : file-excl

  touch foo.txt .foo.txt;
  $* <'print .*.txt' >'.foo.txt'                     : file-incl

  mkdir dir .dir;
  $* <'print */' >/'dir/'                            : dir-excl

  mkdir dir .dir;
  $* <'print .*/' >/'.dir/'                          : dir-incl

  mkdir dir .dir && touch dir/foo.txt .dir/foo.txt;
  $* <'print */*.txt' >/'dir/foo.txt';
  $* <'print **.txt'  >/'dir/foo.txt'                : dir-interm-excl

  mkdir dir .dir && touch dir/foo.txt .dir/foo.txt;
  $* <'print .*/*.txt' >/'.dir/foo.txt'              : dir-interm-incl
}

: buildignore
:
: Test filtering of a directory and its sub-entries if it contains the
: .buildignore file.
:
{
  mkdir dir1 dir2;
  touch dir2/.buildignore;
  $* <'print */' >/'dir1/'                           : self-excl

  mkdir dir1 dir2;
  touch dir1/foo dir2/foo dir2/.buildignore;
  $* <'print f**' >/'dir1/foo'                       : sub-entry-excl
}

: expansion
:
: Test interaction with expansion/concatenation/re-parse.
{
  # Do we want to recognize patterns in non-concatenating expansion?
  #
  # pat = '*.txt'
  # print $pat
  #
  # While this case is probably better rewritten as (i.e., move pattern search
  # to variable assignment):
  #
  # pat = *.txt
  # print $pat
  #
  # One may also want to do something like this:
  #
  # pat = '*.txt'
  # print dir1/{$pat}
  # print dir2/{$pat}
  #
  # Instead, he should write it as follows:
  #
  # pat = '*.txt'
  # print dir1/{+$pat}
  # print dir2/{+$pat}
  #
  # Note that if we make it work, escaping this case will be pretty hairy:
  #
  # filters = --include '*.txt' --exclude '*.obj'
  # options += $filters

  : prefixed-pattern-via-expansion
  :
  : Pattern is prefixed with the literal unquoted plus character, that is
  : stripped.
  :
  touch foo.txt;
  $* <<EOI >foo.txt
    pat = '*.txt'
    print {+$pat}
    EOI

  : non-prefixed-pattern-via-concat-expansion
  :
  : Plus character is a part of the pattern and so is not stripped.
  :
  touch +foo.txt;
  $* <<EOI >'+foo.txt'
    pat = '+*'
    ext = 'txt'
    print {$pat.$ext}
    EOI

  : not-pattern-expansion
  :
  $* <<EOI >'+*.txt'
    pat = '+*.txt'
    print {$pat}
    EOI

  : not-pattern-quoted
  :
  $* <<EOI >'+*.txt'
    print {'+*.txt'}
    EOI

  : pattern-via-expansion-list
  :
  touch foo.txt bar.hxx;
  $* <<EOI >'bar.hxx foo.txt'
    pats = '*.hxx' '*.txt'
    print {+{$pats}}
    EOI

  : pattern-via-expansion-type
  :
  touch foo.txt;
  $* <<EOI >'txt{foo}'
    pat = '*'
    print txt{+$pat}
    EOI

  : pattern-via-expansion-dir
  :
  mkdir dir;
  touch dir/foo.txt;
  $* <<EOI >dir/foo.txt
    pat = '*.txt'
    print dir/{+$pat}
    EOI

  : pattern-via-expansion-dir-type
  :
  mkdir dir;
  touch dir/foo.txt;
  $* <<EOI >dir/txt{foo}
    pat = '*'
    print dir/txt{+$pat}
    EOI

  : pattern-via-concat
  :
  touch foo.txt;
  $* <<EOI >'foo.txt'
    ext = txt
    print *.$ext
    EOI

  : pattern-via-concat-expansion
  :
  touch foo.txt;
  $* <<EOI >'foo.txt'
    pat = 'f*'
    ext = txt
    print $pat.$ext
    EOI
}

: command-line
:
: Test pattern expansion on the command line.
{
  : variable
  :
  {
    mkdir dir;
    $* <'print $d' 'd=*/' >/'dir/'          : dir

    mkdir dir;
    $* <'print $d' 'd=dir{*}' >/'dir{dir/}' : dir-type

    touch foo.txt;
    $* <'print $f' 'f=*.txt' >'foo.txt'     : feil
  }

  : buildspec
  :
  {
    test.arguments =
    test.options += --buildfile buildfile

    mkdir dir && cat <'./:' >=dir/buildfile;
    $* '*/'                                        : dir

    mkdir dir dir1 && cat <'./:' >=dir/buildfile;
    $* 'update(dir{* -dir1})'                      : dir-type
  }
}