This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Tarantool -- an efficient key/value data store".

The branch test-runner has been updated
       via  44f5399b490759ee47c34bf3ed01d08d381d167e (commit)
       via  c06cda26cf897423f85ba7cad0e68ef54104186a (commit)
      from  a2bd93f68da0334bd621b91439c33710404607fa (commit)

Summary of changes:
 test/Makefile                   |    3 +
 test/admin.py                   |   36 ++++++++++++++--
 test/box/suite.ini              |    2 +-
 test/cmd/args.test              |    8 ++++
 test/cmd/suite.ini              |    5 ++
 test/{box => cmd}/tarantool.cfg |    0
 test/cmdline.py                 |   84 +++++++++++++++++++++++++++++++++++++++
 test/test-run.py                |   23 ++++++++--
 8 files changed, 150 insertions(+), 11 deletions(-)
 create mode 100644 test/Makefile
 create mode 100644 test/cmd/args.test
 create mode 100644 test/cmd/suite.ini
 copy test/{box => cmd}/tarantool.cfg (100%)
 create mode 100755 test/cmdline.py

commit 44f5399b490759ee47c34bf3ed01d08d381d167e
Author: Konstantin Osipov <[email protected]>
Date:   Fri Dec 10 19:12:33 2010 +0300

    Test runner: add tests for command line arguments.
    
    Add a new test suite, cmd. Add a new driver for this
    suite, cmdline.py. This driver reads arguments from the test,
    and executes the server with these arguments. Server output
    is passed on as test result.
    
    @todo: It's not necessary to start/stop the server
    for 'cmd' suite. Will be fixed when how to start/stop
    server is defined in suite.ini (we'll then be
    able to define a no-op start/stop routines).
    @todo tarantool_silverbox output is hard to auto-verify
    since it contains the current time and process id.
    Either implement a way to mask out pieces of output
    from the result file (preferrable), or change
    tarantool to not output volatile data.
    
    test-run.py modified: we now can preprocess suite.ini
    "client" parameters, and substitute $constants in them,
    e.g. $server.
    
    @todo: provide ability to substitute $constants in .test
    files as well.

diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..d3c699e
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,3 @@
+test:
+       ./test-run.py
+
diff --git a/test/cmd/args.test b/test/cmd/args.test
new file mode 100644
index 0000000..58b53b5
--- /dev/null
+++ b/test/cmd/args.test
@@ -0,0 +1,8 @@
+--config
+r>  
+--verbose
+r>  
+--config tarantool.cfg
+r>  
+--foo
+r>  
diff --git a/test/cmd/suite.ini b/test/cmd/suite.ini
new file mode 100644
index 0000000..25ddabc
--- /dev/null
+++ b/test/cmd/suite.ini
@@ -0,0 +1,5 @@
+[default]
+description = tarantool/silverbox, command line options 
+client = cmdline.py $server --result-prefix "r> "
+config = tarantool.cfg
+pidfile = box.pid
diff --git a/test/cmd/tarantool.cfg b/test/cmd/tarantool.cfg
new file mode 100644
index 0000000..c09c23a
--- /dev/null
+++ b/test/cmd/tarantool.cfg
@@ -0,0 +1,16 @@
+slab_alloc_arena = 0.1
+
+pid_file = "box.pid"
+
+primary_port = 33013
+secondary_port = 33014
+admin_port = 33015
+
+rows_per_wal = 50
+
+namespace[0].enabled = 1
+namespace[0].index[0].type = "HASH"
+namespace[0].index[0].unique = 1
+namespace[0].index[0].key_field[0].fieldno = 0
+namespace[0].index[0].key_field[0].type = "NUM"
+
diff --git a/test/cmdline.py b/test/cmdline.py
new file mode 100755
index 0000000..3e8a6a1
--- /dev/null
+++ b/test/cmdline.py
@@ -0,0 +1,84 @@
+#! /usr/bin/python 
+"""Test stdout/stdin interaction of a program".
+
+Accepts a path to a UNIX command line program to test.
+Reads command line options from stdin (one set of options per
+one line of input), executes the program, and prints the output
+to stdout, prefixed with r>. """
+
+__author__ = "Konstantin Osipov <[email protected]>"
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+import argparse
+import shlex
+import subprocess
+import sys
+import string
+
+def main():
+  parser = argparse.ArgumentParser(
+      description = "Test command line options of a program.")
+
+  parser.add_argument(
+      "bin",
+      help = """Path to the binary to test. Command line options are
+      read from stdin, one line at a time, the program is run
+      with the options, the output is sent to stdout.""")
+
+  parser.add_argument(
+      "--result-prefix",
+      metavar = "prefix",
+      dest = "result_prefix",
+      help = """Skip input lines that have the given prefix (e.g. "r> ".
+      Prepend the prefix to all output lines. If not set, nothing is
+      skipped and output is printed as-is. This option is used
+      to pipe in .test files, automatically skipping test output.
+      Without this option the program may be used as an interactive
+      client.""")
+
+  args = parser.parse_args()
+
+  try:
+    result_prefix = args.result_prefix
+
+    for line in iter(sys.stdin.readline, ""):
+      if result_prefix != None and line.find(result_prefix) == 0:
+        continue
+      path = string.join([args.bin, line])
+      output = subprocess.Popen(shlex.split(path),
+                                stdout = subprocess.PIPE,
+                                stderr = subprocess.PIPE).stdout.read()
+      if result_prefix != None:
+        print line, result_prefix, string.join(output.split("\n"),
+                                               "\n" + result_prefix)
+      else:
+        sys.stdout.write(output)
+
+    return 0
+  except RuntimeError as e:
+    print "Fatal error: ", repr(e)
+    return -1
+
+if __name__ == "__main__":
+  exit(main())
+
diff --git a/test/test-run.py b/test/test-run.py
index 6054220..39709c5 100755
--- a/test/test-run.py
+++ b/test/test-run.py
@@ -90,7 +90,7 @@ class Options:
         dest = 'suites',
         metavar = "suite",
         nargs="*",
