-
Notifications
You must be signed in to change notification settings - Fork 28
/
startup-y.tst
695 lines (587 loc) · 12.7 KB
/
startup-y.tst
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
# startup-y.tst: yash-specific test of shell startup
test_O -e 17 'one operand with -c' -c 'exit 17'
__IN__
test_o -e 0 'two operands with -c' \
-c 'printf "[%s]\n" "$0" "$@"' 'command name'
__IN__
[command name]
__OUT__
test_o -e 0 'one positional parameter with -c' \
-c 'printf "[%s]\n" "$0" "$@"' 0 1
__IN__
[0]
[1]
__OUT__
test_o -e 0 'many positional parameters with -c' \
-c 'printf "[%s]\n" "$0" "$@"' 0 1 '2 2' 3 4 - 6 7 8 9 10 11
__IN__
[0]
[1]
[2 2]
[3]
[4]
[-]
[6]
[7]
[8]
[9]
[10]
[11]
__OUT__
test_oE -e 0 'stdin is not used with -c'
"$TESTEE" -c 'echo foo' <&-
__IN__
foo
__OUT__
test_oE -e 19 'no operands with -s' -s
echo $#
exit 19
__IN__
0
__OUT__
test_oE -e 23 'one operand with -s' -s '1 1'
printf "[%s]\n" "$@"
exit 23
__IN__
[1 1]
__OUT__
test_oE 'two operands with -s' -s '1 1' 2
printf "[%s]\n" "$@"
__IN__
[1 1]
[2]
__OUT__
test_oE 'many operands with -s' -s '1 1' 2 3 4 - 6 7 8 9 10 11
printf "[%s]\n" "$@"
__IN__
[1 1]
[2]
[3]
[4]
[-]
[6]
[7]
[8]
[9]
[10]
[11]
__OUT__
test_oE '$0 with -s'
exec -a '0 0' "$TESTEE" -s <<\__END__
printf '[%s]\n' "$0"
__END__
__IN__
[0 0]
__OUT__
test_oE -e 0 'negating -c and enabling -s' -c +c -s
echo ok
__IN__
ok
__OUT__
test_oE -e 0 'negating -s and enabling -c' -s +s -c 'echo ok'
__IN__
ok
__OUT__
testcase "$LINENO" -e 2 'missing command with -c' -c \
3</dev/null 4</dev/null 5<<__ERR__
$testee: the -c option is specified but no command is given
__ERR__
testcase "$LINENO" -e 2 'options -c and -s are mutually exclusive (separate)' \
-c -s 'echo XXX' 3</dev/null 4</dev/null 5<<__ERR__
$testee: the -c option cannot be used with the -s option
__ERR__
testcase "$LINENO" -e 2 'options -c and -s are mutually exclusive (combined)' \
-cs 'echo XXX' 3</dev/null 4</dev/null 5<<__ERR__
$testee: the -c option cannot be used with the -s option
__ERR__
testcase "$LINENO" -e 2 'options -c and -s are mutually exclusive (long)' \
--cmdlin --stdi 3</dev/null 4</dev/null 5<<__ERR__
$testee: the -c option cannot be used with the -s option
__ERR__
testcase "$LINENO" -e 2 'options -c and -s are mutually exclusive (-o)' \
-o cmdlin -o stdi 3</dev/null 4</dev/null 5<<__ERR__
$testee: the -c option cannot be used with the -s option
__ERR__
(
input=./input$LINENO
cat >"$input" <<\__END__
echo input "$*"
cat
exit 3
echo not reached
__END__
test_oE -e 3 'reading file w/o positional parameters' "$input"
stdin
__IN__
input
stdin
__OUT__
test_oE -e 3 'reading file with one positional parameter' "$input" '1 1'
stdin
__IN__
input 1 1
stdin
__OUT__
test_oE -e 3 'reading file with many positional parameters' \
"$input" '1 1' 2 3 4 - 6 7 8 9 10 11
stdin
__IN__
input 1 1 2 3 4 - 6 7 8 9 10 11
stdin
__OUT__
)
(
input=input$LINENO
>"$input"
chmod a-r "$input"
# Skip if we're root.
if { <"$input"; } 2>/dev/null; then
skip="true"
fi
test_O -d -e n 'reading non-readable file' "$input"
__IN__
)
test_O -d -e 127 'reading non-existing file' ./_no_such_file_
__IN__
(
unset YASH_LOADPATH
test_o 'LOADPATH is set to default if missing'
echo ${YASH_LOADPATH:+set}
__IN__
set
__OUT__
)
(
export YASH_LOADPATH=/foo/bar:/baz
test_o 'LOADPATH is not modified if exists in environment'
echo ${YASH_LOADPATH:-unset}
__IN__
/foo/bar:/baz
__OUT__
)
(
export HOME="${PWD%/}/home$LINENO"
mkdir "$HOME"
echo echo profile >"$HOME/.yash_profile"
echo echo yashrc >"$HOME/.yashrc"
test_oE 'startup: no argument'
echo $-
__IN__
s
__OUT__
test_oE 'startup: -c' -c 'echo $-'
__IN__
c
__OUT__
test_oE 'startup: -cl, short option, with profile' -cl 'echo $-'
__IN__
profile
cl
__OUT__
test_oE 'startup: -cl, long option, with profile' --cmdline --log-in 'echo $-'
__IN__
profile
cl
__OUT__
test_oE 'startup: -ci +m, short option, with rcfile' -ci +m 'echo $-'
__IN__
yashrc
ci
__OUT__
test_oE 'startup: -ci +m, long option, with rcfile' \
--cmdline --interactive --no-monitor 'echo $-'
__IN__
yashrc
ci
__OUT__
test_oE 'startup: -cil +m, short option, with profile/rcfile' -cil +m 'echo $-'
__IN__
profile
yashrc
cil
__OUT__
test_oE 'startup: -cil +m, long option, with profile/rcfile' \
--cmdline --interactive --log-in --no-monitor 'echo $-'
__IN__
profile
yashrc
cil
__OUT__
test_oE 'startup: -cil +m --noprofile' -cil +m --noprofile 'echo $-'
__IN__
yashrc
cil
__OUT__
test_oE 'startup: -cil +m --norcfile' -cil +m --norcfile 'echo $-'
__IN__
profile
cil
__OUT__
)
test_oE 'startup: -cl with unset HOME' -cl 'echo $-'
__IN__
cl
__OUT__
test_oE 'startup: -ci +m with unset HOME' -ci +m 'echo $-'
__IN__
ci
__OUT__
(
export HOME="${PWD%/}/_no_such_directory_"
test_oE 'startup: -cl with non-existing HOME' -cl 'echo $-'
__IN__
cl
__OUT__
test_oE 'startup: -ci +m with non-existing HOME' -ci +m 'echo $-'
__IN__
ci
__OUT__
)
(
profile="profile$LINENO"
rcfile="rcfile$LINENO"
echo echo local profile >"$profile"
echo echo local rcfile >"$rcfile"
test_oE 'startup: -cl, specified profile' -cl --profile="$profile" 'echo $-'
__IN__
local profile
cl
__OUT__
test_oE 'startup: -ci +m, specified rcfile' -ci +m --rcfile="$rcfile" 'echo $-'
__IN__
local rcfile
ci
__OUT__
test_oE 'startup: -cil +m, specified rcfile' \
-cil +m --profile="$profile" --rcfile="$rcfile" 'echo $-'
__IN__
local profile
local rcfile
cil
__OUT__
)
(
# Ensure $PWD is safe to assign to $YASH_LOADPATH
case $PWD in (*[:%]*)
skip="true"
esac
export HOME="${PWD%/}/home$LINENO"
export YASH_LOADPATH="$HOME/loadpath"
export ENV='${PWD%/}/_no_such_file_'
mkdir -p "$HOME/loadpath/initialization"
echo echo default >"$HOME/loadpath/initialization/default"
test_oE 'startup: -ci +m, LOADPATH fallback for missing yashrc' \
-ci +m 'echo $-'
__IN__
default
ci
__OUT__
test_oE 'startup: -ci +m, no LOADPATH fallback in POSIX mode' \
--posix -ci +m 'echo $-'
__IN__
ci
__OUT__
test_oE 'startup: -ci +m, no LOADPATH fallback with specified rcfile' \
-ci +m --rcfile=_no_such_file_ 'echo $-'
__IN__
ci
__OUT__
echo echo yashrc >"$HOME/.yashrc"
test_oE 'startup: -ci +m, no LOADPATH fallback if ~/.yashrc found' \
-ci +m 'echo $-'
__IN__
yashrc
ci
__OUT__
)
(
export HOME="${PWD%/}/home$LINENO"
mkdir "$HOME"
cat >"$HOME/.yash_profile" <<\__END__
echo error 1
. "$HOME/profile2"
echo error 1 syntax error \$\?=$?
unset var
echo ${var?}
echo error 1 expansion error \$\?=$?
fi
echo not reached
__END__
cat >"$HOME/profile2" <<\__END__
echo error 2
unset var
echo ${var?}
echo error 2 expansion error \$\?=$?
fi
echo not reached
__END__
ln -s .yash_profile "$HOME/.yashrc"
test_o -d -e 0 'errors in profile' -cl 'echo $-'
__IN__
error 1
error 2
error 2 expansion error $?=2
error 1 syntax error $?=258
error 1 expansion error $?=2
cl
__OUT__
test_o -d -e 0 'errors in rcfile' -ci +m 'echo $-'
__IN__
error 1
error 2
error 2 expansion error $?=2
error 1 syntax error $?=258
error 1 expansion error $?=2
ci
__OUT__
)
test_o 'startup: -abCcefhluvx' -abCcefhluvx 'echo $-'
__IN__
aCcefhlbuvx
__OUT__
test_o 'startup: -abCefhlsuvx' -abCefhlsuvx
echo $-
__IN__
aCefhlbsuvx
__OUT__
test_oE 'first operand is ignored if it is a hyphen (-c)' -c - 'echo $-'
__IN__
c
__OUT__
test_oE 'first operand is ignored if it is a hyphen (-s)' -s - -- 2
echo $- "$2" "$1"
__IN__
s 2 --
__OUT__
test_oE 'first operand is ignored if it is a hyphen (no -c or -s)' -
echo $- $#
__IN__
s 0
__OUT__
(
echo echo env >env
export ENV='${PWD%/}/env'
test_oE 'startup: --posix -c' --posix -c 'echo $-'
__IN__
c
__OUT__
test_oE 'startup: --posix -ci +m' --posix -ci +m 'echo $-'
__IN__
env
ci
__OUT__
)
test_oE 'startup: --posix -ci +m with unset ENV' --posix -ci +m 'echo $-'
__IN__
ci
__OUT__
(
export ENV='${PWD%/}/_no_such_file_'
test_oE 'startup: --posix -ci +m with non-existing ENV' --posix -ci +m 'echo $-'
__IN__
ci
__OUT__
)
test_oE 'program name yash disables POSIX mode (w/o directory name)'
exec -a yash "$TESTEE" <<\__END__
set +o | grep posixlycorrect
__END__
__IN__
set +o posixlycorrect
__OUT__
test_oE 'program name yash disables POSIX mode (with directory name)'
exec -a /bin/yash "$TESTEE" <<\__END__
set +o | grep posixlycorrect
__END__
__IN__
set +o posixlycorrect
__OUT__
test_oE 'program name sh enables POSIX mode (w/o directory name)'
exec -a sh "$TESTEE" <<\__END__
set +o | grep posixlycorrect
__END__
__IN__
set -o posixlycorrect
__OUT__
test_oE 'program name sh enables POSIX mode (with directory name)'
exec -a /bin/sh "$TESTEE" <<\__END__
set +o | grep posixlycorrect
__END__
__IN__
set -o posixlycorrect
__OUT__
test_oE 'hyphen prefix enables interactive mode (w/o directory name)'
exec -a -yash "$TESTEE" <<\__END__
echo $-
__END__
__IN__
ls
__OUT__
test_oE 'hyphen prefix enables interactive mode (with directory name)'
exec -a -/bin/yash "$TESTEE" <<\__END__
echo $-
__END__
__IN__
ls
__OUT__
# We cannot test this without mocking the terminal.
#test_oE 'interactive mode is enabled if stdin/stdout are terminal'
# Tested in job-y.tst
#test_oE 'job control is on by default in interactive shell'
(
if ! testee --version --verbose | grep -Fqx ' * help' ||
! testee --version --verbose | grep -Fqx ' * lineedit'; then
skip="true"
fi
test_oE -e 0 'help' --help
__IN__
Syntax:
yash [option...] [filename [argument...]]
yash [option...] -c command [command_name [argument...]]
yash [option...] -s [argument...]
Options:
--help
-V --version
--noprofile
--norcfile
--profile=...
--rcfile=...
-a -o allexport
-o braceexpand
-o caseglob
+C -o clobber
-c -o cmdline
-o curasync
-o curbg
-o curstop
-o dotglob
-o emacs
-o emptylastfield
-e -o errexit
-o errreturn
+n -o exec
-o extendedglob
-o forlocal
+f -o glob
-h -o hashondef
-o histspace
-o ignoreeof
-i -o interactive
-o lealwaysrp
-o lecompdebug
-o leconvmeta
-o lenoconvmeta
-o lepredict
-o lepredictempty
-o lepromptsp
-o levisiblebell
-o log
-l -o login
-o markdirs
-m -o monitor
-b -o notify
-o notifyle
-o nullglob
-o pipefail
-o posixlycorrect
-s -o stdin
-o traceall
+u -o unset
-v -o verbose
-o vi
-x -o xtrace
Try `man yash' for details.
__OUT__
#`
# No long options in the POSIXly-correct mode
test_oE -e 0 'help (POSIX)' --help --posixly-correct
__IN__
Syntax:
sh [option...] [filename [argument...]]
sh [option...] -c command [command_name [argument...]]
sh [option...] -s [argument...]
Options:
-a -o allexport
-o braceexpand
-o caseglob
+C -o clobber
-c -o cmdline
-o curasync
-o curbg
-o curstop
-o dotglob
-o emacs
-o emptylastfield
-e -o errexit
-o errreturn
+n -o exec
-o extendedglob
-o forlocal
+f -o glob
-h -o hashondef
-o histspace
-o ignoreeof
-i -o interactive
-o lealwaysrp
-o lecompdebug
-o leconvmeta
-o lenoconvmeta
-o lepredict
-o lepredictempty
-o lepromptsp
-o levisiblebell
-o log
-l -o login
-o markdirs
-m -o monitor
-b -o notify
-o notifyle
-o nullglob
-o pipefail
-o posixlycorrect
-s -o stdin
-o traceall
+u -o unset
-v -o verbose
-o vi
-x -o xtrace
Try `man yash' for details.
__OUT__
#`
)
test_E -e 0 'version' --version
__IN__
test_E -e 0 'verbose version, short option' -Vv
__IN__
test_E -e 0 'verbose version, long option' --version --verbose
__IN__
testcase "$LINENO" -e 2 'version (short option in POSIX mode)' --posix -V \
3</dev/null 4</dev/null 5<<__ERR__
$testee: \`V' is not a valid option
__ERR__
#'
testcase "$LINENO" -e 2 'version (long option in POSIX mode)' --posix --versi \
3</dev/null 4</dev/null 5<<__ERR__
$testee: \`--versi' is not a valid option
__ERR__
#'
testcase "$LINENO" -e 2 'unexpected option argument' --norc=_unexpected_ \
3</dev/null 4</dev/null 5<<__ERR__
$testee: --norc=_unexpected_: the --norcfile option does not take an argument
__ERR__
testcase "$LINENO" -e 2 'missing profile option argument' --profile \
3</dev/null 4</dev/null 5<<__ERR__
$testee: the --profile option requires an argument
__ERR__
testcase "$LINENO" -e 2 'missing rcfile option argument' --rcfile \
3</dev/null 4</dev/null 5<<__ERR__
$testee: the --rcfile option requires an argument
__ERR__
testcase "$LINENO" -e 2 'long option in POSIX mode' --posix --monitor \
3</dev/null 4</dev/null 5<<__ERR__
$testee: \`--monitor' is not a valid option
__ERR__
#'
test_O -d -e 2 'ambiguous option' --p
__IN__
# vim: set ft=sh ts=8 sts=4 sw=4 noet: