199b7b41eSRaphael Isemann"""
299b7b41eSRaphael IsemannCheck that missing module source files are correctly handled by LLDB.
399b7b41eSRaphael Isemann"""
499b7b41eSRaphael Isemann
599b7b41eSRaphael Isemannfrom lldbsuite.test.decorators import *
699b7b41eSRaphael Isemannfrom lldbsuite.test.lldbtest import *
799b7b41eSRaphael Isemannfrom lldbsuite.test import lldbutil
899b7b41eSRaphael Isemannimport os
999b7b41eSRaphael Isemannimport shutil
1099b7b41eSRaphael Isemann
1199b7b41eSRaphael Isemann
1299b7b41eSRaphael Isemannclass TestCase(TestBase):
1399b7b41eSRaphael Isemann
1499b7b41eSRaphael Isemann    # We only emulate a fake libc++ in this test and don't use the real libc++,
1599b7b41eSRaphael Isemann    # but we still add the libc++ category so that this test is only run in
1699b7b41eSRaphael Isemann    # test configurations where libc++ is actually supposed to be tested.
1799b7b41eSRaphael Isemann    @add_test_categories(["libc++"])
1899b7b41eSRaphael Isemann    @skipIf(compiler=no_match("clang"))
19*66b829acSJonas Devlieghere    @skipIfRemote
2099b7b41eSRaphael Isemann    def test(self):
2199b7b41eSRaphael Isemann        # The path to our temporary target root that contains the temporary
2299b7b41eSRaphael Isemann        # module sources.
2399b7b41eSRaphael Isemann        target_sysroot = self.getBuildArtifact("root")
2499b7b41eSRaphael Isemann
2599b7b41eSRaphael Isemann        # Copy the sources to the root.
2699b7b41eSRaphael Isemann        shutil.copytree(self.getSourcePath("root"), target_sysroot)
2799b7b41eSRaphael Isemann        # Build the binary with the copied sources.
2899b7b41eSRaphael Isemann        self.build()
2999b7b41eSRaphael Isemann        # Delete the copied sources so that they are now unavailable.
3099b7b41eSRaphael Isemann        shutil.rmtree(target_sysroot)
3199b7b41eSRaphael Isemann
3299b7b41eSRaphael Isemann        # Set the sysroot where our dummy libc++ used to exist. Just to make
3399b7b41eSRaphael Isemann        # sure we don't find some existing headers on the system that could
3499b7b41eSRaphael Isemann        # XPASS this test.
3599b7b41eSRaphael Isemann        self.runCmd("platform select --sysroot '" + target_sysroot + "' host")
3699b7b41eSRaphael Isemann
3799b7b41eSRaphael Isemann        lldbutil.run_to_source_breakpoint(self,
3899b7b41eSRaphael Isemann                                          "// Set break point at this line.",
3999b7b41eSRaphael Isemann                                          lldb.SBFileSpec("main.cpp"))
4099b7b41eSRaphael Isemann
4199b7b41eSRaphael Isemann        # Import the std C++ module and run an expression.
4299b7b41eSRaphael Isemann        # As we deleted the sources, LLDB should refuse the load the module
4399b7b41eSRaphael Isemann        # and just print the normal error we get from the expression.
4499b7b41eSRaphael Isemann        self.runCmd("settings set target.import-std-module true")
4599b7b41eSRaphael Isemann        self.expect("expr v.unknown_identifier", error=True,
4699b7b41eSRaphael Isemann                    substrs=["no member named 'unknown_identifier'"])
4799b7b41eSRaphael Isemann        # Check that there is no confusing error about failing to build the
4899b7b41eSRaphael Isemann        # module.
4999b7b41eSRaphael Isemann        self.expect("expr v.unknown_identifier", error=True, matching=False,
5099b7b41eSRaphael Isemann                    substrs=["could not build module 'std'"])
5199b7b41eSRaphael Isemann
5299b7b41eSRaphael Isemann        # Test the fallback mode. It should also just print the normal
5399b7b41eSRaphael Isemann        # error but not mention a failed module build.
5499b7b41eSRaphael Isemann        self.runCmd("settings set target.import-std-module fallback")
5599b7b41eSRaphael Isemann
5699b7b41eSRaphael Isemann        self.expect("expr v.unknown_identifier", error=True,
5799b7b41eSRaphael Isemann                     substrs=["no member named 'unknown_identifier'"])
5899b7b41eSRaphael Isemann        self.expect("expr v.unknown_identifier", error=True, matching=False,
5999b7b41eSRaphael Isemann                    substrs=["could not build module 'std'"])
60