aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2012-03-27 19:53:09 +0800
committerMu Qiao <qiaomuf@gentoo.org>2012-05-26 18:40:50 +0800
commit846f3e937c727996a114045f06f5a0c5ab660619 (patch)
treee283bb09c793ec1e919c78692b662c6d16133f47 /src/builtins
parentBuiltin: handle __export_funcs_var in inherit (diff)
downloadlibbash-846f3e937c727996a114045f06f5a0c5ab660619.tar.gz
libbash-846f3e937c727996a114045f06f5a0c5ab660619.tar.bz2
libbash-846f3e937c727996a114045f06f5a0c5ab660619.zip
Builtin: improve error output for some builtins
Diffstat (limited to 'src/builtins')
-rw-r--r--src/builtins/declare_builtin.cpp8
-rw-r--r--src/builtins/shopt_builtin.cpp6
-rw-r--r--src/builtins/source_builtin.cpp2
-rw-r--r--src/builtins/tests/declare_tests.cpp8
-rw-r--r--src/builtins/tests/shopt_tests.cpp6
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"});
}