From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/
Date: Sat, 25 Jun 2011 10:05:49 +0000 (UTC) [thread overview]
Message-ID: <3016ad21687f5eb9f88c0e159536c4bfc23bfbd1.betelgeuse@gentoo> (raw)
commit: 3016ad21687f5eb9f88c0e159536c4bfc23bfbd1
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 22 15:01:11 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jun 22 15:07:30 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3016ad21
Builtin: make declare built-in throw exceptions
---
src/builtins/declare_builtin.cpp | 11 +++--
src/builtins/tests/declare_tests.cpp | 70 ++++++++++++++++++++--------------
2 files changed, 47 insertions(+), 34 deletions(-)
diff --git a/src/builtins/declare_builtin.cpp b/src/builtins/declare_builtin.cpp
index 412b9ba..2644bb7 100644
--- a/src/builtins/declare_builtin.cpp
+++ b/src/builtins/declare_builtin.cpp
@@ -25,24 +25,25 @@
#include <algorithm>
#include <iostream>
+#include "core/exceptions.h"
#include "core/interpreter.h"
int declare_builtin::exec(const std::vector<std::string>& bash_args)
{
if(bash_args.empty())
{
- *_err_stream << "Arguments required for declare" << std::endl;
+ throw libbash::illegal_argument_exception("Arguments required for declare");
return 1;
}
else if(bash_args[0].size() != 2)
{
- *_err_stream << "Multiple arguments are not supported" << std::endl;
+ throw libbash::unsupported_exception("Multiple arguments are not supported");
return 1;
}
if(bash_args[0][0] != '-' && bash_args[0][0] != '+')
{
- *_err_stream << "Invalid option for declare builtin" << std::endl;
+ throw libbash::illegal_argument_exception("Invalid option for declare builtin");
return 1;
}
@@ -104,10 +105,10 @@ int declare_builtin::exec(const std::vector<std::string>& bash_args)
case 't':
case 'u':
case 'x':
- *_err_stream << "declare " << bash_args[0] << " is not supported yet" << std::endl;
+ throw libbash::unsupported_exception("declare " + bash_args[0] + " is not supported yet");
return 1;
default:
- *_err_stream << "Unrecognized option for declare: " << bash_args[0] << std::endl;
+ throw libbash::illegal_argument_exception("Unrecognized option for declare: " + bash_args[0]);
return 1;
}
}
diff --git a/src/builtins/tests/declare_tests.cpp b/src/builtins/tests/declare_tests.cpp
index 2bedfd3..95f4b61 100644
--- a/src/builtins/tests/declare_tests.cpp
+++ b/src/builtins/tests/declare_tests.cpp
@@ -27,25 +27,37 @@
#include <gtest/gtest.h>
#include "core/bash_ast.h"
+#include "core/exceptions.h"
#include "core/interpreter.h"
#include "cppbash_builtin.h"
using namespace std;
-static void test_declare(const string& expected, std::initializer_list<string> args)
+namespace
{
- stringstream test_output;
- interpreter walker;
- cppbash_builtin::exec("declare",args,cout,test_output,cin,walker);
- EXPECT_EQ(expected, test_output.str());
+ template <typename T>
+ void test_declare(const string& expected, std::initializer_list<string> args)
+ {
+ stringstream test_output;
+ interpreter walker;
+ try
+ {
+ cppbash_builtin::exec("declare",args,cout,test_output,cin,walker);
+ FAIL();
+ }
+ catch(T& e)
+ {
+ EXPECT_EQ(expected, e.what());
+ }
+ }
}
TEST(declare_builtin_test, invalid_arguments)
{
- test_declare("Arguments required for declare\n", {});
- test_declare("Multiple arguments are not supported\n", {"-ap"});
- test_declare("Invalid option for declare builtin\n", {"_a"});
- test_declare("Unrecognized option for declare: -L\n", {"-L"});
+ test_declare<libbash::illegal_argument_exception>("Arguments required for declare", {});
+ test_declare<libbash::unsupported_exception>("Multiple arguments are not supported", {"-ap"});
+ test_declare<libbash::illegal_argument_exception>("Invalid option for declare builtin", {"_a"});
+ test_declare<libbash::illegal_argument_exception>("Unrecognized option for declare: -L", {"-L"});
}
TEST(declare_builtin_test, _F)
@@ -87,23 +99,23 @@ TEST(declare_built_test, _p)
}
#define TEST_DECLARE(name, expected, ...) \
- TEST(declare_builtin_test, name) { test_declare(expected, {__VA_ARGS__}); }
-
-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(_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")
-TEST_DECLARE(_t, "declare -t is not supported yet\n", "-t", "world")
-TEST_DECLARE(_u, "declare -u is not supported yet\n", "-u", "world")
-TEST_DECLARE(_x, "declare -x is not supported yet\n", "-x", "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(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")
-TEST_DECLARE(pt, "declare +t is not supported yet\n", "+t", "world")
-TEST_DECLARE(pu, "declare +u is not supported yet\n", "+u", "world")
-TEST_DECLARE(px, "declare +x is not supported yet\n", "+x", "world")
+ TEST(declare_builtin_test, name) { test_declare<libbash::unsupported_exception>(expected, {__VA_ARGS__}); }
+
+TEST_DECLARE(_a, "declare -a is not supported yet", "-a", "world")
+TEST_DECLARE(_A, "declare -A is not supported yet", "-A", "world")
+TEST_DECLARE(_f, "declare -f is not supported yet", "-f", "world")
+TEST_DECLARE(_i, "declare -i is not supported yet", "-i", "world")
+TEST_DECLARE(_l, "declare -l is not supported yet", "-l", "world")
+TEST_DECLARE(_r, "declare -r is not supported yet", "-r", "world")
+TEST_DECLARE(_t, "declare -t is not supported yet", "-t", "world")
+TEST_DECLARE(_u, "declare -u is not supported yet", "-u", "world")
+TEST_DECLARE(_x, "declare -x is not supported yet", "-x", "world")
+TEST_DECLARE(pa, "declare +a is not supported yet", "+a", "world")
+TEST_DECLARE(pA, "declare +A is not supported yet", "+A", "world")
+TEST_DECLARE(pf, "declare +f is not supported yet", "+f", "world")
+TEST_DECLARE(pi, "declare +i is not supported yet", "+i", "world")
+TEST_DECLARE(pl, "declare +l is not supported yet", "+l", "world")
+TEST_DECLARE(pr, "declare +r is not supported yet", "+r", "world")
+TEST_DECLARE(pt, "declare +t is not supported yet", "+t", "world")
+TEST_DECLARE(pu, "declare +u is not supported yet", "+u", "world")
+TEST_DECLARE(px, "declare +x is not supported yet", "+x", "world")
next reply other threads:[~2011-06-25 10:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-25 10:05 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-06-03 9:08 [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/ Petteri Räty
2011-06-09 7:27 Petteri Räty
2011-05-27 23:03 Petteri Räty
2011-05-25 19:42 Petteri Räty
2011-05-25 19:42 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=3016ad21687f5eb9f88c0e159536c4bfc23bfbd1.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