From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QUZeD-0007ms-2P for garchives@archives.gentoo.org; Thu, 09 Jun 2011 07:27:21 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EDA861C074; Thu, 9 Jun 2011 07:27:08 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id AE1251C074 for ; Thu, 9 Jun 2011 07:27:08 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 358BD1B4028 for ; Thu, 9 Jun 2011 07:27:08 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 2186C80048 for ; Thu, 9 Jun 2011 07:27:07 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: Subject: [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/ X-VCS-Repository: proj/libbash X-VCS-Files: src/builtins/declare_builtin.cpp src/builtins/tests/declare_tests.cpp X-VCS-Directories: src/builtins/tests/ src/builtins/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: aba5408ad36445b170ba5e7519e49ff245bda322 Date: Thu, 9 Jun 2011 07:27:07 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 7eb4bfc990124f2ef1500ffdeabee7d6 commit: aba5408ad36445b170ba5e7519e49ff245bda322 Author: Mu Qiao gentoo org> AuthorDate: Wed Jun 8 13:01:50 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Thu Jun 9 07:23:33 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3Daba5408a Builtin: support declare -p vars We do not support declare -p without arguments for now. --- src/builtins/declare_builtin.cpp | 23 ++++++++++++++++++++++- src/builtins/tests/declare_tests.cpp | 15 ++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/builtins/declare_builtin.cpp b/src/builtins/declare_buil= tin.cpp index 3ee9def..cccbb9d 100644 --- a/src/builtins/declare_builtin.cpp +++ b/src/builtins/declare_builtin.cpp @@ -73,6 +73,28 @@ int declare_builtin::exec(const std::vector& bash_args) *_out_stream << "declare -f " << *iter << std::endl; } return result; + case 'p': + if(bash_args.size() > 1) + { + for(auto iter =3D bash_args.begin() + 1; iter !=3D bash_args.end= (); ++iter) + { + // We do not print the type of the variable for now + if(!_walker.is_unset(*iter)) + { + *_out_stream << "declare -- " << *iter << "=3D\"" << _walker= .resolve(*iter) << "\"" << std::endl; + } + else + { + *_out_stream << "-bash: declare: " << *iter << ": not found"= << std::endl; + result =3D 1; + } + } + } + else + { + throw interpreter_exception("We do not support declare -p withou= t arguments for now"); + } + return result; case 'a': case 'A': case 'f': @@ -82,7 +104,6 @@ int declare_builtin::exec(const std::vector& bash_args) case 't': case 'u': case 'x': - case 'p': *_err_stream << "declare " << bash_args[0] << " is not supported y= et" << std::endl; return 1; default: diff --git a/src/builtins/tests/declare_tests.cpp b/src/builtins/tests/de= clare_tests.cpp index 95c0949..2bedfd3 100644 --- a/src/builtins/tests/declare_tests.cpp +++ b/src/builtins/tests/declare_tests.cpp @@ -72,6 +72,20 @@ TEST(declare_builtin_test, _F) EXPECT_EQ("declare -f bar\ndeclare -f foo\n", test_output3.str()); } =20 +TEST(declare_built_test, _p) +{ + interpreter walker; + walker.define("foo", "bar"); + + stringstream test_output1; + EXPECT_EQ(0, cppbash_builtin::exec("declare", {"-p", "foo"}, test_outp= ut1, cerr, cin, walker)); + EXPECT_EQ("declare -- foo=3D\"bar\"\n", test_output1.str()); + + stringstream test_output2; + EXPECT_EQ(1, cppbash_builtin::exec("declare", {"-p", "bar", "test"}, t= est_output2, cerr, cin, walker)); + EXPECT_EQ("-bash: declare: bar: not found\n-bash: declare: test: not f= ound\n", test_output2.str()); +} + #define TEST_DECLARE(name, expected, ...) \ TEST(declare_builtin_test, name) { test_declare(expected, {__VA_ARGS__}= ); } =20 @@ -84,7 +98,6 @@ TEST_DECLARE(_r, "declare -r is not supported yet\n", "= -r", "world") TEST_DECLARE(_t, "declare -t is not supported yet\n", "-t", "world") TEST_DECLARE(_u, "declare -u is not supported yet\n", "-u", "world") TEST_DECLARE(_x, "declare -x is not supported yet\n", "-x", "world") -TEST_DECLARE(_p, "declare -p is not supported yet\n", "-p", "world") TEST_DECLARE(pa, "declare +a is not supported yet\n", "+a", "world") TEST_DECLARE(pA, "declare +A is not supported yet\n", "+A", "world") TEST_DECLARE(pf, "declare +f is not supported yet\n", "+f", "world")