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 1QPJyk-0004Bq-Tg 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 998811C20E; 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 57A171C1D5 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 DBE661BC016 for ; Wed, 25 May 2011 19:42:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 0E2118050C 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: <73c325c9569cbd890ec564bd5a9f7fab084c8e16.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/shopt_builtin.cpp src/builtins/shopt_builtin.h src/builtins/tests/shopt_tests.cpp X-VCS-Directories: src/builtins/tests/ src/builtins/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 73c325c9569cbd890ec564bd5a9f7fab084c8e16 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: 2c1f267e1b4a22a766ee6fbb632a8d6a commit: 73c325c9569cbd890ec564bd5a9f7fab084c8e16 Author: Mu Qiao gentoo org> AuthorDate: Wed May 25 08:39:12 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Wed May 25 10:13:53 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D73c325c9 Builtin: support shopt -s and -u --- src/builtins/shopt_builtin.cpp | 23 ++++++++++++++++------- src/builtins/shopt_builtin.h | 1 + src/builtins/tests/shopt_tests.cpp | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/builtins/shopt_builtin.cpp b/src/builtins/shopt_builtin.= cpp index 33ca3fc..9d60d74 100644 --- a/src/builtins/shopt_builtin.cpp +++ b/src/builtins/shopt_builtin.cpp @@ -22,20 +22,28 @@ /// \brief implementation for the shopt builtin /// =20 +#include "core/interpreter.h" #include "core/interpreter_exception.h" #include "cppbash_builtin.h" =20 #include "builtins/shopt_builtin.h" =20 -namespace +int shopt_builtin::set_opt(const std::vector& bash_args, bo= ol value) { - int disable_opt(const std::vector& bash_args) + int result =3D 0; + for(auto iter =3D bash_args.begin() + 1; iter !=3D bash_args.end(); ++= iter) { - auto iter =3D find(bash_args.begin() + 1, bash_args.end(), "extglob"= ); - if(iter !=3D bash_args.end()) - throw interpreter_exception("Disabling extglob is not allowed"); - return 0; + try + { + _walker.set_option(*iter, value); + } + catch(interpreter_exception& e) + { + std::cerr << *iter << " is not a valid bash option" << std::endl; + result =3D 1; + } } + return result; } =20 int shopt_builtin::exec(const std::vector& bash_args) @@ -54,8 +62,9 @@ int shopt_builtin::exec(const std::vector&= bash_args) switch(bash_args[0][1]) { case 'u': - return disable_opt(bash_args); + return set_opt(bash_args, false); case 's': + return set_opt(bash_args, true); case 'q': case 'o': *_err_stream << "shopt " << bash_args[0] << " is not supported yet= " << std::endl; diff --git a/src/builtins/shopt_builtin.h b/src/builtins/shopt_builtin.h index bd3291e..d274dc3 100644 --- a/src/builtins/shopt_builtin.h +++ b/src/builtins/shopt_builtin.h @@ -27,6 +27,7 @@ =20 class shopt_builtin : public virtual cppbash_builtin { + int set_opt(const std::vector& bash_args, bool value); public: BUILTIN_CONSTRUCTOR(shopt) virtual int exec(const std::vector& ); diff --git a/src/builtins/tests/shopt_tests.cpp b/src/builtins/tests/shop= t_tests.cpp index 5b4c45c..434555b 100644 --- a/src/builtins/tests/shopt_tests.cpp +++ b/src/builtins/tests/shopt_tests.cpp @@ -29,5 +29,20 @@ TEST(return_builtin_test, disable_extglob) { interpreter walker; - EXPECT_THROW(cppbash_builtin::exec("shopt", {"-u", "extglob"}, std::co= ut, std::cerr, std::cin, walker), interpreter_exception); + EXPECT_EQ(1, cppbash_builtin::exec("shopt", {"-u", "not exist"}, std::= cout, std::cerr, std::cin, walker)); + + walker.set_option("autocd", true); + EXPECT_EQ(0, cppbash_builtin::exec("shopt", {"-u", "autocd", "cdspell"= }, std::cout, std::cerr, std::cin, walker)); + EXPECT_FALSE(walker.get_option("autocd")); + EXPECT_FALSE(walker.get_option("cdspell")); +} + +TEST(return_builtin_test, enable_extglob) +{ + interpreter walker; + EXPECT_EQ(1, cppbash_builtin::exec("shopt", {"-s", "not exist"}, std::= cout, std::cerr, std::cin, walker)); + + EXPECT_EQ(0, cppbash_builtin::exec("shopt", {"-s", "autocd", "cdspell"= }, std::cout, std::cerr, std::cin, walker)); + EXPECT_TRUE(walker.get_option("autocd")); + EXPECT_TRUE(walker.get_option("cdspell")); }