public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: src/, /, src/builtins/tests/, src/builtins/
Date: Sun,  6 Mar 2011 12:05:36 +0000 (UTC)	[thread overview]
Message-ID: <2a301b4b4181dd8bee647c5c2f1dfbcdba002087.betelgeuse@gentoo> (raw)

commit:     2a301b4b4181dd8bee647c5c2f1dfbcdba002087
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sun Aug 29 22:23:06 2010 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sun Aug 29 22:27:57 2010 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2a301b4b

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 += builtin_unittests
 check_PROGRAMS = builtin_unittests
 builtin_unittests_SOURCES = src/builtins/tests/run_tests.cpp
 builtin_unittests_SOURCES += src/builtins/tests/echo_tests.cpp
+builtin_unittests_SOURCES += src/builtins/tests/boolean_tests.cpp
 builtin_unittests_LDADD = ${GTEST_LIBS} libcppbash.la
 endif
 

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äty
 
    This file is part of libbash.
 
@@ -14,23 +14,22 @@
 
    You should have received a copy of the GNU General Public License
    along with libbash.  If not, see <http://www.gnu.org/licenses/>.
-   */
+*/
 ///
-/// \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
 ///
 
-#include "cppbash_builtin.h"
-#include "builtins/echo_builtin.h"
+#include "../cppbash_builtin.h"
 
-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<std::string>& bash_args) { return 0; }
+};
 
-cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
-  static boost::scoped_ptr<builtins_type> p(new builtins_type {
-      {"echo", boost::factory<echo_builtin*>()}
-  });
-  return *p;
-}
+struct false_builtin : public virtual cppbash_builtin
+{
+  BUILTIN_CONSTRUCTOR(false)
+  virtual int exec(const std::vector<std::string>& bash_args) { return 1; }
+};

diff --git a/src/builtins/tests/boolean_tests.cpp b/src/builtins/tests/boolean_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äty
+
+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 ANY 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 <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file echo_tests.cpp
+/// \brief series of unit tests for echo built in
+///
+#include <iostream>
+#include "../../cppbash_builtin.h"
+#include <gtest/gtest.h>
+
+using namespace std;
+
+TEST(boolean_builtin_test, true)
+{
+  int result = cppbash_builtin::exec("true", {}, std::cout, std::cerr, std::cin);
+  ASSERT_EQ(0, result);
+}
+
+TEST(boolean_builtin_test, false)
+{
+  int result = 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 @@
 
 #include "cppbash_builtin.h"
 #include "builtins/echo_builtin.h"
+#include "builtins/boolean_builtins.h"
 
 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 &outstream, std::ostream &errstrea
 
 cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
   static boost::scoped_ptr<builtins_type> p(new builtins_type {
-      {"echo", boost::factory<echo_builtin*>()}
+      {"echo", boost::factory<echo_builtin*>()},
+      {"true", boost::factory<true_builtin*>()},
+      {"false", boost::factory<false_builtin*>()}
   });
   return *p;
 }



             reply	other threads:[~2011-03-06 12:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-06 12:05 Petteri Räty [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-03-06 12:05 [gentoo-commits] proj/libbash:master commit in: src/, /, src/builtins/tests/, src/builtins/ Petteri Räty
2011-05-24 14:50 Petteri Räty
2011-05-25 19:42 Petteri Räty
2011-05-29 11:20 Petteri Räty
2011-06-25 10:05 Petteri Räty
2012-07-08  9:31 Petteri Räty
2012-07-08  9:31 Petteri Räty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a301b4b4181dd8bee647c5c2f1dfbcdba002087.betelgeuse@gentoo \
    --to=betelgeuse@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox