1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*
Please use git log for copyright holder and year information
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 shopt_tests.cpp
/// \brief series of unit tests for shopt builtin
///
#include <gtest/gtest.h>
#include "builtins/builtin_exceptions.h"
#include "core/interpreter.h"
#include "cppbash_builtin.h"
static void test_shopt_builtin(const std::string& expected, const std::vector<std::string>& args)
{
std::stringstream output;
interpreter walker;
try
{
cppbash_builtin::exec("shopt", args, std::cout, output, std::cin, walker);
FAIL();
}
catch(libbash::interpreter_exception& e)
{
EXPECT_STREQ(expected.c_str(), e.what());
}
}
TEST(shopt_builtin_test, disable_extglob)
{
test_shopt_builtin("not exist is not a valid bash option", {"-u", "not exist"});
interpreter 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(shopt_builtin_test, enable_extglob)
{
test_shopt_builtin("not exist is not a valid bash option", {"-s", "not exist"});
interpreter 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"));
}
TEST(shopt_builtin_test, invalid_argument)
{
test_shopt_builtin("Arguments required for shopt", {});
test_shopt_builtin("Multiple arguments are not supported", {"-so"});
test_shopt_builtin("shopt -q is not supported yet", {"-q"});
test_shopt_builtin("Unrecognized option for shopt: -d", {"-d"});
}
|