* [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/
@ 2011-05-25 19:42 Petteri Räty
0 siblings, 0 replies; 6+ messages in thread
From: Petteri Räty @ 2011-05-25 19:42 UTC (permalink / raw
To: gentoo-commits
commit: 73c325c9569cbd890ec564bd5a9f7fab084c8e16
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed May 25 08:39:12 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 25 10:13:53 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=73c325c9
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
///
+#include "core/interpreter.h"
#include "core/interpreter_exception.h"
#include "cppbash_builtin.h"
#include "builtins/shopt_builtin.h"
-namespace
+int shopt_builtin::set_opt(const std::vector<std::string>& bash_args, bool value)
{
- int disable_opt(const std::vector<std::string>& bash_args)
+ int result = 0;
+ for(auto iter = bash_args.begin() + 1; iter != bash_args.end(); ++iter)
{
- auto iter = find(bash_args.begin() + 1, bash_args.end(), "extglob");
- if(iter != 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 = 1;
+ }
}
+ return result;
}
int shopt_builtin::exec(const std::vector<std::string>& bash_args)
@@ -54,8 +62,9 @@ int shopt_builtin::exec(const std::vector<std::string>& 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 @@
class shopt_builtin : public virtual cppbash_builtin
{
+ int set_opt(const std::vector<std::string>& bash_args, bool value);
public:
BUILTIN_CONSTRUCTOR(shopt)
virtual int exec(const std::vector<std::string>& );
diff --git a/src/builtins/tests/shopt_tests.cpp b/src/builtins/tests/shopt_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::cout, 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"));
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/
@ 2011-05-25 19:42 Petteri Räty
0 siblings, 0 replies; 6+ messages in thread
From: Petteri Räty @ 2011-05-25 19:42 UTC (permalink / raw
To: gentoo-commits
commit: 811fd37b618ff770549e53ade07cfdd3afb0baab
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed May 25 07:43:15 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed May 25 13:44:49 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=811fd37b
Builtin: support declare -F and +F
---
src/builtins/declare_builtin.cpp | 29 ++++++++++++++++++++++++++++-
src/builtins/tests/declare_tests.cpp | 27 +++++++++++++++++++++++++--
2 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/src/builtins/declare_builtin.cpp b/src/builtins/declare_builtin.cpp
index 5d21bb3..90b127f 100644
--- a/src/builtins/declare_builtin.cpp
+++ b/src/builtins/declare_builtin.cpp
@@ -21,8 +21,11 @@
/// \author Mu Qiao
/// \brief class that implements the declare builtin
///
+#include <algorithm>
#include <iostream>
+#include "core/interpreter.h"
+
#include "builtins/declare_builtin.h"
int declare_builtin::exec(const std::vector<std::string>& bash_args)
@@ -44,12 +47,36 @@ int declare_builtin::exec(const std::vector<std::string>& bash_args)
return 1;
}
+ int result = 0;
switch(bash_args[0][1])
{
+ case 'F':
+ if(bash_args[0][0] == '+')
+ return 0;
+ if(bash_args.size() > 1)
+ {
+ for(auto iter = bash_args.begin() + 1; iter != bash_args.end(); ++iter)
+ {
+ if(_walker.has_function(*iter))
+ *_out_stream << *iter << std::endl;
+ else
+ result = 1;
+ }
+ }
+ else
+ {
+ std::vector<std::string> functions;
+
+ _walker.get_all_function_names(functions);
+ sort(functions.begin(), functions.end());
+
+ for(auto iter = functions.begin(); iter != functions.end(); ++iter)
+ *_out_stream << "declare -f " << *iter << std::endl;
+ }
+ return result;
case 'a':
case 'A':
case 'f':
- case 'F':
case 'i':
case 'l':
case 'r':
diff --git a/src/builtins/tests/declare_tests.cpp b/src/builtins/tests/declare_tests.cpp
index 925c5b9..21657dd 100644
--- a/src/builtins/tests/declare_tests.cpp
+++ b/src/builtins/tests/declare_tests.cpp
@@ -27,6 +27,7 @@
#include <gtest/gtest.h>
+#include "core/bash_ast.h"
#include "core/interpreter.h"
#include "cppbash_builtin.h"
@@ -40,13 +41,36 @@ static void test_declare(const string& expected, std::initializer_list<string> a
EXPECT_EQ(expected, test_output.str());
}
+TEST(declare_builtin_test, _F)
+{
+ stringstream expression("function foo() { :; }; function bar() { :; }");
+ interpreter walker;
+ bash_ast ast(expression);
+ ast.interpret_with(walker);
+
+ stringstream test_output1;
+ EXPECT_EQ(0, cppbash_builtin::exec("declare", {"-F", "foo"}, test_output1, cerr, cin, walker));
+ EXPECT_EQ("foo\n", test_output1.str());
+
+ stringstream test_output2;
+ EXPECT_EQ(1, cppbash_builtin::exec("declare", {"-F", "foo", "bar", "test"}, test_output2, cerr, cin, walker));
+ EXPECT_EQ("foo\nbar\n", test_output2.str());
+
+ stringstream test_output3;
+ EXPECT_EQ(0, cppbash_builtin::exec("declare", {"+F", "foo", "bar", "test"}, test_output3, cerr, cin, walker));
+ EXPECT_EQ("", test_output3.str());
+
+ stringstream test_output4;
+ EXPECT_EQ(0, cppbash_builtin::exec("declare", {"-F"}, test_output3, cerr, cin, walker));
+ EXPECT_EQ("declare -f bar\ndeclare -f foo\n", test_output3.str());
+}
+
#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(_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")
@@ -57,7 +81,6 @@ TEST_DECLARE(_p, "declare -p is not supported yet\n", "-p", "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(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")
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/
@ 2011-05-27 23:03 Petteri Räty
0 siblings, 0 replies; 6+ messages in thread
From: Petteri Räty @ 2011-05-27 23:03 UTC (permalink / raw
To: gentoo-commits
commit: d33c85725fde46652bf0d625e3738103686f3190
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu May 26 08:52:58 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu May 26 14:56:52 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d33c8572
Builtin: source returns 1 if the script is illegal
If the given script can not be parsed properly, source will return
1 rather than printing error message only. A test is added for
testing empty argument.
---
src/builtins/source_builtin.cpp | 3 +++
src/builtins/tests/source_tests.cpp | 19 +++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/builtins/source_builtin.cpp b/src/builtins/source_builtin.cpp
index 87f8a5d..5f78177 100644
--- a/src/builtins/source_builtin.cpp
+++ b/src/builtins/source_builtin.cpp
@@ -50,7 +50,10 @@ int source_builtin::exec(const std::vector<std::string>& bash_args)
{
stored_ast.reset(new bash_ast(path));
if(stored_ast->get_error_count())
+ {
std::cerr << path << " could not be parsed properly" << std::endl;
+ return 1;
+ }
}
const std::string& original_path = _walker.resolve<std::string>("0");
diff --git a/src/builtins/tests/source_tests.cpp b/src/builtins/tests/source_tests.cpp
index 4549954..b051de3 100644
--- a/src/builtins/tests/source_tests.cpp
+++ b/src/builtins/tests/source_tests.cpp
@@ -73,3 +73,22 @@ TEST(source_builtin_test, source_return)
EXPECT_EQ(status, 10);
EXPECT_TRUE(walker.is_unset_or_null("NOT_EXIST", 0));
}
+
+TEST(source_builtin_test, invalid)
+{
+ interpreter walker;
+ EXPECT_THROW(cppbash_builtin::exec("source",
+ {},
+ std::cout,
+ std::cerr,
+ std::cin,
+ walker),
+ interpreter_exception);
+ int status = cppbash_builtin::exec("source",
+ {get_src_dir() + "/scripts/illegal_script.sh"},
+ std::cout,
+ std::cerr,
+ std::cin,
+ walker);
+ EXPECT_NE(status, 0);
+}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/
@ 2011-06-09 7:27 Petteri Räty
0 siblings, 0 replies; 6+ messages in thread
From: Petteri Räty @ 2011-06-09 7:27 UTC (permalink / raw
To: gentoo-commits
commit: aba5408ad36445b170ba5e7519e49ff245bda322
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 8 13:01:50 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun 9 07:23:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=aba5408a
Builtin: support declare -p vars
We do not support declare -p without arguments for now.
---
src/builtins/declare_builtin.cpp | 23 ++++++++++++++++++++++-
src/builtins/tests/declare_tests.cpp | 15 ++++++++++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/builtins/declare_builtin.cpp b/src/builtins/declare_builtin.cpp
index 3ee9def..cccbb9d 100644
--- a/src/builtins/declare_builtin.cpp
+++ b/src/builtins/declare_builtin.cpp
@@ -73,6 +73,28 @@ int declare_builtin::exec(const std::vector<std::string>& bash_args)
*_out_stream << "declare -f " << *iter << std::endl;
}
return result;
+ case 'p':
+ if(bash_args.size() > 1)
+ {
+ for(auto iter = bash_args.begin() + 1; iter != bash_args.end(); ++iter)
+ {
+ // We do not print the type of the variable for now
+ if(!_walker.is_unset(*iter))
+ {
+ *_out_stream << "declare -- " << *iter << "=\"" << _walker.resolve<std::string>(*iter) << "\"" << std::endl;
+ }
+ else
+ {
+ *_out_stream << "-bash: declare: " << *iter << ": not found" << std::endl;
+ result = 1;
+ }
+ }
+ }
+ else
+ {
+ throw interpreter_exception("We do not support declare -p without arguments for now");
+ }
+ return result;
case 'a':
case 'A':
case 'f':
@@ -82,7 +104,6 @@ int declare_builtin::exec(const std::vector<std::string>& bash_args)
case 't':
case 'u':
case 'x':
- case 'p':
*_err_stream << "declare " << bash_args[0] << " is not supported yet" << std::endl;
return 1;
default:
diff --git a/src/builtins/tests/declare_tests.cpp b/src/builtins/tests/declare_tests.cpp
index 95c0949..2bedfd3 100644
--- a/src/builtins/tests/declare_tests.cpp
+++ b/src/builtins/tests/declare_tests.cpp
@@ -72,6 +72,20 @@ TEST(declare_builtin_test, _F)
EXPECT_EQ("declare -f bar\ndeclare -f foo\n", test_output3.str());
}
+TEST(declare_built_test, _p)
+{
+ interpreter walker;
+ walker.define("foo", "bar");
+
+ stringstream test_output1;
+ EXPECT_EQ(0, cppbash_builtin::exec("declare", {"-p", "foo"}, test_output1, cerr, cin, walker));
+ EXPECT_EQ("declare -- foo=\"bar\"\n", test_output1.str());
+
+ stringstream test_output2;
+ EXPECT_EQ(1, cppbash_builtin::exec("declare", {"-p", "bar", "test"}, test_output2, cerr, cin, walker));
+ EXPECT_EQ("-bash: declare: bar: not found\n-bash: declare: test: not found\n", test_output2.str());
+}
+
#define TEST_DECLARE(name, expected, ...) \
TEST(declare_builtin_test, name) { test_declare(expected, {__VA_ARGS__}); }
@@ -84,7 +98,6 @@ 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(_p, "declare -p is not supported yet\n", "-p", "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")
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/
@ 2011-06-25 10:05 Petteri Räty
0 siblings, 0 replies; 6+ messages in thread
From: Petteri Räty @ 2011-06-25 10:05 UTC (permalink / raw
To: gentoo-commits
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")
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/
@ 2012-06-03 9:08 Petteri Räty
0 siblings, 0 replies; 6+ messages in thread
From: Petteri Räty @ 2012-06-03 9:08 UTC (permalink / raw
To: gentoo-commits
commit: 846f3e937c727996a114045f06f5a0c5ab660619
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 27 11:53:09 2012 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat May 26 10:40:50 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=846f3e93
Builtin: improve error output for some builtins
---
src/builtins/declare_builtin.cpp | 8 ++++----
src/builtins/shopt_builtin.cpp | 6 +++---
src/builtins/source_builtin.cpp | 2 +-
src/builtins/tests/declare_tests.cpp | 8 ++++----
src/builtins/tests/shopt_tests.cpp | 6 +++---
5 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/builtins/declare_builtin.cpp b/src/builtins/declare_builtin.cpp
index 1c85d61..db955c4 100644
--- a/src/builtins/declare_builtin.cpp
+++ b/src/builtins/declare_builtin.cpp
@@ -32,18 +32,18 @@ int declare_builtin::exec(const std::vector<std::string>& bash_args)
{
if(bash_args.empty())
{
- throw libbash::illegal_argument_exception("Arguments required for declare");
+ throw libbash::illegal_argument_exception("declare: arguments required");
return 1;
}
else if(bash_args[0].size() != 2)
{
- throw libbash::unsupported_exception("Multiple arguments are not supported");
+ throw libbash::unsupported_exception("declare: multiple arguments are not supported");
return 1;
}
if(bash_args[0][0] != '-' && bash_args[0][0] != '+')
{
- throw libbash::illegal_argument_exception("Invalid option for declare builtin");
+ throw libbash::illegal_argument_exception("declare: invalid option");
return 1;
}
@@ -108,7 +108,7 @@ int declare_builtin::exec(const std::vector<std::string>& bash_args)
throw libbash::unsupported_exception("declare " + bash_args[0] + " is not supported yet");
return 1;
default:
- throw libbash::illegal_argument_exception("Unrecognized option for declare: " + bash_args[0]);
+ throw libbash::illegal_argument_exception("declare: unrecognized option: " + bash_args[0]);
return 1;
}
}
diff --git a/src/builtins/shopt_builtin.cpp b/src/builtins/shopt_builtin.cpp
index fd9e581..1e3da70 100644
--- a/src/builtins/shopt_builtin.cpp
+++ b/src/builtins/shopt_builtin.cpp
@@ -42,9 +42,9 @@ void shopt_builtin::print_opts() const
int shopt_builtin::exec(const std::vector<std::string>& bash_args)
{
if(bash_args.empty())
- throw libbash::illegal_argument_exception("Arguments required for shopt");
+ throw libbash::illegal_argument_exception("shopt: arguments required");
else if(bash_args[0].size() != 2)
- throw libbash::unsupported_exception("Multiple arguments are not supported");
+ throw libbash::unsupported_exception("shopt: multiple arguments are not supported");
switch(bash_args[0][1])
{
@@ -61,7 +61,7 @@ int shopt_builtin::exec(const std::vector<std::string>& bash_args)
case 'o':
throw libbash::unsupported_exception("shopt " + bash_args[0] + " is not supported yet");
default:
- throw libbash::illegal_argument_exception("Unrecognized option for shopt: " + bash_args[0]);
+ throw libbash::illegal_argument_exception("shopt: unrecognized option: " + bash_args[0]);
}
return 0;
diff --git a/src/builtins/source_builtin.cpp b/src/builtins/source_builtin.cpp
index 91f3397..7af4f91 100644
--- a/src/builtins/source_builtin.cpp
+++ b/src/builtins/source_builtin.cpp
@@ -65,7 +65,7 @@ namespace {
int source_builtin::exec(const std::vector<std::string>& bash_args)
{
if(bash_args.size() == 0)
- throw libbash::illegal_argument_exception("should provide one argument for source builtin");
+ throw libbash::illegal_argument_exception("source: argument required");
const std::string& original_path = _walker.resolve<std::string>("0");
_walker.define("0", bash_args.front(), true);
diff --git a/src/builtins/tests/declare_tests.cpp b/src/builtins/tests/declare_tests.cpp
index 686c816..19347ac 100644
--- a/src/builtins/tests/declare_tests.cpp
+++ b/src/builtins/tests/declare_tests.cpp
@@ -54,10 +54,10 @@ namespace
TEST(declare_builtin_test, invalid_arguments)
{
- 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<libbash::illegal_argument_exception>("declare: arguments required", {});
+ test_declare<libbash::unsupported_exception>("declare: multiple arguments are not supported", {"-ap"});
+ test_declare<libbash::illegal_argument_exception>("declare: invalid option", {"_a"});
+ test_declare<libbash::illegal_argument_exception>("declare: unrecognized option: -L", {"-L"});
}
TEST(declare_builtin_test, _F)
diff --git a/src/builtins/tests/shopt_tests.cpp b/src/builtins/tests/shopt_tests.cpp
index dc43dee..af2915b 100644
--- a/src/builtins/tests/shopt_tests.cpp
+++ b/src/builtins/tests/shopt_tests.cpp
@@ -69,8 +69,8 @@ TEST(shopt_builtin_test, enable_extglob)
TEST(shopt_builtin_test, invalid_argument)
{
- test_shopt_builtin<libbash::illegal_argument_exception>("Arguments required for shopt", {});
- test_shopt_builtin<libbash::unsupported_exception>("Multiple arguments are not supported", {"-so"});
+ test_shopt_builtin<libbash::illegal_argument_exception>("shopt: arguments required", {});
+ test_shopt_builtin<libbash::unsupported_exception>("shopt: multiple arguments are not supported", {"-so"});
test_shopt_builtin<libbash::unsupported_exception>("shopt -q is not supported yet", {"-q"});
- test_shopt_builtin<libbash::illegal_argument_exception>("Unrecognized option for shopt: -d", {"-d"});
+ test_shopt_builtin<libbash::illegal_argument_exception>("shopt: unrecognized option: -d", {"-d"});
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-06-03 9:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-25 19:42 [gentoo-commits] proj/libbash:master commit in: src/builtins/tests/, src/builtins/ Petteri Räty
-- strict thread matches above, loose matches on Subject: below --
2012-06-03 9:08 Petteri Räty
2011-06-25 10:05 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox