1 |
commit: d33c85725fde46652bf0d625e3738103686f3190 |
2 |
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu May 26 08:52:58 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu May 26 14:56:52 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=d33c8572 |
7 |
|
8 |
Builtin: source returns 1 if the script is illegal |
9 |
|
10 |
If the given script can not be parsed properly, source will return |
11 |
1 rather than printing error message only. A test is added for |
12 |
testing empty argument. |
13 |
|
14 |
--- |
15 |
src/builtins/source_builtin.cpp | 3 +++ |
16 |
src/builtins/tests/source_tests.cpp | 19 +++++++++++++++++++ |
17 |
2 files changed, 22 insertions(+), 0 deletions(-) |
18 |
|
19 |
diff --git a/src/builtins/source_builtin.cpp b/src/builtins/source_builtin.cpp |
20 |
index 87f8a5d..5f78177 100644 |
21 |
--- a/src/builtins/source_builtin.cpp |
22 |
+++ b/src/builtins/source_builtin.cpp |
23 |
@@ -50,7 +50,10 @@ int source_builtin::exec(const std::vector<std::string>& bash_args) |
24 |
{ |
25 |
stored_ast.reset(new bash_ast(path)); |
26 |
if(stored_ast->get_error_count()) |
27 |
+ { |
28 |
std::cerr << path << " could not be parsed properly" << std::endl; |
29 |
+ return 1; |
30 |
+ } |
31 |
} |
32 |
|
33 |
const std::string& original_path = _walker.resolve<std::string>("0"); |
34 |
|
35 |
diff --git a/src/builtins/tests/source_tests.cpp b/src/builtins/tests/source_tests.cpp |
36 |
index 4549954..b051de3 100644 |
37 |
--- a/src/builtins/tests/source_tests.cpp |
38 |
+++ b/src/builtins/tests/source_tests.cpp |
39 |
@@ -73,3 +73,22 @@ TEST(source_builtin_test, source_return) |
40 |
EXPECT_EQ(status, 10); |
41 |
EXPECT_TRUE(walker.is_unset_or_null("NOT_EXIST", 0)); |
42 |
} |
43 |
+ |
44 |
+TEST(source_builtin_test, invalid) |
45 |
+{ |
46 |
+ interpreter walker; |
47 |
+ EXPECT_THROW(cppbash_builtin::exec("source", |
48 |
+ {}, |
49 |
+ std::cout, |
50 |
+ std::cerr, |
51 |
+ std::cin, |
52 |
+ walker), |
53 |
+ interpreter_exception); |
54 |
+ int status = cppbash_builtin::exec("source", |
55 |
+ {get_src_dir() + "/scripts/illegal_script.sh"}, |
56 |
+ std::cout, |
57 |
+ std::cerr, |
58 |
+ std::cin, |
59 |
+ walker); |
60 |
+ EXPECT_NE(status, 0); |
61 |
+} |