diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/command_script/import')
16 files changed, 189 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/Makefile b/packages/Python/lldbsuite/test/functionalities/command_script/import/Makefile new file mode 100644 index 0000000..9374aef --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/Makefile @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +C_SOURCES := main.c +EXE := hello_world + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py new file mode 100644 index 0000000..691045a --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py @@ -0,0 +1,73 @@ +"""Test custom import command to import files by path.""" + +from __future__ import print_function + + + +import os, sys, time +import lldb +from lldbsuite.test.lldbtest import * + +class ImportTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(['pyapi']) + @no_debug_info_test + def test_import_command(self): + """Import some Python scripts by path and test them""" + self.run_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def run_test(self): + """Import some Python scripts by path and test them.""" + + # This is the function to remove the custom commands in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('command script delete foo2cmd', check=False) + self.runCmd('command script delete foocmd', check=False) + self.runCmd('command script delete foobarcmd', check=False) + self.runCmd('command script delete barcmd', check=False) + self.runCmd('command script delete barothercmd', check=False) + self.runCmd('command script delete TPcommandA', check=False) + self.runCmd('command script delete TPcommandB', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("command script import ./foo/foo.py --allow-reload") + self.runCmd("command script import ./foo/foo2.py --allow-reload") + self.runCmd("command script import ./foo/bar/foobar.py --allow-reload") + self.runCmd("command script import ./bar/bar.py --allow-reload") + + self.expect("command script import ./nosuchfile.py", + error=True, startstr='error: module importing failed') + self.expect("command script import ./nosuchfolder/", + error=True, startstr='error: module importing failed') + self.expect("command script import ./foo/foo.py", error=False) + + self.runCmd("command script import --allow-reload ./thepackage") + self.expect("TPcommandA",substrs=["hello world A"]) + self.expect("TPcommandB",substrs=["hello world B"]) + + self.runCmd("script import dummymodule") + self.expect("command script import ./dummymodule.py", error=False) + self.expect("command script import --allow-reload ./dummymodule.py", error=False) + + self.runCmd("command script add -f foo.foo_function foocmd") + self.runCmd("command script add -f foobar.foo_function foobarcmd") + self.runCmd("command script add -f bar.bar_function barcmd") + self.expect("foocmd hello", + substrs = ['foo says', 'hello']) + self.expect("foo2cmd hello", + substrs = ['foo2 says', 'hello']) + self.expect("barcmd hello", + substrs = ['barutil says', 'bar told me', 'hello']) + self.expect("barothercmd hello", + substrs = ['barutil says', 'bar told me', 'hello']) + self.expect("foobarcmd hello", + substrs = ['foobar says', 'hello']) diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/bar.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/bar.py new file mode 100644 index 0000000..bbc41f3 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/bar.py @@ -0,0 +1,12 @@ +from __future__ import print_function + +def bar_function(debugger, args, result, dict): + global UtilityModule + print(UtilityModule.barutil_function("bar told me " + args), file=result) + return None + +def __lldb_init_module(debugger, session_dict): + global UtilityModule + UtilityModule = __import__("barutil") + debugger.HandleCommand("command script add -f bar.bar_function barothercmd") + return None
\ No newline at end of file diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/barutil.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/barutil.py new file mode 100644 index 0000000..0d3d2eb --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/bar/barutil.py @@ -0,0 +1,2 @@ +def barutil_function(x): + return "barutil says: " + x diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/dummymodule.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/dummymodule.py new file mode 100644 index 0000000..dcc724e --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/dummymodule.py @@ -0,0 +1,2 @@ +def no_useful_code(foo): + return foo diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/bar/foobar.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/bar/foobar.py new file mode 100644 index 0000000..659ded2 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/bar/foobar.py @@ -0,0 +1,5 @@ +from __future__ import print_function + +def foo_function(debugger, args, result, dict): + print("foobar says " + args, file=result) + return None diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo.py new file mode 100644 index 0000000..51cc0c3 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo.py @@ -0,0 +1,5 @@ +from __future__ import print_function + +def foo_function(debugger, args, result, dict): + print("foo says " + args, file=result) + return None diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo2.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo2.py new file mode 100644 index 0000000..6863454 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/foo/foo2.py @@ -0,0 +1,9 @@ +from __future__ import print_function + +def foo2_function(debugger, args, result, dict): + print("foo2 says " + args, file=result) + return None + +def __lldb_init_module(debugger, session_dict): + debugger.HandleCommand("command script add -f foo2.foo2_function foo2cmd") + return None
\ No newline at end of file diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/main.c b/packages/Python/lldbsuite/test/functionalities/command_script/import/main.c new file mode 100644 index 0000000..dffc8c7 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/main.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main(int argc, char const *argv[]) { + printf("Hello world.\n"); // Set break point at this line. + if (argc == 1) + return 0; + + // Waiting to be attached by the debugger, otherwise. + char line[100]; + while (fgets(line, sizeof(line), stdin)) { // Waiting to be attached... + printf("input line=>%s\n", line); + } + + printf("Exiting now\n"); +} diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/Makefile b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/Makefile new file mode 100644 index 0000000..7913aaa --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/Makefile @@ -0,0 +1,3 @@ +LEVEL = ../../../../make + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/TestRdar12586188.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/TestRdar12586188.py new file mode 100644 index 0000000..9800a08 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/TestRdar12586188.py @@ -0,0 +1,31 @@ +"""Check that we handle an ImportError in a special way when command script importing files.""" + +from __future__ import print_function + + + +import os, sys, time +import lldb +from lldbsuite.test.lldbtest import * + +class Rdar12586188TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @add_test_categories(['pyapi']) + @no_debug_info_test + def test_rdar12586188_command(self): + """Check that we handle an ImportError in a special way when command script importing files.""" + self.run_test() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def run_test(self): + """Check that we handle an ImportError in a special way when command script importing files.""" + + self.expect("command script import ./fail12586188.py --allow-reload", + error=True, substrs = ['raise ImportError("I do not want to be imported")']) + self.expect("command script import ./fail212586188.py --allow-reload", + error=True, substrs = ['raise ValueError("I do not want to be imported")']) diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail12586188.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail12586188.py new file mode 100644 index 0000000..add85a7 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail12586188.py @@ -0,0 +1,4 @@ +def f(x): + return x + 1 + +raise ImportError("I do not want to be imported") diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail212586188.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail212586188.py new file mode 100644 index 0000000..1549a03 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/rdar-12586188/fail212586188.py @@ -0,0 +1,4 @@ +def f(x): + return x + 1 + +raise ValueError("I do not want to be imported") diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitA.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitA.py new file mode 100644 index 0000000..fb65305 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitA.py @@ -0,0 +1,6 @@ + +import six + +def command(debugger, command, result, internal_dict): + result.PutCString(six.u("hello world A")) + return None diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitB.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitB.py new file mode 100644 index 0000000..60b31b8 --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/TPunitB.py @@ -0,0 +1,6 @@ + +import six + +def command(debugger, command, result, internal_dict): + result.PutCString(six.u("hello world B")) + return None diff --git a/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/__init__.py b/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/__init__.py new file mode 100644 index 0000000..faa4e3b --- /dev/null +++ b/packages/Python/lldbsuite/test/functionalities/command_script/import/thepackage/__init__.py @@ -0,0 +1,6 @@ +import TPunitA +import TPunitB + +def __lldb_init_module(debugger,*args): + debugger.HandleCommand("command script add -f thepackage.TPunitA.command TPcommandA") + debugger.HandleCommand("command script add -f thepackage.TPunitB.command TPcommandB") |