Added TestArrayTypes.py for test/array_types directory.

Also modified dotest.py so that it sets the LLDB_TEST environment variable
so that individual test cases can locate their supporting files correctly.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@107220 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/array_types/TestArrayTypes.py b/test/array_types/TestArrayTypes.py
new file mode 100644
index 0000000..8b626a6
--- /dev/null
+++ b/test/array_types/TestArrayTypes.py
@@ -0,0 +1,79 @@
+"""Test breakpoint by file/line number; and list variables with array types."""
+
+import os
+import lldb
+import unittest
+
+class TestArrayTypes(unittest.TestCase):
+
+    def setUp(self):
+        # Save old working directory.
+        self.oldcwd = os.getcwd()
+        # Change current working directory if ${LLDB_TEST} is defined.
+        if ("LLDB_TEST" in os.environ):
+            os.chdir(os.path.join(os.environ["LLDB_TEST"], "array_types"));
+        self.dbg = lldb.SBDebugger.Create()
+        self.dbg.SetAsync(False)
+        self.ci = self.dbg.GetCommandInterpreter()
+        if not self.ci:
+            raise Exception('Could not get the command interpreter')
+
+    def tearDown(self):
+        # Restore old working directory.
+        os.chdir(self.oldcwd)
+
+    def test_array_types(self):
+        """Test 'variable list var_name' on some variables with array types."""
+        res = lldb.SBCommandReturnObject()
+        self.ci.HandleCommand("file a.out", res)
+        self.assertTrue(res.Succeeded())
+        self.ci.HandleCommand("breakpoint set -f main.c -l 42", res)
+        self.assertTrue(res.Succeeded())
+        self.assertTrue(res.GetOutput().startswith(
+            "Breakpoint created: 1: file ='main.c', line = 42, locations = 1"))
+
+        self.ci.HandleCommand("run", res)
+        self.assertTrue(res.Succeeded())
+
+        self.ci.HandleCommand("breakpoint list", res)
+        self.assertTrue(res.Succeeded())
+        self.assertTrue(res.GetOutput().find('resolved, hit count = 1'))
+
+        self.ci.HandleCommand("thread list", res)
+        self.assertTrue(res.Succeeded())
+        self.assertTrue(res.GetOutput().find('state is Stopped') and
+                        res.GetOutput().find('stop reason = breakpoint'))
+
+        self.ci.HandleCommand("variable list strings", res);
+        self.assertTrue(res.Succeeded())
+        self.assertTrue(res.GetOutput().startswith('(char *[4])') and
+                        res.GetOutput().find('(char *) strings[0]') and
+                        res.GetOutput().find('(char *) strings[1]') and
+                        res.GetOutput().find('(char *) strings[2]') and
+                        res.GetOutput().find('(char *) strings[3]') and
+                        res.GetOutput().find('Hello') and
+                        res.GetOutput().find('Hola') and
+                        res.GetOutput().find('Bonjour') and
+                        res.GetOutput().find('Guten Tag'))
+
+        self.ci.HandleCommand("variable list char_16", res);
+        self.assertTrue(res.Succeeded())
+        self.assertTrue(res.GetOutput().find('(char) char_16[0]') and
+                        res.GetOutput().find('(char) char_16[15]'))
+
+        self.ci.HandleCommand("variable list ushort_matrix", res);
+        self.assertTrue(res.Succeeded())
+        self.assertTrue(res.GetOutput().startswith('(unsigned short [2][3])'))
+
+        self.ci.HandleCommand("variable list long_6", res);
+        self.assertTrue(res.Succeeded())
+        self.assertTrue(res.GetOutput().startswith('(long [6])'))
+
+        self.ci.HandleCommand("continue", res)
+        self.assertTrue(res.Succeeded())
+
+
+if __name__ == '__main__':
+    lldb.SBDebugger.Initialize()
+    unittest.main()
+    lldb.SBDebugger.Terminate()
diff --git a/test/array_types/main.c b/test/array_types/main.c
index b6eaf4b..f395df5 100644
--- a/test/array_types/main.c
+++ b/test/array_types/main.c
@@ -27,7 +27,7 @@
     short short_4[4] = { 1,2,3,4 };
     short short_matrix[1][2] = { {1,2} };
     unsigned short ushort_4[4] = { 1,2,3,4 };
-    short ushort_matrix[2][3] = {
+    unsigned short ushort_matrix[2][3] = {
         { 1, 2, 3},
         {11,22,33}
     };
diff --git a/test/dotest.py b/test/dotest.py
index 9d51816..3ab116b 100755
--- a/test/dotest.py
+++ b/test/dotest.py
@@ -42,6 +42,9 @@
 and:
 args : specify a list of directory names to search for python Test*.py scripts
        if empty, search from the curret working directory, instead
+
+Running of this script also sets up the LLDB_TEST environment variable so that
+individual test cases can locate their supporting files correctly.
 """
 
 
@@ -54,6 +57,8 @@
         print "This script expects to reside in lldb's test directory."
         sys.exit(-1)
 
+    os.environ["LLDB_TEST"] = testPath
+
     base = os.path.abspath(os.path.join(testPath, os.pardir))
     dbgPath = os.path.join(base, 'build', 'Debug', 'LLDB.framework',
                            'Resources', 'Python')
diff --git a/test/help/TestHelp.py b/test/help/TestHelp.py
index 5b006ef..56ec504 100644
--- a/test/help/TestHelp.py
+++ b/test/help/TestHelp.py
@@ -1,19 +1,26 @@
 """Test lldb help command."""
 
+import os
 import lldb
 import unittest
 
 class TestHelpCommand(unittest.TestCase):
 
     def setUp(self):
-        self.debugger = lldb.SBDebugger.Create()
-        self.debugger.SetAsync(False)
-        self.ci = self.debugger.GetCommandInterpreter()
+        # Save old working directory.
+        self.oldcwd = os.getcwd()
+        # Change current working directory if ${LLDB_TEST} is defined.
+        if ("LLDB_TEST" in os.environ):
+            os.chdir(os.path.join(os.environ["LLDB_TEST"], "help"));
+        self.dbg = lldb.SBDebugger.Create()
+        self.dbg.SetAsync(False)
+        self.ci = self.dbg.GetCommandInterpreter()
         if not self.ci:
             raise Exception('Could not get the command interpreter')
 
     def tearDown(self):
-        pass
+        # Restore old working directory.
+        os.chdir(self.oldcwd)
 
     def test_simplehelp(self):
         """A simple test of 'help' command and its output."""
@@ -22,7 +29,6 @@
         self.assertTrue(res.Succeeded())
         self.assertTrue(res.GetOutput().startswith(
             'The following is a list of built-in, permanent debugger commands'))
-        #print res.GetOutput()
 
     def test_help_should_not_hang_emacsshell(self):
         """'set term-width 0' should not hang the help command."""
@@ -33,7 +39,6 @@
         self.assertTrue(res.Succeeded())
         self.assertTrue(res.GetOutput().startswith(
             'The following is a list of built-in, permanent debugger commands'))
-        #print res.GetOutput()
 
 
 if __name__ == '__main__':