From patchwork Thu May 30 14:21:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 32921 Received: (qmail 38437 invoked by alias); 30 May 2019 14:21:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 38369 invoked by uid 89); 30 May 2019 14:21:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=6066 X-HELO: mailsec108.isp.belgacom.be Received: from mailsec108.isp.belgacom.be (HELO mailsec108.isp.belgacom.be) (195.238.20.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 May 2019 14:21:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1559226082; x=1590762082; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UOmhGvU/WO02aHZbvSBdAONLEX04woumZJYMAWZ9zaM=; b=OAmezgyLrbxr1vdwCsj+uTCcGBfsEoufh/lhUPTM0uHBiGkeZoG1OsQs jtA6BWfJzfqq9/ZK331PfVFjvy734Q==; Received: from 161.32-242-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.242.32.161]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 30 May 2019 16:21:15 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv4 4/5] Test the | (pipe) command. Date: Thu, 30 May 2019 16:21:05 +0200 Message-Id: <20190530142106.25487-5-philippe.waroquiers@skynet.be> In-Reply-To: <20190530142106.25487-1-philippe.waroquiers@skynet.be> References: <20190530142106.25487-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes gdb/testsuite/ChangeLog 2019-05-30 Philippe Waroquiers * gdb.base/shell.exp: Test pipe command, $_shell_exitcode, $_shell_exitsignal. * gdb.base/default.exp: Update for new convenience variables. --- gdb/testsuite/gdb.base/default.exp | 2 + gdb/testsuite/gdb.base/shell.exp | 90 +++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp index 56ec917aa3..0325b8045d 100644 --- a/gdb/testsuite/gdb.base/default.exp +++ b/gdb/testsuite/gdb.base/default.exp @@ -606,6 +606,8 @@ set show_conv_list \ {$_isvoid = } \ {$_gdb_major = 8} \ {$_gdb_minor = 4} \ + {$_shell_exitsignal = void} \ + {$_shell_exitcode = 0} \ } if ![skip_python_tests] { append show_conv_list \ diff --git a/gdb/testsuite/gdb.base/shell.exp b/gdb/testsuite/gdb.base/shell.exp index 60d6e31e4f..375575b729 100644 --- a/gdb/testsuite/gdb.base/shell.exp +++ b/gdb/testsuite/gdb.base/shell.exp @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Test that the shell and ! commands work. +# Test that the "shell", "!", "|" and "pipe" commands work. gdb_exit gdb_start @@ -22,3 +22,91 @@ gdb_test "shell echo foo" "foo" gdb_test "! echo foo" "foo" gdb_test "!echo foo" "foo" + +# Convenience variables with shell command. +gdb_test_no_output "! exit 0" +gdb_test "p \$_shell_exitcode" " = 0" "shell success exitcode" +gdb_test "p \$_shell_exitsignal" " = void" "shell success exitsignal" + +gdb_test_no_output "! exit 1" +gdb_test "p \$_shell_exitcode" " = 1" "shell fail exitcode" +gdb_test "p \$_shell_exitsignal" " = void" "shell fail exitsignal" + +gdb_test_no_output "! kill -2 $$" +gdb_test "p \$_shell_exitcode" " = void" "shell interrupt exitcode" +gdb_test "p \$_shell_exitsignal" " = 2" "shell interrupt exitsignal" + +# Define the user command "foo", used to test "pipe" command. +gdb_test_multiple "define foo" "define foo" { + -re "End with" { + pass "define foo" + } +} +gdb_test \ + [multi_line_input \ + { echo coucou\n }\ + { echo truc\n }\ + { echo machin\n }\ + { if $argc > 0 }\ + { echo $arg0\n}\ + {end}\ + {end}] \ + "" \ + "enter commands" + + +gdb_test "pipe foo | wc -l" "3" "simple pipe" +gdb_test "pipe foo brol| wc -l" "4" "simple pipe with arg" +gdb_test "pipe foo truc2 | grep truc | wc -l" "2" "double pipe" + +gdb_test "| foo truc2 | grep truc | wc -l" "2" "double pipe, pipe char" +gdb_test "|foo|grep truc|wc -l" "1" "no space around pipe char" + +gdb_test "echo coucou\\n" "coucou" "echo coucou" +gdb_test "||wc -l" "1" "repeat previous command" + +gdb_test "| -d ! echo this contains a | character\\n ! sed -e 's/|/PIPE/'" \ + "this contains a PIPE character" "alternate 1char delim" + +gdb_test "|-d ! echo this contains a | character\\n!sed -e 's/|/PIPE/'" \ + "this contains a PIPE character" "alternate 1char delim, no space" + +gdb_test "| -d !!! echo this contains a | character\\n !!! sed -e 's/|/PIPE/'" \ + "this contains a PIPE character" "alternate 3char delim" + +gdb_test "|-d !!! echo this contains a | character\\n!!!sed -e 's/|/PIPE/'" \ + "this contains a PIPE character" "alternate 3char delim, no space" + +# Convenience variables with pipe command. +gdb_test "|p 123| exit 0" "" +gdb_test "p \$_shell_exitcode" " = 0" "pipe success exitcode" +gdb_test "p \$_shell_exitsignal" " = void" "pipe success exitsignal" + +gdb_test "|p 123| exit 1" "" +gdb_test "p \$_shell_exitcode" " = 1" "pipe fail exitcode" +gdb_test "p \$_shell_exitsignal" " = void" "pipe fail exitsignal" + +gdb_test "|p 123| kill -2 $$" "" +gdb_test "p \$_shell_exitcode" " = void" "pipe interrupt exitcode" +gdb_test "p \$_shell_exitsignal" " = 2" "pipe interrupt exitsignal" + +# Error handling verifications. +gdb_test "|" "Missing COMMAND" "all missing" +gdb_test "|-d" "Missing delimiter DELIM after -d" "-d value missing" +gdb_test "|-d " "Missing delimiter DELIM after -d" "-d spaces value missing" +gdb_test "| echo coucou" \ + "Missing delimiter before SHELL_COMMAND" \ + "| delimiter missing" +gdb_test "|-d DELIM echo coucou" \ + "Missing delimiter before SHELL_COMMAND" \ + "DELIM delimiter missing" +gdb_test "|echo coucou|" \ + "Missing SHELL_COMMAND" \ + "SHELL_COMMAND missing" +gdb_test "|-d ! echo coucou !" \ + "Missing SHELL_COMMAND" \ + "SHELL_COMMAND missing with delimiter" +gdb_test "|-d! echo coucou ! wc" \ + "Missing delimiter before SHELL_COMMAND" \ + "Delimiter missing due to missing space" +