aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-05-13 17:07:07 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-05-13 19:08:35 +0800
commitfbbffbf9fe8d4a56535335e6e45db20f6e4ae3a2 (patch)
tree38a78af425d938c08120b0fe7ddfdffa45e0eb1c /test
parentTests: fix cppunittests (diff)
downloadlibbash-fbbffbf9fe8d4a56535335e6e45db20f6e4ae3a2.tar.gz
libbash-fbbffbf9fe8d4a56535335e6e45db20f6e4ae3a2.tar.bz2
libbash-fbbffbf9fe8d4a56535335e6e45db20f6e4ae3a2.zip
Core&Utility: return non zero exit status on failure
The public API, ast_printer and bash_ast are refactored to return non zero exit status on failure.
Diffstat (limited to 'test')
-rw-r--r--test/api_test.cpp28
-rwxr-xr-xtest/ast_printer_test.sh12
2 files changed, 38 insertions, 2 deletions
diff --git a/test/api_test.cpp b/test/api_test.cpp
index 813c3b0..8746a0a 100644
--- a/test/api_test.cpp
+++ b/test/api_test.cpp
@@ -25,8 +25,7 @@
#include <gtest/gtest.h>
#include "libbash.h"
-
-using namespace std;
+#include "test.h"
TEST(libbashapi, bad_path)
{
@@ -35,3 +34,28 @@ TEST(libbashapi, bad_path)
EXPECT_THROW(libbash::interpret("not exist", variables, functions),
interpreter_exception);
}
+
+TEST(libbashapi, illegal_script)
+{
+ std::unordered_map<std::string, std::vector<std::string>> variables;
+ std::vector<std::string> functions;
+ int result = libbash::interpret(get_src_dir() + "/scripts/illegal_script.sh",
+ variables,
+ functions);
+ EXPECT_NE(0, result);
+}
+
+TEST(libbashapi, legal_script)
+{
+ std::unordered_map<std::string, std::vector<std::string>> variables;
+ std::vector<std::string> functions;
+ int result = libbash::interpret(get_src_dir() + std::string("/scripts/source_true.sh"),
+ variables,
+ functions);
+ EXPECT_EQ(0, result);
+
+ result = libbash::interpret(get_src_dir() + std::string("/scripts/source_false.sh"),
+ variables,
+ functions);
+ EXPECT_NE(0, result);
+}
diff --git a/test/ast_printer_test.sh b/test/ast_printer_test.sh
index 6549921..e0c930f 100755
--- a/test/ast_printer_test.sh
+++ b/test/ast_printer_test.sh
@@ -10,4 +10,16 @@ error+=$?
| diff -u $srcdir/bashast/features_script/features.sh.tokens -
error+=$?
+./ast_printer -f $srcdir/bashast/features_script/illegal_script.sh 2 > /dev/null
+if [[ $? == 0 ]]
+then
+ error+=1
+fi
+
+./ast_printer -e "case" 2 > /dev/null
+if [[ $? == 0 ]]
+then
+ error+=1
+fi
+
exit $error