Tue Mar 8 14:19:28 2016 UTC ()
Correct the way that TEST_SH is used so that the tests work as
intended when TEST_SH is specifies a shell that needs options (like
sh -F, or bash -o posix). (from kre)


(christos)
diff -r1.2 -r1.3 src/tests/bin/sh/t_option.sh

cvs diff -r1.2 -r1.3 src/tests/bin/sh/t_option.sh (expand / switch to unified diff)

--- src/tests/bin/sh/t_option.sh 2016/03/01 12:39:35 1.2
+++ src/tests/bin/sh/t_option.sh 2016/03/08 14:19:28 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: t_option.sh,v 1.2 2016/03/01 12:39:35 christos Exp $ 1# $NetBSD: t_option.sh,v 1.3 2016/03/08 14:19:28 christos Exp $
2# 2#
3# Copyright (c) 2016 The NetBSD Foundation, Inc. 3# Copyright (c) 2016 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
@@ -404,62 +404,65 @@ set_v_head() { @@ -404,62 +404,65 @@ set_v_head() {
404 atf_set "descr" "Tests that 'set -v' turns on input read echoing " \ 404 atf_set "descr" "Tests that 'set -v' turns on input read echoing " \
405 "and that it behaves as defined by the standard" 405 "and that it behaves as defined by the standard"
406} 406}
407set_v_body() { 407set_v_body() {
408 test_option_on_off v 408 test_option_on_off v
409 409
410 # check that -v does nothing if no later input line is read 410 # check that -v does nothing if no later input line is read
411 atf_check -s exit:0 \ 411 atf_check -s exit:0 \
412 -o match:OKOK -o not-match:echo -o not-match:printf \ 412 -o match:OKOK -o not-match:echo -o not-match:printf \
413 -e empty \ 413 -e empty \
414 ${TEST_SH} -ec 'printf "%s" OK; set -v; echo OK; exit 0' 414 ${TEST_SH} -ec 'printf "%s" OK; set -v; echo OK; exit 0'
415 415
416 # but that it does when there are multiple lines 416 # but that it does when there are multiple lines
 417 cat <<- 'EOF' |
 418 set -v
 419 printf %s OK
 420 echo OK
 421 exit 0
 422 EOF
417 atf_check -s exit:0 \ 423 atf_check -s exit:0 \
418 -o match:OKOK -o not-match:echo -o not-match:printf \ 424 -o match:OKOK -o not-match:echo -o not-match:printf \
419 -e match:printf -e match:OK -e match:echo \ 425 -e match:printf -e match:OK -e match:echo \
420 ${TEST_SH} -ec '{ 426 -e not-match:set ${TEST_SH}
421 echo "set -v" 
422 echo "printf %s OK" 
423 echo "echo OK" 
424 echo "exit 0" 
425 } | '"'${TEST_SH}'"' -e' 
426 427
427 # and that it can be disabled again 428 # and that it can be disabled again
 429 cat <<- 'EOF' |
 430 set -v
 431 printf %s OK
 432 set +v
 433 echo OK
 434 exit 0
 435 EOF
428 atf_check -s exit:0 \ 436 atf_check -s exit:0 \
429 -o match:OKOK -o not-match:echo -o not-match:printf \ 437 -o match:OKOK -o not-match:echo -o not-match:printf \
430 -e match:printf -e match:OK -e not-match:echo \ 438 -e match:printf -e match:OK -e not-match:echo \
431 ${TEST_SH} -ec '{ 439 ${TEST_SH}
432 echo "set -v" 
433 echo "printf %s OK" 
434 echo "set +v" 
435 echo "echo OK" 
436 echo "exit 0" 
437 } | '"'${TEST_SH}'"' -e' 
438 440
439 # and lastly, that shell keywords do get output when "read" 441 # and lastly, that shell keywords do get output when "read"
 442 cat <<- 'EOF' |
 443 set -v
 444 for i in 111 222 333
 445 do
 446 printf %s $i
 447 done
 448 exit 0
 449 EOF
