diff options
author | André Aparício <aparicio99@gmail.com> | 2012-05-28 23:48:16 +0100 |
---|---|---|
committer | André Aparício <aparicio99@gmail.com> | 2012-07-03 02:16:19 +0100 |
commit | 31f6bbe25a23e7e0d2b1411b3952ba39066a195b (patch) | |
tree | 9fd3bd256f466bad90f132f90afb50e8941b7d5b /src/builtins | |
parent | Builtin: Implement set builtin (diff) | |
download | libbash-31f6bbe25a23e7e0d2b1411b3952ba39066a195b.tar.gz libbash-31f6bbe25a23e7e0d2b1411b3952ba39066a195b.tar.bz2 libbash-31f6bbe25a23e7e0d2b1411b3952ba39066a195b.zip |
Builtin: Implement set -u option
Diffstat (limited to 'src/builtins')
-rw-r--r-- | src/builtins/set_builtin.cpp | 2 | ||||
-rw-r--r-- | src/builtins/tests/set_tests.cpp | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/builtins/set_builtin.cpp b/src/builtins/set_builtin.cpp index fca0f82..6becb76 100644 --- a/src/builtins/set_builtin.cpp +++ b/src/builtins/set_builtin.cpp @@ -62,6 +62,8 @@ int set_builtin::exec(const std::vector<std::string>& bash_args) case 'p': case 't': case 'u': + _walker.set_option('u', bash_args[0][0] == '-'); + return 0; case 'v': case 'x': case 'B': diff --git a/src/builtins/tests/set_tests.cpp b/src/builtins/tests/set_tests.cpp index c4807c9..2b724bb 100644 --- a/src/builtins/tests/set_tests.cpp +++ b/src/builtins/tests/set_tests.cpp @@ -41,3 +41,22 @@ TEST(set_builtin_test, positional) EXPECT_EQ(0, walker.get_array_length("*")); EXPECT_STREQ("", walker.resolve<std::string>("*", 1).c_str()); } + +TEST(set_builtin_test, u_option) +{ + interpreter walker; + + EXPECT_EQ(0, cppbash_builtin::exec("set", {"-u"}, std::cout, std::cerr, std::cin, walker)); + EXPECT_THROW(walker.resolve<std::string>("VAR1").c_str(), libbash::unsupported_exception); + + walker.set_value("ARRAY", "foo"); + EXPECT_NO_THROW(walker.resolve<std::string>("ARRAY").c_str()); + EXPECT_THROW(walker.resolve<std::string>("ARRAY", 2).c_str(), libbash::unsupported_exception); + + walker.set_value("ARRAY", "foo", 3); + EXPECT_NO_THROW(walker.resolve<std::string>("ARRAY", 3).c_str()); + + EXPECT_EQ(0, cppbash_builtin::exec("set", {"+u"}, std::cout, std::cerr, std::cin, walker)); + EXPECT_NO_THROW(walker.resolve<std::string>("VAR2", 1).c_str()); + +} |