Files
clang-p2996/lldb/test/functionalities/command_script/import/TestImport.py
Enrico Granata e0c70f1b2c <rdar://problem/11109316>
command script import now does reloads - for real
If you invoke command script import foo and it detects that foo has already been imported, it will
 - invoke reload(foo) to reload the module in Python
 - re-invoke foo.__lldb_init_module
 This second step is necessary to ensure that LLDB does not keep cached copies of any formatter, command, ... that the module is providing

Usual caveats with Python imports persist. Among these:
 - if you have objects lurking around, reloading the module won't magically update them to reflect changes
 - if module A imports module B, reloading A won't reload B
These are Python-specific issues independent of LLDB that would require more extensive design work

The --allow-reload (-r) option is maintained for compatibility with existing scripts, but is clearly documented as redundant - reloading is always enabled whether you use it or not

llvm-svn: 182977
2013-05-31 01:03:09 +00:00

78 lines
3.2 KiB
Python

"""Test custom import command to import files by path."""
import os, sys, time
import unittest2
import lldb
from lldbtest import *
class ImportTestCase(TestBase):
mydir = os.path.join("functionalities", "command_script", "import")
@python_api_test
@skipIfLinux # causes buildbot failures, skip until we can investigate it
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'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()