public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-03-30 12:48 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-03-30 12:48 UTC (permalink / raw
  To: gentoo-commits

commit:     88ebb72008a432e5b532d164aa2741e6a2582f5c
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 29 09:33:47 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Mar 29 10:18:26 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=88ebb720

Refactor unit test

Wrap most logic into helper function.

---
 test/walker_test.cpp |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/test/walker_test.cpp b/test/walker_test.cpp
index 65db3f8..c6ad4a9 100644
--- a/test/walker_test.cpp
+++ b/test/walker_test.cpp
@@ -55,10 +55,16 @@ protected:
     lxr->free(lxr);
     input->close(input);
   }
+  void init_walker(const char* script);
 public:
   pbashwalker treePsr;
   shared_ptr<interpreter> walker;
-  void init_walker(const char *script);
+
+  int run_arithmetic(const char* script)
+  {
+    init_walker(script);
+    return treePsr->arithmetics(treePsr);
+  }
 };
 
 
@@ -110,7 +116,7 @@ void walker_test::init_walker(const char *script){
 
 #define TEST_BINARY_ARITHMETIC(name, script, exp_value)\
   TEST_F(walker_test, name)\
-  {init_walker(script); EXPECT_EQ(exp_value, treePsr->arithmetics(treePsr));}
+  {EXPECT_EQ(exp_value, run_arithmetic(script));}
 
 TEST_BINARY_ARITHMETIC(logicor_true,        "0 || -2",      1)
 TEST_BINARY_ARITHMETIC(logicor_false,       "0 || 0",       0)



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-03-31 12:32 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-03-31 12:32 UTC (permalink / raw
  To: gentoo-commits

commit:     f7c40576759f562a3911b2adbc49eabb4e94a0e4
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 31 03:13:53 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Mar 31 08:29:31 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=f7c40576

Refactor unit test to allow adding new rules

Extract some logic into subclass in order to make it possible to
add new rules.

---
 test/walker_test.cpp |   67 +++++++++++++++++++++++++++----------------------
 1 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/test/walker_test.cpp b/test/walker_test.cpp
index 41720ad..c026605 100644
--- a/test/walker_test.cpp
+++ b/test/walker_test.cpp
@@ -38,10 +38,9 @@ class walker_test: public ::testing::Test
   pANTLR3_INPUT_STREAM input;
   plibbashLexer lxr;
   pANTLR3_COMMON_TOKEN_STREAM tstream;
-  plibbashParser psr;
-  libbashParser_arithmetics_return langAST;
-  pANTLR3_COMMON_TREE_NODE_STREAM nodes;
 protected:
+  pANTLR3_COMMON_TREE_NODE_STREAM nodes;
+  plibbashParser psr;
   virtual void SetUp()
   {
     walker = shared_ptr<interpreter>(new interpreter);
@@ -55,30 +54,13 @@ protected:
     lxr->free(lxr);
     input->close(input);
   }
-  void init_walker(const char* script);
+  void init_parser(const char*);
 public:
   plibbashWalker treePsr;
   shared_ptr<interpreter> walker;
-
-  int run_arithmetic(const char* script)
-  {
-    init_walker(script);
-    return treePsr->arithmetics(treePsr);
-  }
-
-  void check_arithmetic_assignment(const char* script,
-                                   const string& name,
-                                   int exp_value)
-  {
-    // the return value of the arithmetic expression should be equal to
-    // the new value of the variable
-    EXPECT_EQ(exp_value, run_arithmetic(script));
-    EXPECT_EQ(exp_value, walker->resolve<int>(name));
-  }
 };
 
-
-void walker_test::init_walker(const char *script){
+void walker_test::init_parser(const char *script){
 
   auto start = reinterpret_cast<pANTLR3_UINT8>(const_cast<char *>(script));
   input  = antlr3NewAsciiStringInPlaceStream(start,
@@ -115,17 +97,42 @@ void walker_test::init_walker(const char *script){
     ANTLR3_FPRINTF(stderr, "Out of memory trying to allocate parser\n");
     FAIL();
   }
+}
 
-  langAST = psr->arithmetics(psr);
-  nodes   = antlr3CommonTreeNodeStreamNewTree(langAST.tree,
+class arithmetic_walker: public walker_test
+{
+  libbashParser_arithmetics_return langAST;
+protected:
+  void init_walker(const char* script)
+  {
+    init_parser(script);
+    langAST = psr->arithmetics(psr);
+    nodes = antlr3CommonTreeNodeStreamNewTree(langAST.tree,
                                               ANTLR3_SIZE_HINT);
-  treePsr = libbashWalkerNew(nodes);
-  walker->define("value", 100);
-  set_interpreter(walker);
-}
+    treePsr = libbashWalkerNew(nodes);
+    walker->define("value", 100);
+    set_interpreter(walker);
+  }
+
+  int run_arithmetic(const char* script)
+  {
+    init_walker(script);
+    return treePsr->arithmetics(treePsr);
+  }
+
+  void check_arithmetic_assignment(const char* script,
+                                   const string& name,
+                                   int exp_value)
+  {
+    // the return value of the arithmetic expression should be equal to
+    // the new value of the variable
+    EXPECT_EQ(exp_value, run_arithmetic(script));
+    EXPECT_EQ(exp_value, walker->resolve<int>(name));
+  }
+};
 
 #define TEST_BINARY_ARITHMETIC(name, script, exp_value)\
-  TEST_F(walker_test, name)\
+  TEST_F(arithmetic_walker, name)\
   {EXPECT_EQ(exp_value, run_arithmetic(script));}
 
 TEST_BINARY_ARITHMETIC(logicor_true,        "0 || -2",      1)
@@ -167,7 +174,7 @@ TEST_BINARY_ARITHMETIC(complex_cal2,        "10*${value}<<3%2**5", 8000)
 TEST_BINARY_ARITHMETIC(complex_cal3,        "(20&5|3||1*100-20&5*10)+~(2*5)", -10)
 
 #define TEST_ARITHMETIC_ASSIGNMENT(name, script, var_name, exp_value)\
-  TEST_F(walker_test, name) \
+  TEST_F(arithmetic_walker, name) \
   { check_arithmetic_assignment(script, var_name, exp_value); }
 
 TEST_ARITHMETIC_ASSIGNMENT(assignment,             "new_var=10",   "new_var",      10)



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-04-02 15:50 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-04-02 15:50 UTC (permalink / raw
  To: gentoo-commits

commit:     2a3efed81037df11a5d338503713092e3ef0237c
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr  2 15:30:50 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Apr  2 15:46:51 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2a3efed8

Use std::map to simplify variable printer

std::map is sorted so we can simplify the code by just creating a map
from the unsorted_map.

---
 test/variable_printer.cpp |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/test/variable_printer.cpp b/test/variable_printer.cpp
index ab2b4cb..b519d3f 100644
--- a/test/variable_printer.cpp
+++ b/test/variable_printer.cpp
@@ -24,11 +24,9 @@
 
 #include <algorithm>
 #include <iostream>
-#include <vector>
+#include <map>
 
-#include <boost/range/adaptor/map.hpp>
 #include <boost/range/algorithm/for_each.hpp>
-#include <boost/range/algorithm/sort.hpp>
 #include <gtest/gtest.h>
 
 #include "libbash.h"
@@ -46,11 +44,9 @@ int main(int argc, char** argv)
   unordered_map<string, string> variables;
   libbash::interpret(argv[1], variables);
 
-  auto keys = variables | boost::adaptors::map_keys;
-  vector<string> names(keys.begin(), keys.end());
-  auto sorted = boost::sort(names);
-  boost::for_each(boost::sort(names), [&](const string& key){
-    cout << key << '=' << variables[key] << endl;
+  std::map<string, string> sorted(variables.begin(), variables.end());
+  boost::for_each(sorted, [&](const std::pair<string,string>& pair){
+    cout << pair.first << '=' << pair.second << endl;
   });
 
   return 0;



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-04-03 10:16 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-04-03 10:16 UTC (permalink / raw
  To: gentoo-commits

commit:     cc316ba6127e6dd527205e352ddf9e97d00be21b
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Apr  2 21:00:19 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Apr  2 21:00:19 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=cc316ba6

Variable printer output using Karma

---
 test/variable_printer.cpp |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/test/variable_printer.cpp b/test/variable_printer.cpp
index b519d3f..cb839f2 100644
--- a/test/variable_printer.cpp
+++ b/test/variable_printer.cpp
@@ -26,28 +26,27 @@
 #include <iostream>
 #include <map>
 
-#include <boost/range/algorithm/for_each.hpp>
 #include <gtest/gtest.h>
+#include <boost/spirit/include/karma.hpp>
+#include <boost/fusion/include/std_pair.hpp>
 
 #include "libbash.h"
 
-using namespace std;
-
 int main(int argc, char** argv)
 {
   if(argc != 2)
   {
-    cerr<<"Please provide your script as an argument"<<endl;
+    std::cerr<<"Please provide your script as an argument"<<std::endl;
     exit(EXIT_FAILURE);
   }
 
-  unordered_map<string, string> variables;
+  std::unordered_map<std::string, std::string> variables;
   libbash::interpret(argv[1], variables);
 
-  std::map<string, string> sorted(variables.begin(), variables.end());
-  boost::for_each(sorted, [&](const std::pair<string,string>& pair){
-    cout << pair.first << '=' << pair.second << endl;
-  });
+  std::map<std::string, std::string> sorted(variables.begin(), variables.end());
+
+  using namespace boost::spirit::karma;
+  std::cout << format((string << '=' << string) % eol, sorted) << std::endl;
 
   return 0;
 }



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-05-24 14:40 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-05-24 14:40 UTC (permalink / raw
  To: gentoo-commits

commit:     3c7346eaa4197fe2be4ce1a13ca817c9241b45ea
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Tue May 24 14:39:17 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue May 24 14:39:17 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=3c7346ea

Test: /bin/bash instead of /bin/sh

verify_bash_test.sh uses bash syntax so it must be run with bash.

---
 test/verify_bashs_test.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/test/verify_bashs_test.sh b/test/verify_bashs_test.sh
index 2c42195..8b70030 100755
--- a/test/verify_bashs_test.sh
+++ b/test/verify_bashs_test.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 num_of_ebuild_files=$(grep 'scripts/.*.bash' $srcdir/Makefile.am | wc -l)
 [[ $num_of_ebuild_files == $(ls $srcdir/scripts/*.bash* | wc -l) ]]



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-05-27 23:03 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-05-27 23:03 UTC (permalink / raw
  To: gentoo-commits

commit:     101979fc6ddbe2ef2c49a7bf53d219338e91177a
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu May 26 09:01:33 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu May 26 14:56:52 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=101979fc

Test: improve test coverage for public API

---
 test/api_test.cpp |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/test/api_test.cpp b/test/api_test.cpp
index 7e1bd23..a724401 100644
--- a/test/api_test.cpp
+++ b/test/api_test.cpp
@@ -79,4 +79,9 @@ TEST(libbashapi, preload)
                               variables,
                               functions);
   EXPECT_NE(0, result);
+  result = libbash::interpret(get_src_dir() + std::string("/scripts/source_true.sh"),
+                              get_src_dir() + std::string("/scripts/illegal_script.sh"),
+                              variables,
+                              functions);
+  EXPECT_NE(0, result);
 }



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-06-09  8:15 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-06-09  8:15 UTC (permalink / raw
  To: gentoo-commits

commit:     36183890c078e12e2789e1cf17000f5be4833fe8
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Jun  2 08:35:15 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Jun  9 08:11:43 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=36183890

Test: silent the error output of gtest

---
 test/run_tests.cpp |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/test/run_tests.cpp b/test/run_tests.cpp
index 1681a81..6606a90 100644
--- a/test/run_tests.cpp
+++ b/test/run_tests.cpp
@@ -21,6 +21,8 @@
 /// \brief runs unit tests for post_check
 ///
 
+#include <cstdio>
+
 #include<gtest/gtest.h>
 
 ///
@@ -28,6 +30,8 @@
 ///
 int main(int argc, char* argv[])
 {
+  if(!freopen("/dev/null", "w", stderr))
+    return EXIT_FAILURE;
   ::testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
 }



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/libbash:master commit in: test/
@ 2011-06-19 19:15 Petteri Räty
  0 siblings, 0 replies; 8+ messages in thread
From: Petteri Räty @ 2011-06-19 19:15 UTC (permalink / raw
  To: gentoo-commits

commit:     7fee8a51ec0138f61ce1632747753510f3cd4a17
Author:     Petteri Räty <petsku <AT> petteriraty <DOT> eu>
AuthorDate: Sat Jun 18 09:59:17 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Sat Jun 18 09:59:17 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=7fee8a51

Test: verify_error_output_test.sh improvement

The file now needs to be changes less often as it doesn't depend on
exact line numbers any more. This should make it easier to merge
branches.

---
 test/verify_error_output_test.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/test/verify_error_output_test.sh b/test/verify_error_output_test.sh
index f8a2a7b..4bb0465 100755
--- a/test/verify_error_output_test.sh
+++ b/test/verify_error_output_test.sh
@@ -2,4 +2,4 @@
 
 illegal="${srcdir}/scripts/illegal_script.sh"
 output=$(./variable_printer "$illegal" 2>&1)
-[[ $output == "${illegal}(1)  : error 3 : 131:1: command_atom : ( compound_command | function | simple_command );, at offset 3"* ]]
+[[ $output == "${illegal}(1)  : error 3 : "???":1: command_atom : ( compound_command | function | simple_command );, at offset 3"* ]]



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-06-19 19:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-19 19:15 [gentoo-commits] proj/libbash:master commit in: test/ Petteri Räty
  -- strict thread matches above, loose matches on Subject: below --
2011-06-09  8:15 Petteri Räty
2011-05-27 23:03 Petteri Räty
2011-05-24 14:40 Petteri Räty
2011-04-03 10:16 Petteri Räty
2011-04-02 15:50 Petteri Räty
2011-03-31 12:32 Petteri Räty
2011-03-30 12:48 Petteri Räty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox