forked from mvdan/sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.go
2543 lines (2476 loc) · 55.5 KB
/
parser_test.go
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2016, Daniel Martí <[email protected]>
// See LICENSE for licensing information
package syntax
import (
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
"regexp"
"strings"
"sync"
"testing"
"github.com/go-quicktest/qt"
"github.com/google/go-cmp/cmp"
)
func TestParseBashKeepComments(t *testing.T) {
t.Parallel()
p := NewParser(KeepComments(true))
for i, c := range fileTestsKeepComments {
want := c.Bash
if want == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j), singleParse(p, in, want))
}
}
}
func TestParseBash(t *testing.T) {
t.Parallel()
p := NewParser()
for i, c := range append(fileTests, fileTestsNoPrint...) {
want := c.Bash
if want == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j), singleParse(p, in, want))
}
}
}
func TestParsePosOverflow(t *testing.T) {
t.Parallel()
// Consider using a custom reader to save memory.
tests := []struct {
name, in, want string
}{
{
"LineOverflowIsValid",
strings.Repeat("\n", lineMax) + "foo; bar",
"<nil>",
},
{
"LineOverflowPosString",
strings.Repeat("\n", lineMax) + ")",
"?:1: ) can only be used to close a subshell",
},
{
"LineOverflowExtraPosString",
strings.Repeat("\n", lineMax+5) + ")",
"?:1: ) can only be used to close a subshell",
},
{
"ColOverflowPosString",
strings.Repeat(" ", colMax) + ")",
"1:?: ) can only be used to close a subshell",
},
{
"ColOverflowExtraPosString",
strings.Repeat(" ", colMax) + ")",
"1:?: ) can only be used to close a subshell",
},
{
"ColOverflowSkippedPosString",
strings.Repeat(" ", colMax+5) + "\n)",
"2:1: ) can only be used to close a subshell",
},
{
"LargestLineNumber",
strings.Repeat("\n", lineMax-1) + ")",
"262143:1: ) can only be used to close a subshell",
},
{
"LargestColNumber",
strings.Repeat(" ", colMax-1) + ")",
"1:16383: ) can only be used to close a subshell",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
test := test
t.Parallel()
p := NewParser()
_, err := p.Parse(strings.NewReader(test.in), "")
got := fmt.Sprint(err)
if got != test.want {
t.Fatalf("want error %q, got %q", test.want, got)
}
})
}
}
func TestParsePosix(t *testing.T) {
t.Parallel()
p := NewParser(Variant(LangPOSIX))
for i, c := range append(fileTests, fileTestsNoPrint...) {
want := c.Posix
if want == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j),
singleParse(p, in, want))
}
}
}
func TestParseMirBSDKorn(t *testing.T) {
t.Parallel()
p := NewParser(Variant(LangMirBSDKorn))
for i, c := range append(fileTests, fileTestsNoPrint...) {
want := c.MirBSDKorn
if want == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j),
singleParse(p, in, want))
}
}
}
func TestParseBats(t *testing.T) {
t.Parallel()
p := NewParser(Variant(LangBats))
for i, c := range append(fileTests, fileTestsNoPrint...) {
want := c.Bats
if want == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j),
singleParse(p, in, want))
}
}
}
func TestMain(m *testing.M) {
// Set the locale to computer-friendly English and UTF-8, C.UTF-8,
// which started shipping with glibc 2.35 in February 2022.
os.Setenv("LANGUAGE", "C.UTF-8")
os.Setenv("LC_ALL", "C.UTF-8")
os.Exit(m.Run())
}
var (
onceHasBash52 = sync.OnceValue(func() bool {
return cmdContains("version 5.2", "bash", "--version")
})
onceHasDash059 = sync.OnceValue(func() bool {
// dash provides no way to check its version, so we have to
// check if it's new enough as to not have the bug that breaks
// our integration tests.
// This also means our check does not require a specific version.
return cmdContains("Bad subst", "dash", "-c", "echo ${#<}")
})
onceHasMksh59 = sync.OnceValue(func() bool {
return cmdContains(" R59 ", "mksh", "-c", "echo $KSH_VERSION")
})
)
func requireBash52(tb testing.TB) {
if !onceHasBash52() {
tb.Skipf("bash 5.2 required to run")
}
}
func requireDash059(tb testing.TB) {
if !onceHasDash059() {
tb.Skipf("dash 0.5.9+ required to run")
}
}
func requireMksh59(tb testing.TB) {
if !onceHasMksh59() {
tb.Skipf("mksh 59 required to run")
}
}
func cmdContains(substr, cmd string, args ...string) bool {
out, err := exec.Command(cmd, args...).CombinedOutput()
got := string(out)
if err != nil {
got += "\n" + err.Error()
}
return strings.Contains(got, substr)
}
var extGlobRe = regexp.MustCompile(`[@?*+!]\(`)
func confirmParse(in, cmd string, wantErr bool) func(*testing.T) {
return func(t *testing.T) {
t.Helper()
t.Parallel()
var opts []string
if strings.Contains(in, "\\\r\n") {
t.Skip("shells do not generally support CRLF line endings")
}
if cmd == "bash" && extGlobRe.MatchString(in) {
// otherwise bash refuses to parse these
// properly. Also avoid -n since that too makes
// bash bail.
in = "shopt -s extglob\n" + in
} else if !wantErr {
// -n makes bash accept invalid inputs like
// "let" or "`{`", so only use it in
// non-erroring tests. Should be safe to not use
// -n anyway since these are supposed to just fail.
// also, -n will break if we are using extglob
// as extglob is not actually applied.
opts = append(opts, "-n")
}
cmd := exec.Command(cmd, opts...)
cmd.Dir = t.TempDir() // to be safe
cmd.Stdin = strings.NewReader(in)
var stderr bytes.Buffer
cmd.Stderr = &stderr
err := cmd.Run()
if stderr.Len() > 0 {
// bash sometimes likes to error on an input via stderr
// while forgetting to set the exit code to non-zero. Fun.
// Note that we also treat warnings as errors.
err = errors.New(stderr.String())
}
if err != nil && strings.Contains(err.Error(), "command not found") {
err = nil
}
if wantErr && err == nil {
t.Fatalf("Expected error in %q of %q, found none", strings.Join(cmd.Args, " "), in)
} else if !wantErr && err != nil {
t.Fatalf("Unexpected error in %q of %q: %v", strings.Join(cmd.Args, " "), in, err)
}
}
}
func TestParseBashConfirm(t *testing.T) {
if testing.Short() {
t.Skip("calling bash is slow.")
}
requireBash52(t)
i := 0
for _, c := range append(fileTests, fileTestsNoPrint...) {
if c.Bash == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j),
confirmParse(in, "bash", false))
}
i++
}
}
func TestParsePosixConfirm(t *testing.T) {
if testing.Short() {
t.Skip("calling dash is slow.")
}
requireDash059(t)
i := 0
for _, c := range append(fileTests, fileTestsNoPrint...) {
if c.Posix == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j),
confirmParse(in, "dash", false))
}
i++
}
}
func TestParseMirBSDKornConfirm(t *testing.T) {
if testing.Short() {
t.Skip("calling mksh is slow.")
}
requireMksh59(t)
i := 0
for _, c := range append(fileTests, fileTestsNoPrint...) {
if c.MirBSDKorn == nil {
continue
}
for j, in := range c.Strs {
t.Run(fmt.Sprintf("#%03d-%d", i, j),
confirmParse(in, "mksh", false))
}
i++
}
}
func TestParseErrBashConfirm(t *testing.T) {
if testing.Short() {
t.Skip("calling bash is slow.")
}
requireBash52(t)
for _, c := range shellTests {
want := c.common
if c.bsmk != nil {
want = c.bsmk
}
if c.bash != nil {
want = c.bash
}
if want == nil {
continue
}
wantErr := !strings.Contains(want.(string), " #NOERR")
t.Run("", confirmParse(c.in, "bash", wantErr))
}
}
func TestParseErrPosixConfirm(t *testing.T) {
if testing.Short() {
t.Skip("calling dash is slow.")
}
requireDash059(t)
for _, c := range shellTests {
want := c.common
if c.posix != nil {
want = c.posix
}
if want == nil {
continue
}
wantErr := !strings.Contains(want.(string), " #NOERR")
t.Run("", confirmParse(c.in, "dash", wantErr))
}
}
func TestParseErrMirBSDKornConfirm(t *testing.T) {
if testing.Short() {
t.Skip("calling mksh is slow.")
}
requireMksh59(t)
for _, c := range shellTests {
want := c.common
if c.bsmk != nil {
want = c.bsmk
}
if c.mksh != nil {
want = c.mksh
}
if want == nil {
continue
}
wantErr := !strings.Contains(want.(string), " #NOERR")
t.Run("", confirmParse(c.in, "mksh", wantErr))
}
}
var cmpOpt = cmp.FilterValues(func(p1, p2 Pos) bool { return true }, cmp.Ignore())
func singleParse(p *Parser, in string, want *File) func(t *testing.T) {
return func(t *testing.T) {
t.Helper()
got, err := p.Parse(newStrictReader(in), "")
if err != nil {
t.Fatalf("Unexpected error in %q: %v", in, err)
}
recursiveSanityCheck(t, in, got)
if diff := cmp.Diff(want, got, cmpOpt); diff != "" {
t.Errorf("syntax tree mismatch in %q (-want +got):\n%s", in, diff)
}
}
}
func BenchmarkParse(b *testing.B) {
b.ReportAllocs()
src := "" +
strings.Repeat("\n\n\t\t \n", 10) +
"# " + strings.Repeat("foo bar ", 10) + "\n" +
strings.Repeat("longlit_", 10) + "\n" +
"'" + strings.Repeat("foo bar ", 10) + "'\n" +
`"` + strings.Repeat("foo bar ", 10) + `"` + "\n" +
strings.Repeat("aa bb cc dd; ", 6) +
"a() { (b); { c; }; }; $(d; `e`)\n" +
"foo=bar; a=b; c=d$foo${bar}e $simple ${complex:-default}\n" +
"if a; then while b; do for c in d e; do f; done; done; fi\n" +
"a | b && c || d | e && g || f\n" +
"foo >a <b <<<c 2>&1 <<EOF\n" +
strings.Repeat("somewhat long heredoc line\n", 10) +
"EOF" +
""
p := NewParser(KeepComments(true))
in := strings.NewReader(src)
for i := 0; i < b.N; i++ {
if _, err := p.Parse(in, ""); err != nil {
b.Fatal(err)
}
in.Reset(src)
}
}
type errorCase struct {
in string
common any
bash, posix any
bsmk, mksh any
}
var shellTests = []errorCase{
{
in: "echo \x80",
common: `1:6: invalid UTF-8 encoding #NOERR common shells use bytes`,
},
{
in: "\necho \x80",
common: `2:6: invalid UTF-8 encoding #NOERR common shells use bytes`,
},
{
in: "echo foo\x80bar",
common: `1:9: invalid UTF-8 encoding #NOERR common shells use bytes`,
},
{
in: "echo foo\xc3",
common: `1:9: invalid UTF-8 encoding #NOERR common shells use bytes`,
},
{
in: "#foo\xc3",
common: `1:5: invalid UTF-8 encoding #NOERR common shells use bytes`,
},
{
in: "echo a\x80",
common: `1:7: invalid UTF-8 encoding #NOERR common shells use bytes`,
},
{
in: "<<$\xc8\n$\xc8",
common: `1:4: invalid UTF-8 encoding #NOERR common shells use bytes`,
},
{
in: "echo $((foo\x80bar",
common: `1:12: invalid UTF-8 encoding`,
},
{
in: "z=($\\\n#\\\n\\\n$#\x91\\\n",
bash: `4:3: invalid UTF-8 encoding`,
},
{
in: `((# 1 + 2))`,
bash: `1:1: unsigned expressions are a mksh feature`,
},
{
in: `$((# 1 + 2))`,
posix: `1:1: unsigned expressions are a mksh feature`,
bash: `1:1: unsigned expressions are a mksh feature`,
},
{
in: `${ foo;}`,
posix: `1:1: "${ stmts;}" is a mksh feature`,
bash: `1:1: "${ stmts;}" is a mksh feature`,
},
{
in: `${ `,
mksh: `1:1: reached EOF without matching ${ with }`,
},
{
in: `${ foo;`,
mksh: `1:1: reached EOF without matching ${ with }`,
},
{
in: `${ foo }`,
mksh: `1:1: reached EOF without matching ${ with }`,
},
{
in: `${|foo;}`,
posix: `1:1: "${|stmts;}" is a mksh feature`,
bash: `1:1: "${|stmts;}" is a mksh feature`,
},
{
in: `${|`,
mksh: `1:1: reached EOF without matching ${ with }`,
},
{
in: `${|foo;`,
mksh: `1:1: reached EOF without matching ${ with }`,
},
{
in: `${|foo }`,
mksh: `1:1: reached EOF without matching ${ with }`,
},
{
in: "((foo\x80bar",
common: `1:6: invalid UTF-8 encoding`,
},
{
in: ";\x80",
common: `1:2: invalid UTF-8 encoding`,
},
{
in: "${a\x80",
common: `1:4: invalid UTF-8 encoding`,
},
{
in: "${a#\x80",
common: `1:5: invalid UTF-8 encoding`,
},
{
in: "${a-'\x80",
common: `1:6: invalid UTF-8 encoding`,
},
{
in: "echo $((a |\x80",
common: `1:12: invalid UTF-8 encoding`,
},
{
in: "!",
common: `1:1: "!" cannot form a statement alone`,
},
{
// bash allows lone '!', unlike dash, mksh, and us.
in: "! !",
common: `1:1: cannot negate a command multiple times`,
bash: `1:1: cannot negate a command multiple times #NOERR`,
},
{
in: "! ! foo",
common: `1:1: cannot negate a command multiple times #NOERR`,
posix: `1:1: cannot negate a command multiple times`,
},
{
in: "}",
common: `1:1: "}" can only be used to close a block`,
},
{
in: "then",
common: `1:1: "then" can only be used in an if`,
},
{
in: "elif",
common: `1:1: "elif" can only be used in an if`,
},
{
in: "fi",
common: `1:1: "fi" can only be used to end an if`,
},
{
in: "do",
common: `1:1: "do" can only be used in a loop`,
},
{
in: "done",
common: `1:1: "done" can only be used to end a loop`,
},
{
in: "esac",
common: `1:1: "esac" can only be used to end a case`,
},
{
in: "a=b { foo; }",
common: `1:12: "}" can only be used to close a block`,
},
{
in: "a=b foo() { bar; }",
common: `1:8: a command can only contain words and redirects; encountered (`,
},
{
in: "a=b if foo; then bar; fi",
common: `1:13: "then" can only be used in an if`,
},
{
in: ">f { foo; }",
common: `1:11: "}" can only be used to close a block`,
},
{
in: ">f foo() { bar; }",
common: `1:7: a command can only contain words and redirects; encountered (`,
},
{
in: ">f if foo; then bar; fi",
common: `1:12: "then" can only be used in an if`,
},
{
in: "if done; then b; fi",
common: `1:4: "done" can only be used to end a loop`,
},
{
in: "'",
common: `1:1: reached EOF without closing quote '`,
},
{
in: `"`,
common: `1:1: reached EOF without closing quote "`,
},
{
in: `'\''`,
common: `1:4: reached EOF without closing quote '`,
},
{
in: ";",
common: `1:1: ; can only immediately follow a statement`,
},
{
in: "{ ; }",
common: `1:3: ; can only immediately follow a statement`,
},
{
in: `"foo"(){ :; }`,
common: `1:1: invalid func name`,
mksh: `1:1: invalid func name #NOERR`,
},
{
in: `foo$bar(){ :; }`,
common: `1:1: invalid func name`,
},
{
in: "{",
common: `1:1: reached EOF without matching { with }`,
},
{
in: "{ #}",
common: `1:1: reached EOF without matching { with }`,
},
{
in: "(",
common: `1:1: reached EOF without matching ( with )`,
},
{
in: ")",
common: `1:1: ) can only be used to close a subshell`,
},
{
in: "`",
common: "1:1: reached EOF without closing quote `",
},
{
in: ";;",
common: `1:1: ;; can only be used in a case clause`,
},
{
in: "( foo;",
common: `1:1: reached EOF without matching ( with )`,
},
{
in: "&",
common: `1:1: & can only immediately follow a statement`,
},
{
in: "|",
common: `1:1: | can only immediately follow a statement`,
},
{
in: "&&",
common: `1:1: && can only immediately follow a statement`,
},
{
in: "||",
common: `1:1: || can only immediately follow a statement`,
},
{
in: "foo; || bar",
common: `1:6: || can only immediately follow a statement`,
},
{
in: "echo & || bar",
common: `1:8: || can only immediately follow a statement`,
},
{
in: "echo & ; bar",
common: `1:8: ; can only immediately follow a statement`,
},
{
in: "foo;;",
common: `1:4: ;; can only be used in a case clause`,
},
{
in: "foo(",
common: `1:1: "foo(" must be followed by )`,
},
{
in: "foo(bar",
common: `1:1: "foo(" must be followed by )`,
},
{
in: "à(",
common: `1:1: "foo(" must be followed by )`,
},
{
in: "foo'",
common: `1:4: reached EOF without closing quote '`,
},
{
in: `foo"`,
common: `1:4: reached EOF without closing quote "`,
},
{
in: `"foo`,
common: `1:1: reached EOF without closing quote "`,
},
{
in: `"foobar\`,
common: `1:1: reached EOF without closing quote "`,
},
{
in: `"foo\a`,
common: `1:1: reached EOF without closing quote "`,
},
{
in: "foo()",
common: `1:1: "foo()" must be followed by a statement`,
mksh: `1:1: "foo()" must be followed by a statement #NOERR`,
},
{
in: "foo() {",
common: `1:7: reached EOF without matching { with }`,
},
{
in: "foo-bar() { x; }",
posix: `1:1: invalid func name`,
},
{
in: "foò() { x; }",
posix: `1:1: invalid func name`,
},
{
in: "echo foo(",
common: `1:9: a command can only contain words and redirects; encountered (`,
},
{
in: "echo &&",
common: `1:6: && must be followed by a statement`,
},
{
in: "echo |",
common: `1:6: | must be followed by a statement`,
},
{
in: "echo ||",
common: `1:6: || must be followed by a statement`,
},
{
in: "echo | #bar",
common: `1:6: | must be followed by a statement`,
},
{
in: "echo && #bar",
common: `1:6: && must be followed by a statement`,
},
{
in: "`echo &&`",
common: `1:7: && must be followed by a statement`,
},
{
in: "`echo |`",
common: `1:7: | must be followed by a statement`,
},
{
in: "echo | ! bar",
common: `1:8: "!" can only be used in full statements`,
},
{
in: "echo >",
common: `1:6: > must be followed by a word`,
},
{
in: "echo >>",
common: `1:6: >> must be followed by a word`,
},
{
in: "echo <",
common: `1:6: < must be followed by a word`,
},
{
in: "echo 2>",
common: `1:7: > must be followed by a word`,
},
{
in: "echo <\nbar",
common: `1:6: < must be followed by a word`,
},
{
in: "echo | < #bar",
common: `1:8: < must be followed by a word`,
},
{
in: "echo && > #",
common: `1:9: > must be followed by a word`,
},
{
in: "foo &>/dev/null",
posix: `1:5: &> redirects are a bash/mksh feature`,
},
{
in: "foo &>>/dev/null",
posix: `1:5: &> redirects are a bash/mksh feature`,
},
{
in: "<<",
common: `1:1: << must be followed by a word`,
},
{
in: "<<EOF",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<EOF\n\\",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<EOF\n\\\n",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<EOF\n\\\nEOF",
// Seems like mksh has a bug here.
common: `1:1: unclosed here-document 'EOF' #NOERR`,
},
{
in: "<<EOF\nfoo\\\nEOF",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<'EOF'\n\\\n",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<EOF <`\n#\n`\n``",
common: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<'EOF'",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<\\EOF",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<\\\\EOF",
common: `1:1: unclosed here-document '\EOF' #NOERR`,
bsmk: `1:1: unclosed here-document '\EOF'`,
},
{
in: "<<-EOF",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<-EOF\n\t",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<-'EOF'\n\t",
common: `1:1: unclosed here-document 'EOF' #NOERR`,
bsmk: `1:1: unclosed here-document 'EOF'`,
},
{
in: "<<\nEOF\nbar\nEOF",
common: `1:1: << must be followed by a word`,
},
{
in: "$(<<EOF\nNOTEOF)",
bsmk: `1:3: unclosed here-document 'EOF'`,
},
{
in: "`<<EOF\nNOTEOF`",
bsmk: `1:2: unclosed here-document 'EOF'`,
},
{
in: "if",
common: `1:1: "if" must be followed by a statement list`,
},
{
in: "if true;",
common: `1:1: "if <cond>" must be followed by "then"`,
},
{
in: "if true then",
common: `1:1: "if <cond>" must be followed by "then"`,
},
{
in: "if true; then bar;",
common: `1:1: if statement must end with "fi"`,
},
{
in: "if true; then bar; fi#etc",
common: `1:1: if statement must end with "fi"`,
},
{
in: "if a; then b; elif c;",
common: `1:15: "elif <cond>" must be followed by "then"`,
},
{
in: "'foo' '",
common: `1:7: reached EOF without closing quote '`,
},
{
in: "'foo\n' '",
common: `2:3: reached EOF without closing quote '`,
},
{
in: "while",
common: `1:1: "while" must be followed by a statement list`,
},
{
in: "while true;",
common: `1:1: "while <cond>" must be followed by "do"`,
},
{
in: "while true; do bar",
common: `1:1: while statement must end with "done"`,
},
{
in: "while true; do bar;",
common: `1:1: while statement must end with "done"`,
},
{
in: "until",
common: `1:1: "until" must be followed by a statement list`,
},
{
in: "until true;",
common: `1:1: "until <cond>" must be followed by "do"`,
},
{
in: "until true; do bar",
common: `1:1: until statement must end with "done"`,
},
{
in: "until true; do bar;",
common: `1:1: until statement must end with "done"`,
},
{
in: "for",
common: `1:1: "for" must be followed by a literal`,
},
{
in: "for i",
common: `1:1: "for foo" must be followed by "in", "do", ;, or a newline`,
},
{
in: "for i in;",
common: `1:1: "for foo [in words]" must be followed by "do"`,
},
{
in: "for i in 1 2 3;",
common: `1:1: "for foo [in words]" must be followed by "do"`,
},
{
in: "for i in 1 2 &",
common: `1:1: "for foo [in words]" must be followed by "do"`,
},
{
in: "for i in 1 2 (",
common: `1:14: word list can only contain words`,
},
{
in: "for i in 1 2 3; do echo $i;",
common: `1:1: for statement must end with "done"`,
},
{
in: "for i in 1 2 3; echo $i;",
common: `1:1: "for foo [in words]" must be followed by "do"`,
},
{
in: "for 'i' in 1 2 3; do echo $i; done",
common: `1:1: "for" must be followed by a literal`,
},
{
in: "for in 1 2 3; do echo $i; done",
common: `1:1: "for foo" must be followed by "in", "do", ;, or a newline`,
},
{
in: "select",
bsmk: `1:1: "select" must be followed by a literal`,
},
{
in: "select i",
bsmk: `1:1: "select foo" must be followed by "in", "do", ;, or a newline`,
},
{
in: "select i in;",