| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: t_cmdsub.sh,v 1.2 2016/03/27 14:53:17 christos Exp $ | | 1 | # $NetBSD: t_cmdsub.sh,v 1.3 2016/03/31 16:20:39 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 | # |
| @@ -509,26 +509,136 @@ u_nested_backticks_in_heredoc_body() { | | | @@ -509,26 +509,136 @@ u_nested_backticks_in_heredoc_body() { |
509 | `V=\`cat File\`; echo "${V%lo}p" ` me! | | 509 | `V=\`cat File\`; echo "${V%lo}p" ` me! |
510 | EOF' | | 510 | EOF' |
511 | | | 511 | |
512 | rm -f * 2>/dev/null || : | | 512 | rm -f * 2>/dev/null || : |
513 | echo V>V ; echo A>A; echo R>R | | 513 | echo V>V ; echo A>A; echo R>R |
514 | echo Value>VAR | | 514 | echo Value>VAR |
515 | | | 515 | |
516 | atf_check -s exit:0 -o inline:'$5.20\n' -e empty \ | | 516 | atf_check -s exit:0 -o inline:'$5.20\n' -e empty \ |
517 | ${TEST_SH} -c 'cat <<- EOF | | 517 | ${TEST_SH} -c 'cat <<- EOF |
518 | `Value='\''$5.20'\'';eval echo \`eval \\\`cat V\\\`\\\`cat A\\\`\\\`cat R\\\`=\\\'\''\\\$\\\`cat \\\\\\\`cat V\\\\\\\`\\\\\\\`cat A\\\\\\\`\\\\\\\`cat R\\\\\\\`\\\`\\\'\''; eval echo \\\$\\\`set -- *;echo \\\\\${3}\\\\\${1}\\\\\${2}\\\`\`` | | 518 | `Value='\''$5.20'\'';eval echo \`eval \\\`cat V\\\`\\\`cat A\\\`\\\`cat R\\\`=\\\'\''\\\$\\\`cat \\\\\\\`cat V\\\\\\\`\\\\\\\`cat A\\\\\\\`\\\\\\\`cat R\\\\\\\`\\\`\\\'\''; eval echo \\\$\\\`set -- *;echo \\\\\${3}\\\\\${1}\\\\\${2}\\\`\`` |
519 | EOF' | | 519 | EOF' |
520 | } | | 520 | } |
521 | | | 521 | |
| | | 522 | atf_test_case v_cmdsub_paren_tests |
| | | 523 | v_cmdsub__paren_tests_head() { |
| | | 524 | atf_set "descr" "tests with cmdsubs containing embedded ')'" |
| | | 525 | } |
| | | 526 | v_cmdsub_paren_tests_body() { |
| | | 527 | |
| | | 528 | # Tests from: |
| | | 529 | # http://www.in-ulm.de/~mascheck/various/cmd-subst/ |
| | | 530 | # (slightly modified.) |
| | | 531 | |
| | | 532 | atf_check -s exit:0 -o inline:'A.1\n' -e empty ${TEST_SH} -c \ |
| | | 533 | 'echo $( |
| | | 534 | case x in x) echo A.1;; esac |
| | | 535 | )' |
| | | 536 | |
| | | 537 | atf_check -s exit:0 -o inline:'A.2\n' -e empty ${TEST_SH} -c \ |
| | | 538 | 'echo $( |
| | | 539 | case x in x) echo A.2;; esac # comment |
| | | 540 | )' |
| | | 541 | |
| | | 542 | atf_check -s exit:0 -o inline:'A.3\n' -e empty ${TEST_SH} -c \ |
| | | 543 | 'echo $( |
| | | 544 | case x in (x) echo A.3;; esac |
| | | 545 | )' |
| | | 546 | |
| | | 547 | atf_check -s exit:0 -o inline:'A.4\n' -e empty ${TEST_SH} -c \ |
| | | 548 | 'echo $( |
| | | 549 | case x in (x) echo A.4;; esac # comment |
| | | 550 | )' |
| | | 551 | |
| | | 552 | atf_check -s exit:0 -o inline:'A.5\n' -e empty ${TEST_SH} -c \ |
| | | 553 | 'echo $( |
| | | 554 | case x in (x) echo A.5 |
| | | 555 | esac |
| | | 556 | )' |
| | | 557 | |
| | | 558 | atf_check -s exit:0 -o inline:'B: quoted )\n' -e empty ${TEST_SH} -c \ |
| | | 559 | 'echo $( |
| | | 560 | echo '\''B: quoted )'\'' |
| | | 561 | )' |
| | | 562 | |
| | | 563 | atf_check -s exit:0 -o inline:'C: comment then closing paren\n' \ |
| | | 564 | -e empty ${TEST_SH} -c \ |
| | | 565 | 'echo $( |
| | | 566 | echo C: comment then closing paren # ) |
| | | 567 | )' |
| | | 568 | |
| | | 569 | atf_check -s exit:0 -o inline:'D.1: here-doc with )\n' \ |
| | | 570 | -e empty ${TEST_SH} -c \ |
| | | 571 | 'echo $( |
| | | 572 | cat <<-\eof |
| | | 573 | D.1: here-doc with ) |
| | | 574 | eof |
| | | 575 | )' |
| | | 576 | |
| | | 577 | # D.2 is a bogus test. |
| | | 578 | |
| | | 579 | atf_check -s exit:0 -o inline:'D.3: here-doc with \()\n' \ |
| | | 580 | -e empty ${TEST_SH} -c \ |
| | | 581 | 'echo $( |
| | | 582 | cat <<-\eof |
| | | 583 | D.3: here-doc with \() |
| | | 584 | eof |
| | | 585 | )' |
| | | 586 | |
| | | 587 | atf_check -s exit:0 -e empty \ |
| | | 588 | -o inline:'E: here-doc terminated with a parenthesis ("academic")\n' \ |
| | | 589 | ${TEST_SH} -c \ |
| | | 590 | 'echo $( |
| | | 591 | cat <<-\) |
| | | 592 | E: here-doc terminated with a parenthesis ("academic") |
| | | 593 | ) |
| | | 594 | )' |
| | | 595 | |
| | | 596 | atf_check -s exit:0 -e empty \ |
| | | 597 | -o inline:'F.1: here-doc embed with unbal single, back- or doublequote '\''\n' \ |
| | | 598 | ${TEST_SH} -c \ |
| | | 599 | 'echo $( |
| | | 600 | cat <<-"eof" |
| | | 601 | F.1: here-doc embed with unbal single, back- or doublequote '\'' |
| | | 602 | eof |
| | | 603 | )' |
| | | 604 | atf_check -s exit:0 -e empty \ |
| | | 605 | -o inline:'F.2: here-doc embed with unbal single, back- or doublequote "\n' \ |
| | | 606 | ${TEST_SH} -c \ |
| | | 607 | 'echo $( |
| | | 608 | cat <<-"eof" |
| | | 609 | F.2: here-doc embed with unbal single, back- or doublequote " |
| | | 610 | eof |
| | | 611 | )' |
| | | 612 | atf_check -s exit:0 -e empty \ |
| | | 613 | -o inline:'F.3: here-doc embed with unbal single, back- or doublequote `\n' \ |
| | | 614 | ${TEST_SH} -c \ |
| | | 615 | 'echo $( |
| | | 616 | cat <<-"eof" |
| | | 617 | F.3: here-doc embed with unbal single, back- or doublequote ` |
| | | 618 | eof |
| | | 619 | )' |
| | | 620 | |
| | | 621 | atf_check -s exit:0 -e empty -o inline:'G: backslash at end of line\n' \ |
| | | 622 | ${TEST_SH} -c \ |
| | | 623 | 'echo $( |
| | | 624 | echo G: backslash at end of line # \ |
| | | 625 | )' |
| | | 626 | |
| | | 627 | atf_check -s exit:0 -e empty \ |
| | | 628 | -o inline:'H: empty command-substitution\n' \ |
| | | 629 | ${TEST_SH} -c 'echo H: empty command-substitution $( )' |
| | | 630 | } |
| | | 631 | |
522 | atf_test_case z_absurd_heredoc_cmdsub_combos | | 632 | atf_test_case z_absurd_heredoc_cmdsub_combos |
523 | z_absurd_heredoc_cmdsub_combos_head() { | | 633 | z_absurd_heredoc_cmdsub_combos_head() { |
524 | atf_set "descr" "perverse and unusual cmd substitutions & more" | | 634 | atf_set "descr" "perverse and unusual cmd substitutions & more" |
525 | } | | 635 | } |
526 | z_absurd_heredoc_cmdsub_combos_body() { | | 636 | z_absurd_heredoc_cmdsub_combos_body() { |
527 | | | 637 | |
528 | echo "Help!" > help | | 638 | echo "Help!" > help |
529 | | | 639 | |
530 | # This version works in NetBSD (& FreeBSD)'s sh (and most others) | | 640 | # This version works in NetBSD (& FreeBSD)'s sh (and most others) |
531 | atf_check -s exit:0 -o inline:'Help!\nMe 2\n' -e empty ${TEST_SH} -c ' | | 641 | atf_check -s exit:0 -o inline:'Help!\nMe 2\n' -e empty ${TEST_SH} -c ' |
532 | cat <<- EOF | | 642 | cat <<- EOF |
533 | $( | | 643 | $( |
534 | cat <<- STOP | | 644 | cat <<- STOP |
| @@ -580,15 +690,16 @@ atf_init_test_cases() { | | | @@ -580,15 +690,16 @@ atf_init_test_cases() { |
580 | atf_add_test_case i_vars_in_backticks | | 690 | atf_add_test_case i_vars_in_backticks |
581 | atf_add_test_case j_cmdsub_in_varexpand | | 691 | atf_add_test_case j_cmdsub_in_varexpand |
582 | atf_add_test_case k_backticks_in_varexpand | | 692 | atf_add_test_case k_backticks_in_varexpand |
583 | atf_add_test_case l_arithmetic_in_cmdsub | | 693 | atf_add_test_case l_arithmetic_in_cmdsub |
584 | atf_add_test_case m_arithmetic_in_backticks | | 694 | atf_add_test_case m_arithmetic_in_backticks |
585 | atf_add_test_case n_cmdsub_in_arithmetic | | 695 | atf_add_test_case n_cmdsub_in_arithmetic |
586 | atf_add_test_case o_backticks_in_arithmetic | | 696 | atf_add_test_case o_backticks_in_arithmetic |
587 | atf_add_test_case p_cmdsub_in_heredoc | | 697 | atf_add_test_case p_cmdsub_in_heredoc |
588 | atf_add_test_case q_backticks_in_heredoc | | 698 | atf_add_test_case q_backticks_in_heredoc |
589 | atf_add_test_case r_heredoc_in_cmdsub | | 699 | atf_add_test_case r_heredoc_in_cmdsub |
590 | atf_add_test_case s_heredoc_in_backticks | | 700 | atf_add_test_case s_heredoc_in_backticks |
591 | atf_add_test_case t_nested_cmdsubs_in_heredoc | | 701 | atf_add_test_case t_nested_cmdsubs_in_heredoc |
592 | atf_add_test_case u_nested_backticks_in_heredoc | | 702 | atf_add_test_case u_nested_backticks_in_heredoc |
| | | 703 | atf_add_test_case v_cmdsub_paren_tests |
593 | atf_add_test_case z_absurd_heredoc_cmdsub_combos | | 704 | atf_add_test_case z_absurd_heredoc_cmdsub_combos |
594 | } | | 705 | } |