440 atf_check -s exit:0 \ 450 atf_check -s exit:0 \
441 -o match:111222333 -o not-match:printf \ 451 -o match:111222333 -o not-match:printf \
442 -o not-match:for -o not-match:do -o not-match:done \ 452 -o not-match:for -o not-match:do -o not-match:done \
443 -e match:printf -e match:111 -e not-match:111222 \ 453 -e match:printf -e match:111 -e not-match:111222 \
444 -e match:for -e match:do -e match:done \ 454 -e match:for -e match:do -e match:done \
445 ${TEST_SH} -ec '{ 455 ${TEST_SH}
446 echo "set -v" 
447 echo "for i in 111 222 333" 
448 echo "do" 
449 echo "printf %s \$i" 
450 echo "done" 
451 echo "exit 0" 
452 } | '"'${TEST_SH}'"' -e' 
453} 456}
454 457
455atf_test_case set_x 458atf_test_case set_x
456set_x_head() { 459set_x_head() {
457 atf_set "descr" "Tests that 'set -x' turns on command exec logging " \ 460 atf_set "descr" "Tests that 'set -x' turns on command exec logging " \
458 "and that it behaves as defined by the standard" 461 "and that it behaves as defined by the standard"
459} 462}
460set_x_body() { 463set_x_body() {
461 test_option_on_off x 464 test_option_on_off x
462 465
463 # check that cmd output appears after -x is enabled 466 # check that cmd output appears after -x is enabled
464 atf_check -s exit:0 \ 467 atf_check -s exit:0 \
465 -o match:OKOK -o not-match:echo -o not-match:printf \ 468 -o match:OKOK -o not-match:echo -o not-match:printf \
@@ -590,26 +593,29 @@ vi_emacs_VE_toggle_body() { @@ -590,26 +593,29 @@ vi_emacs_VE_toggle_body() {
590 set -V; q V E || x V E 593 set -V; q V E || x V E
591 set +EV; q "" "[VE]" || x "" VE 594 set +EV; q "" "[VE]" || x "" VE
592 exit 0 595 exit 0
593 ' 596 '
594} 597}
595 598
596atf_test_case xx_bogus 599atf_test_case xx_bogus
597xx_bogus_head() { 600xx_bogus_head() {
598 atf_set "descr" "Tests that attempting to set a nonsense option fails." 601 atf_set "descr" "Tests that attempting to set a nonsense option fails."
599} 602}
600xx_bogus_body() { 603xx_bogus_body() {
601 # Biggest problem here is picking a "nonsense option" that is 604 # Biggest problem here is picking a "nonsense option" that is
602 # not implemented by any shell, anywhere. Hopefully this will do. 605 # not implemented by any shell, anywhere. Hopefully this will do.
 606
 607 # 'set' is a special builtin, so a conforming shell should exit
 608 # on an arg error, and the ERR should not be printed.
603 atf_check -s not-exit:0 -o empty -e not-empty \ 609 atf_check -s not-exit:0 -o empty -e not-empty \
604 ${TEST_SH} -c 'set -% ; echo ERR' 610 ${TEST_SH} -c 'set -% ; echo ERR'
605} 611}
606 612
607atf_test_case Option_switching 613atf_test_case Option_switching
608Option_switching_head() { 614Option_switching_head() {
609 atf_set "descr" "options can be enabled and disabled" 615 atf_set "descr" "options can be enabled and disabled"
610} 616}
611Option_switching_body() { 617Option_switching_body() {
612 618
613 # Cannot test -m, setting it causes test shell to fail... 619 # Cannot test -m, setting it causes test shell to fail...
614 # (test shell gets SIGKILL!) Wonder why ... something related to atf 620 # (test shell gets SIGKILL!) Wonder why ... something related to atf
615 # That is, it works if just run as "sh -c 'echo $-; set -m; echo $-'" 621 # That is, it works if just run as "sh -c 'echo $-; set -m; echo $-'"