-        default = ["box"],
+        default = ["box", "cmd"],
         help = """List of tests suites to look for tests in. Default: 
"box".""")
 
     parser.add_argument(
@@ -180,6 +180,7 @@ class Server:
 
       subprocess.check_call([self.abspath_to_exe, "--init_storage"],
                             cwd = self.args.vardir,
+# catch stdout/stderr to not clutter output
                             stdout = subprocess.PIPE,
                             stderr = subprocess.PIPE)
 
@@ -267,7 +268,7 @@ class Test:
     """Return true if this test was run successfully."""
     return self.is_executed and self.is_client_ok and self.is_equal_result
 
-  def run(self, is_force):
+  def run(self, test_env):
     """Execute the client program, giving it test as stdin,
     result as stdout. If the client program aborts, print
     its output to stdout, and raise an exception. Else, comprare
@@ -275,12 +276,20 @@ class Test:
     stdout and raise an exception. The exception is raised only
     if is_force flag is not set."""
 
+    def subst_test_env(arg):
+      if len(arg) and arg[0] == '$':
+        return test_env[arg[1:]]
+      else:
+        return arg
+
+    args = map(subst_test_env, shlex.split(self.client))
+
     sys.stdout.write("{0}".format(self.name))
 
     with open(self.name, "r") as test:
       with open(self.result, "w+") as result:
         self.is_client_ok = \
-          subprocess.call(shlex.split(self.client),
+          subprocess.call(args,
                           stdin = test, stdout = result) == 0
     
     self.is_executed = True
@@ -300,7 +309,7 @@ class Test:
       else:
         self.print_unidiff()
         where = ": wrong test output"
-      if not is_force:
+      if not test_env["is_force"]:
         raise TestRunException("Failed to run test " + self.name + where)
 
 
@@ -385,9 +394,11 @@ class TestSuite:
     print "TEST\t\t\t\tRESULT"
     print shortsep
     failed_tests = []
+    test_env = { "is_force" : self.args.is_force,
+                  "server" : server.abspath_to_exe }
 
     for test in self.tests:
-      test.run(self.args.is_force)
+      test.run(test_env)
       if not test.passed():
         failed_tests.append(test.name)
 

commit c06cda26cf897423f85ba7cad0e68ef54104186a
Author: Konstantin Osipov <[email protected]>
Date:   Thu Dec 9 17:59:04 2010 +0300

    Test-runner: admin.py as an interactive client.
    
    Provide options to admin.py to use it not just as
    a test console, but aslo as an interactive client.

diff --git a/test/admin.py b/test/admin.py
index ddae452..1f171e0 100755
--- a/test/admin.py
+++ b/test/admin.py
@@ -53,6 +53,25 @@ class Options:
         dest = "port",
         default = 33015,
         help = "Server port to connect to. Default: 33015")
+
+    parser.add_argument(
+        "--result-prefix",
+        metavar = "prefix",
+        dest = "result_prefix",
+        help = """Skip input lines that have the given prefix (e.g. "r> ".
+        Prepend the prefix to all output lines. If not set, nothing is
+        skipped and output is printed as-is. This option is used
+        to pipe in .test files, automatically skipping test output.
+        Without this option the program may be used as an interactive
+        client. See also --prompt.""")
+
+    parser.add_argument(
+        "--prompt",
+        metavar = "prompt",
+        dest = "prompt",
+        default = "\033[92mtarantool> \033[0m",
+        help = """Command prompt. Set to "" for no prompt. Default:
+        tarantool> """)
     
     self.args = parser.parse_args()
 
@@ -101,16 +120,23 @@ def main():
   options = Options()
   try:
     with Connection(options.args.host, options.args.port) as con:
-      res_sep = "r> "
+      result_prefix = options.args.result_prefix
+      prompt = options.args.prompt
+      if prompt != "":
+        sys.stdout.write(prompt)
       for line in iter(sys.stdin.readline, ""):
-        if line.find(res_sep) == 0:
+        if result_prefix != None and line.find(result_prefix) == 0:
           continue
-        print line,
         output = con.execute(line)
-        print res_sep, string.join(output.split("\n"), "\n"+res_sep)
+        if result_prefix != None:
+          print line, result_prefix, string.join(output.split("\n"),
+                                               "\n" + result_prefix)
+        else:
+          sys.stdout.write(output)
+        sys.stdout.write(prompt)
 
     return 0
-  except (RuntimeError, socket.error) as e:
+  except (RuntimeError, socket.error, KeyboardInterrupt) as e:
     print "Fatal error: ", repr(e)
     return -1
 
diff --git a/test/box/suite.ini b/test/box/suite.ini
index 7afa15a..5d7d6dd 100644
--- a/test/box/suite.ini
+++ b/test/box/suite.ini
@@ -1,5 +1,5 @@
 [default]
 description = tarantool/silverbox, minimal configuration
-client = admin.py
+client = admin.py --prompt "" --result-prefix "r> "
 config = tarantool.cfg
 pidfile = box.pid
diff --git a/test/test-run.py b/test/test-run.py
index 7bdc62e..6054220 100755
--- a/test/test-run.py
+++ b/test/test-run.py
@@ -39,6 +39,7 @@ import time
 import collections
 import difflib
 import filecmp
+import shlex
 
 #
 # Run a collection of tests.
@@ -279,7 +280,8 @@ class Test:
     with open(self.name, "r") as test:
       with open(self.result, "w+") as result:
         self.is_client_ok = \
-          subprocess.call([self.client], stdin = test, stdout = result) == 0
+          subprocess.call(shlex.split(self.client),
+                          stdin = test, stdout = result) == 0
     
     self.is_executed = True
 

-- 
Tarantool -- an efficient key/value data store

_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to