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 1PwCic-000876-D9 for garchives@archives.gentoo.org; Sun, 06 Mar 2011 12:05:50 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4A1311C050; Sun, 6 Mar 2011 12:05:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 0D5F81C050 for ; Sun, 6 Mar 2011 12:05:37 +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 7FF341B4094 for ; Sun, 6 Mar 2011 12:05:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id B73938006E for ; Sun, 6 Mar 2011 12:05:36 +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: <2a301b4b4181dd8bee647c5c2f1dfbcdba002087.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: src/, /, src/builtins/tests/, src/builtins/ X-VCS-Repository: proj/libbash X-VCS-Files: Makefile.am src/builtins/boolean_builtins.h src/builtins/tests/boolean_tests.cpp src/cppbash_builtin.cpp X-VCS-Directories: src/ / src/builtins/tests/ src/builtins/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 2a301b4b4181dd8bee647c5c2f1dfbcdba002087 Date: Sun, 6 Mar 2011 12:05:36 +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: 3911f086b318550fb0a6adf3ca7004cf commit: 2a301b4b4181dd8bee647c5c2f1dfbcdba002087 Author: Petteri R=C3=A4ty petteriraty eu> AuthorDate: Sun Aug 29 22:23:06 2010 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Sun Aug 29 22:27:57 2010 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D2a301b4b Implement true and false builtins Implementations of true and false builtins to see how much code implementing a very simple builtin takes. --- Makefile.am | 1 + .../boolean_builtins.h} | 29 +++++++-------= - src/builtins/tests/boolean_tests.cpp | 38 ++++++++++++++= ++++++ src/cppbash_builtin.cpp | 5 ++- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/Makefile.am b/Makefile.am index e66ceb2..33064bb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,6 +31,7 @@ TESTS +=3D builtin_unittests check_PROGRAMS =3D builtin_unittests builtin_unittests_SOURCES =3D src/builtins/tests/run_tests.cpp builtin_unittests_SOURCES +=3D src/builtins/tests/echo_tests.cpp +builtin_unittests_SOURCES +=3D src/builtins/tests/boolean_tests.cpp builtin_unittests_LDADD =3D ${GTEST_LIBS} libcppbash.la endif =20 diff --git a/src/cppbash_builtin.cpp b/src/builtins/boolean_builtins.h similarity index 53% copy from src/cppbash_builtin.cpp copy to src/builtins/boolean_builtins.h index ec6f683..b7afa12 100644 --- a/src/cppbash_builtin.cpp +++ b/src/builtins/boolean_builtins.h @@ -1,5 +1,5 @@ /* - Copyright 2010 Nathan Eloe + Copyright 2010 Petteri R=C3=A4ty =20 This file is part of libbash. =20 @@ -14,23 +14,22 @@ =20 You should have received a copy of the GNU General Public License along with libbash. If not, see . - */ +*/ /// -/// \file cppbash_builtin.cpp -/// \author Nathan Eloe -/// \brief Implementation of class to inherit builtins from +/// \file boolean_builtins.cpp +/// \brief implementations for the true and false builtins /// =20 -#include "cppbash_builtin.h" -#include "builtins/echo_builtin.h" +#include "../cppbash_builtin.h" =20 -cppbash_builtin::cppbash_builtin(std::ostream &outstream, std::ostream &= errstream, std::istream &instream): _out_stream(&outstream), _err_stream(= &errstream), _inp_stream(&instream) +struct true_builtin : public virtual cppbash_builtin { -} + BUILTIN_CONSTRUCTOR(true) + virtual int exec(const std::vector& bash_args) { return 0= ; } +}; =20 -cppbash_builtin::builtins_type& cppbash_builtin::builtins() { - static boost::scoped_ptr p(new builtins_type { - {"echo", boost::factory()} - }); - return *p; -} +struct false_builtin : public virtual cppbash_builtin +{ + BUILTIN_CONSTRUCTOR(false) + virtual int exec(const std::vector& bash_args) { return 1= ; } +}; diff --git a/src/builtins/tests/boolean_tests.cpp b/src/builtins/tests/bo= olean_tests.cpp new file mode 100644 index 0000000..ff65a9b --- /dev/null +++ b/src/builtins/tests/boolean_tests.cpp @@ -0,0 +1,38 @@ +/* +Copyright 2010 Petteri R=C3=A4ty + +This file is part of libbash. + +libbash is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +libbash is distributed in the hope that it will be useful,but WITHOUT AN= Y WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with libbash. If not, see . +*/ +/// +/// \file echo_tests.cpp +/// \brief series of unit tests for echo built in +/// +#include +#include "../../cppbash_builtin.h" +#include + +using namespace std; + +TEST(boolean_builtin_test, true) +{ + int result =3D cppbash_builtin::exec("true", {}, std::cout, std::cerr,= std::cin); + ASSERT_EQ(0, result); +} + +TEST(boolean_builtin_test, false) +{ + int result =3D cppbash_builtin::exec("false", {}, std::cout, std::cerr= , std::cin); + ASSERT_EQ(1, result); +} diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp index ec6f683..a486bd6 100644 --- a/src/cppbash_builtin.cpp +++ b/src/cppbash_builtin.cpp @@ -23,6 +23,7 @@ =20 #include "cppbash_builtin.h" #include "builtins/echo_builtin.h" +#include "builtins/boolean_builtins.h" =20 cppbash_builtin::cppbash_builtin(std::ostream &outstream, std::ostream &= errstream, std::istream &instream): _out_stream(&outstream), _err_stream(= &errstream), _inp_stream(&instream) { @@ -30,7 +31,9 @@ cppbash_builtin::cppbash_builtin(std::ostream &outstrea= m, std::ostream &errstrea =20 cppbash_builtin::builtins_type& cppbash_builtin::builtins() { static boost::scoped_ptr p(new builtins_type { - {"echo", boost::factory()} + {"echo", boost::factory()}, + {"true", boost::factory()}, + {"false", boost::factory()} }); return *p; }