199451b44SJordan Rupprecht"""Test custom import command to import files by path."""
299451b44SJordan Rupprecht
399451b44SJordan Rupprecht
499451b44SJordan Rupprecht
599451b44SJordan Rupprechtimport lldb
699451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
799451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
899451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprechtclass ImportTestCase(TestBase):
1299451b44SJordan Rupprecht
1399451b44SJordan Rupprecht    @add_test_categories(['pyapi'])
1499451b44SJordan Rupprecht    @no_debug_info_test
1599451b44SJordan Rupprecht    def test_import_command(self):
1699451b44SJordan Rupprecht        """Import some Python scripts by path and test them"""
1799451b44SJordan Rupprecht        self.run_test()
1899451b44SJordan Rupprecht
1999451b44SJordan Rupprecht    def run_test(self):
2099451b44SJordan Rupprecht        """Import some Python scripts by path and test them."""
2199451b44SJordan Rupprecht
2299451b44SJordan Rupprecht        # This is the function to remove the custom commands in order to have a
2399451b44SJordan Rupprecht        # clean slate for the next test case.
2499451b44SJordan Rupprecht        def cleanup():
2599451b44SJordan Rupprecht            self.runCmd('command script delete foo2cmd', check=False)
2699451b44SJordan Rupprecht            self.runCmd('command script delete foocmd', check=False)
2799451b44SJordan Rupprecht            self.runCmd('command script delete foobarcmd', check=False)
2899451b44SJordan Rupprecht            self.runCmd('command script delete barcmd', check=False)
2999451b44SJordan Rupprecht            self.runCmd('command script delete barothercmd', check=False)
3099451b44SJordan Rupprecht            self.runCmd('command script delete TPcommandA', check=False)
3199451b44SJordan Rupprecht            self.runCmd('command script delete TPcommandB', check=False)
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht        # Execute the cleanup function during test case tear down.
3499451b44SJordan Rupprecht        self.addTearDownHook(cleanup)
3599451b44SJordan Rupprecht
3699451b44SJordan Rupprecht        self.runCmd("command script import ./foo/foo.py --allow-reload")
3799451b44SJordan Rupprecht        self.runCmd("command script import ./foo/foo2.py --allow-reload")
3899451b44SJordan Rupprecht        self.runCmd("command script import ./foo/bar/foobar.py --allow-reload")
3999451b44SJordan Rupprecht        self.runCmd("command script import ./bar/bar.py --allow-reload")
4099451b44SJordan Rupprecht
41*e83d47f6SJim Ingham        self.expect("command script import ''",
42*e83d47f6SJim Ingham                    error=True, startstr="error: module importing failed: empty path")
4399451b44SJordan Rupprecht        self.expect("command script import ./nosuchfile.py",
44*e83d47f6SJim Ingham                    error=True, startstr="error: module importing failed: invalid pathname './nosuchfile.py'")
4599451b44SJordan Rupprecht        self.expect("command script import ./nosuchfolder/",
46*e83d47f6SJim Ingham                    error=True, startstr="error: module importing failed: invalid pathname './nosuchfolder/'")
4799451b44SJordan Rupprecht        self.expect("command script import ./foo/foo.py", error=False)
4899451b44SJordan Rupprecht        self.runCmd("command script import --allow-reload ./thepackage")
4999451b44SJordan Rupprecht        self.expect("TPcommandA", substrs=["hello world A"])
5099451b44SJordan Rupprecht        self.expect("TPcommandB", substrs=["hello world B"])
5199451b44SJordan Rupprecht
5299451b44SJordan Rupprecht        self.runCmd("script import dummymodule")
5399451b44SJordan Rupprecht        self.expect("command script import ./dummymodule.py", error=False)
5499451b44SJordan Rupprecht        self.expect(
5599451b44SJordan Rupprecht            "command script import --allow-reload ./dummymodule.py",
5699451b44SJordan Rupprecht            error=False)
5799451b44SJordan Rupprecht
5899451b44SJordan Rupprecht        self.runCmd("command script add -f foo.foo_function foocmd")
5999451b44SJordan Rupprecht        self.runCmd("command script add -f foobar.foo_function foobarcmd")
6099451b44SJordan Rupprecht        self.runCmd("command script add -f bar.bar_function barcmd")
6199451b44SJordan Rupprecht        self.expect("foocmd hello",
6299451b44SJordan Rupprecht                    substrs=['foo says', 'hello'])
6399451b44SJordan Rupprecht        self.expect("foo2cmd hello",
6499451b44SJordan Rupprecht                    substrs=['foo2 says', 'hello'])
6599451b44SJordan Rupprecht        self.expect("barcmd hello",
6699451b44SJordan Rupprecht                    substrs=['barutil says', 'bar told me', 'hello'])
6799451b44SJordan Rupprecht        self.expect("barothercmd hello",
6899451b44SJordan Rupprecht                    substrs=['barutil says', 'bar told me', 'hello'])
6999451b44SJordan Rupprecht        self.expect("foobarcmd hello",
7099451b44SJordan Rupprecht                    substrs=['foobar says', 'hello'])
71