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 1QFKa7-0003ai-NI for garchives@archives.gentoo.org; Thu, 28 Apr 2011 06:20:07 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B7D651C04B; Thu, 28 Apr 2011 06:19:55 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 70D721C04B for ; Thu, 28 Apr 2011 06:19:55 +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 E4C2D2AC01B for ; Thu, 28 Apr 2011 06:19:54 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 101068050B for ; Thu, 28 Apr 2011 06:19:54 +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: <1ef836789621c8dafcd1bf7601f5050bbfc89e89.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, src/builtins/tests/, src/builtins/ X-VCS-Repository: proj/libbash X-VCS-Files: Makefile.am scripts/source_false.sh scripts/source_true.sh src/builtins/source_builtin.cpp src/builtins/source_builtin.h src/builtins/tests/source_tests.cpp src/cppbash_builtin.cpp X-VCS-Directories: src/ scripts/ / src/builtins/tests/ src/builtins/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 1ef836789621c8dafcd1bf7601f5050bbfc89e89 Date: Thu, 28 Apr 2011 06:19:54 +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: c35346fb576a5079fa716988b75f3319 commit: 1ef836789621c8dafcd1bf7601f5050bbfc89e89 Author: Mu Qiao gentoo org> AuthorDate: Thu Apr 21 13:20:15 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Thu Apr 28 03:09:02 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D1ef83678 Builtin: implement source builtin --- Makefile.am | 5 +++ scripts/source_false.sh | 1 + scripts/source_true.sh | 5 +++ .../source_builtin.cpp} | 38 ++++++++++++--= ----- .../source_builtin.h} | 39 ++++++++++++--= ------ .../tests/source_tests.cpp} | 35 +++++++++++---= ---- src/cppbash_builtin.cpp | 2 + 7 files changed, 81 insertions(+), 44 deletions(-) diff --git a/Makefile.am b/Makefile.am index aefcf51..5518599 100644 --- a/Makefile.am +++ b/Makefile.am @@ -101,6 +101,7 @@ cppunittests_SOURCES =3D test/run_tests.cpp \ src/core/tests/interpreter_test.cpp \ src/builtins/tests/echo_tests.cpp \ src/builtins/tests/boolean_tests.cpp \ + src/builtins/tests/source_tests.cpp \ test/post_check.cpp \ test/api_test.cpp \ test/walker_test.cpp @@ -158,6 +159,8 @@ libcppbash_la_SOURCES =3D src/common.h \ src/builtins/echo_builtin.cpp \ src/builtins/echo_builtin.h \ src/builtins/boolean_builtins.h \ + src/builtins/source_builtin.h \ + src/builtins/source_builtin.cpp \ $(GENERATED_PARSER_C) \ $(GENERATED_PARSER_H) \ src/core/interpreter_exception.h \ @@ -182,6 +185,8 @@ EXTRA_DIST =3D bashast/bashast.g \ bashast/features_script/features.sh.tokens \ test/ast_printer_test.sh \ test/verify_bashs_test.sh \ + scripts/source_false.sh \ + scripts/source_true.sh \ utils/meta_gen.sh \ $(BASH_TESTS) \ $(BASH_RESULT) \ diff --git a/scripts/source_false.sh b/scripts/source_false.sh new file mode 100644 index 0000000..c508d53 --- /dev/null +++ b/scripts/source_false.sh @@ -0,0 +1 @@ +false diff --git a/scripts/source_true.sh b/scripts/source_true.sh new file mode 100644 index 0000000..ceb5c3f --- /dev/null +++ b/scripts/source_true.sh @@ -0,0 +1,5 @@ +FOO001=3Dhello +function foo() +{ + : +} diff --git a/src/cppbash_builtin.cpp b/src/builtins/source_builtin.cpp similarity index 50% copy from src/cppbash_builtin.cpp copy to src/builtins/source_builtin.cpp index 38a6111..d2b4bcb 100644 --- a/src/cppbash_builtin.cpp +++ b/src/builtins/source_builtin.cpp @@ -17,24 +17,34 @@ along with libbash. If not, see . */ /// -/// \file cppbash_builtin.cpp -/// \author Nathan Eloe -/// \brief Implementation of class to inherit builtins from +/// \file source_builtin.h +/// \author Mu Qiao +/// \brief class that implements the source builtin /// =20 +#include "builtins/source_builtin.h" + +#include +#include + #include "cppbash_builtin.h" -#include "builtins/echo_builtin.h" -#include "builtins/boolean_builtins.h" +#include "core/interpreter.h" +#include "core/interpreter_exception.h" +#include "core/bash_ast.h" =20 -cppbash_builtin::cppbash_builtin(BUILTIN_ARGS): _out_stream(&out), _err_= stream(&err), _inp_stream(&in), _walker(walker) +int source_builtin::exec(const std::vector& bash_args) { -} + if(bash_args.size() =3D=3D 0) + throw interpreter_exception("should provide one argument for source = builtin"); + + // we need fix this to pass extra arguments as positional parameters + const std::string& path =3D bash_args[0]; + std::ifstream input(path); + if(!input) + throw interpreter_exception(path + " can't be read"); + + bash_ast ast(input); + ast.interpret_with(_walker); =20 -cppbash_builtin::builtins_type& cppbash_builtin::builtins() { - static boost::scoped_ptr p(new builtins_type { - {"echo", boost::factory()}, - {"true", boost::factory()}, - {"false", boost::factory()} - }); - return *p; + return _walker.get_status(); } diff --git a/src/cppbash_builtin.cpp b/src/builtins/source_builtin.h similarity index 55% copy from src/cppbash_builtin.cpp copy to src/builtins/source_builtin.h index 38a6111..964d214 100644 --- a/src/cppbash_builtin.cpp +++ b/src/builtins/source_builtin.h @@ -17,24 +17,31 @@ along with libbash. If not, see . */ /// -/// \file cppbash_builtin.cpp -/// \author Nathan Eloe -/// \brief Implementation of class to inherit builtins from +/// \file source_builtin.h +/// \author Mu Qiao +/// \brief class that implements the source builtin /// =20 +#ifndef LIBBASH_BUILTINS_SOURCE_BUILTIN_H_ +#define LIBBASH_BUILTINS_SOURCE_BUILTIN_H_ + #include "cppbash_builtin.h" -#include "builtins/echo_builtin.h" -#include "builtins/boolean_builtins.h" =20 -cppbash_builtin::cppbash_builtin(BUILTIN_ARGS): _out_stream(&out), _err_= stream(&err), _inp_stream(&in), _walker(walker) +/// +/// \class source_builtin +/// \brief the source builtin for bash +/// +class source_builtin: public virtual cppbash_builtin { -} - -cppbash_builtin::builtins_type& cppbash_builtin::builtins() { - static boost::scoped_ptr p(new builtins_type { - {"echo", boost::factory()}, - {"true", boost::factory()}, - {"false", boost::factory()} - }); - return *p; -} + public: + BUILTIN_CONSTRUCTOR(source) + + /// + /// \brief runs the source builtin on the supplied arguments + /// \param bash_args the arguments to the source builtin + /// \return exit status of source + /// + virtual int exec(const std::vector& bash_args); +}; + +#endif diff --git a/src/cppbash_builtin.cpp b/src/builtins/tests/source_tests.cp= p similarity index 51% copy from src/cppbash_builtin.cpp copy to src/builtins/tests/source_tests.cpp index 38a6111..ac0fd3c 100644 --- a/src/cppbash_builtin.cpp +++ b/src/builtins/tests/source_tests.cpp @@ -17,24 +17,31 @@ along with libbash. If not, see . */ /// -/// \file cppbash_builtin.cpp -/// \author Nathan Eloe -/// \brief Implementation of class to inherit builtins from +/// \file source_tests.cpp +/// \brief series of unit tests for source built in /// =20 +#include + +#include +#include + +#include + +#include "core/interpreter.h" #include "cppbash_builtin.h" -#include "builtins/echo_builtin.h" -#include "builtins/boolean_builtins.h" =20 -cppbash_builtin::cppbash_builtin(BUILTIN_ARGS): _out_stream(&out), _err_= stream(&err), _inp_stream(&in), _walker(walker) +using namespace std; + +TEST(source_builtin_test, source) { -} + std::string srcdir(getenv("srcdir")); + interpreter walker; + int status =3D cppbash_builtin::exec("source", {srcdir + "/scripts/sou= rce_true.sh"}, std::cout, std::cerr, std::cin, walker); + EXPECT_EQ(status, 0); + EXPECT_TRUE(walker.has_function("foo")); + EXPECT_STREQ("hello", walker.resolve("FOO001").c_str()); =20 -cppbash_builtin::builtins_type& cppbash_builtin::builtins() { - static boost::scoped_ptr p(new builtins_type { - {"echo", boost::factory()}, - {"true", boost::factory()}, - {"false", boost::factory()} - }); - return *p; + status =3D cppbash_builtin::exec("source", {srcdir + "/scripts/source_= false.sh"}, std::cout, std::cerr, std::cin, walker); + EXPECT_EQ(status, 1); } diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp index 38a6111..0df9cbf 100644 --- a/src/cppbash_builtin.cpp +++ b/src/cppbash_builtin.cpp @@ -25,6 +25,7 @@ #include "cppbash_builtin.h" #include "builtins/echo_builtin.h" #include "builtins/boolean_builtins.h" +#include "builtins/source_builtin.h" =20 cppbash_builtin::cppbash_builtin(BUILTIN_ARGS): _out_stream(&out), _err_= stream(&err), _inp_stream(&in), _walker(walker) { @@ -33,6 +34,7 @@ cppbash_builtin::cppbash_builtin(BUILTIN_ARGS): _out_st= ream(&out), _err_stream(& cppbash_builtin::builtins_type& cppbash_builtin::builtins() { static boost::scoped_ptr p(new builtins_type { {"echo", boost::factory()}, + {"source", boost::factory()}, {"true", boost::factory()}, {"false", boost::factory()} });