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 1QPJyl-0004C1-Ng for garchives@archives.gentoo.org; Wed, 25 May 2011 19:42:51 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CAD921C1E5; Wed, 25 May 2011 19:42:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 8AFF11C1D5 for ; Wed, 25 May 2011 19:42:38 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1902A1B4032 for ; Wed, 25 May 2011 19:42:38 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 7716C80505 for ; Wed, 25 May 2011 19:42:37 +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: <811fd37b618ff770549e53ade07cfdd3afb0baab.betelgeuse@gentoo> 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: 811fd37b618ff770549e53ade07cfdd3afb0baab Date: Wed, 25 May 2011 19:42:37 +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: c4fa013396b89d4f7e415944d1f7980a commit: 811fd37b618ff770549e53ade07cfdd3afb0baab Author: Mu Qiao gentoo org> AuthorDate: Wed May 25 07:43:15 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed May 25 13:44:49 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D811fd37b Builtin: support declare -F and +F --- src/builtins/declare_builtin.cpp | 29 ++++++++++++++++++++++++++++= - src/builtins/tests/declare_tests.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/builtins/declare_builtin.cpp b/src/builtins/declare_buil= tin.cpp index 5d21bb3..90b127f 100644 --- a/src/builtins/declare_builtin.cpp +++ b/src/builtins/declare_builtin.cpp @@ -21,8 +21,11 @@ /// \author Mu Qiao /// \brief class that implements the declare builtin /// +#include #include =20 +#include "core/interpreter.h" + #include "builtins/declare_builtin.h" =20 int declare_builtin::exec(const std::vector& bash_args) @@ -44,12 +47,36 @@ int declare_builtin::exec(const std::vector& bash_args) return 1; } =20 + int result =3D 0; switch(bash_args[0][1]) { + case 'F': + if(bash_args[0][0] =3D=3D '+') + return 0; + if(bash_args.size() > 1) + { + for(auto iter =3D bash_args.begin() + 1; iter !=3D bash_args.end= (); ++iter) + { + if(_walker.has_function(*iter)) + *_out_stream << *iter << std::endl; + else + result =3D 1; + } + } + else + { + std::vector functions; + + _walker.get_all_function_names(functions); + sort(functions.begin(), functions.end()); + + for(auto iter =3D functions.begin(); iter !=3D functions.end(); = ++iter) + *_out_stream << "declare -f " << *iter << std::endl; + } + return result; case 'a': case 'A': case 'f': - case 'F': case 'i': case 'l': case 'r': diff --git a/src/builtins/tests/declare_tests.cpp b/src/builtins/tests/de= clare_tests.cpp index 925c5b9..21657dd 100644 --- a/src/builtins/tests/declare_tests.cpp +++ b/src/builtins/tests/declare_tests.cpp @@ -27,6 +27,7 @@ =20 #include =20 +#include "core/bash_ast.h" #include "core/interpreter.h" #include "cppbash_builtin.h" =20 @@ -40,13 +41,36 @@ static void test_declare(const string& expected, std:= :initializer_list a EXPECT_EQ(expected, test_output.str()); } =20 +TEST(declare_builtin_test, _F) +{ + stringstream expression("function foo() { :; }; function bar() { :; }"= ); + interpreter walker; + bash_ast ast(expression); + ast.interpret_with(walker); + + stringstream test_output1; + EXPECT_EQ(0, cppbash_builtin::exec("declare", {"-F", "foo"}, test_outp= ut1, cerr, cin, walker)); + EXPECT_EQ("foo\n", test_output1.str()); + + stringstream test_output2; + EXPECT_EQ(1, cppbash_builtin::exec("declare", {"-F", "foo", "bar", "te= st"}, test_output2, cerr, cin, walker)); + EXPECT_EQ("foo\nbar\n", test_output2.str()); + + stringstream test_output3; + EXPECT_EQ(0, cppbash_builtin::exec("declare", {"+F", "foo", "bar", "te= st"}, test_output3, cerr, cin, walker)); + EXPECT_EQ("", test_output3.str()); + + stringstream test_output4; + EXPECT_EQ(0, cppbash_builtin::exec("declare", {"-F"}, test_output3, ce= rr, cin, walker)); + EXPECT_EQ("declare -f bar\ndeclare -f foo\n", test_output3.str()); +} + #define TEST_DECLARE(name, expected, ...) \ TEST(declare_builtin_test, name) { test_declare(expected, {__VA_ARGS__}= ); } =20 TEST_DECLARE(_a, "declare -a is not supported yet\n", "-a", "world") TEST_DECLARE(_A, "declare -A is not supported yet\n", "-A", "world") TEST_DECLARE(_f, "declare -f is not supported yet\n", "-f", "world") -TEST_DECLARE(_F, "declare -F is not supported yet\n", "-F", "world") TEST_DECLARE(_i, "declare -i is not supported yet\n", "-i", "world") TEST_DECLARE(_l, "declare -l is not supported yet\n", "-l", "world") TEST_DECLARE(_r, "declare -r is not supported yet\n", "-r", "world") @@ -57,7 +81,6 @@ 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") -TEST_DECLARE(pF, "declare +F is not supported yet\n", "+F", "world") TEST_DECLARE(pi, "declare +i is not supported yet\n", "+i", "world") TEST_DECLARE(pl, "declare +l is not supported yet\n", "+l", "world") TEST_DECLARE(pr, "declare +r is not supported yet\n", "+r", "world")