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    # We only emulate a fake libc++ in this test and don't use the real libc++,
1499b7b41eSRaphael Isemann    # but we still add the libc++ category so that this test is only run in
1599b7b41eSRaphael Isemann    # test configurations where libc++ is actually supposed to be tested.
1699b7b41eSRaphael Isemann    @add_test_categories(["libc++"])
1799b7b41eSRaphael Isemann    @skipIf(compiler=no_match("clang"))
1866b829acSJonas Devlieghere    @skipIfRemote
1999b7b41eSRaphael Isemann    def test(self):
2099b7b41eSRaphael Isemann        # The path to our temporary target root that contains the temporary
2199b7b41eSRaphael Isemann        # module sources.
2299b7b41eSRaphael Isemann        target_sysroot = self.getBuildArtifact("root")
2399b7b41eSRaphael Isemann
2499b7b41eSRaphael Isemann        # Copy the sources to the root.
2599b7b41eSRaphael Isemann        shutil.copytree(self.getSourcePath("root"), target_sysroot)
2699b7b41eSRaphael Isemann        # Build the binary with the copied sources.
2799b7b41eSRaphael Isemann        self.build()
2899b7b41eSRaphael Isemann        # Delete the copied sources so that they are now unavailable.
2999b7b41eSRaphael Isemann        shutil.rmtree(target_sysroot)
3099b7b41eSRaphael Isemann
3199b7b41eSRaphael Isemann        # Set the sysroot where our dummy libc++ used to exist. Just to make
3299b7b41eSRaphael Isemann        # sure we don't find some existing headers on the system that could
3399b7b41eSRaphael Isemann        # XPASS this test.
3499b7b41eSRaphael Isemann        self.runCmd("platform select --sysroot '" + target_sysroot + "' host")
3599b7b41eSRaphael Isemann
36*2238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
37*2238dcc3SJonas Devlieghere            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")
38*2238dcc3SJonas Devlieghere        )
3999b7b41eSRaphael Isemann
4099b7b41eSRaphael Isemann        # Import the std C++ module and run an expression.
4199b7b41eSRaphael Isemann        # As we deleted the sources, LLDB should refuse the load the module
4299b7b41eSRaphael Isemann        # and just print the normal error we get from the expression.
4399b7b41eSRaphael Isemann        self.runCmd("settings set target.import-std-module true")
44*2238dcc3SJonas Devlieghere        self.expect(
45*2238dcc3SJonas Devlieghere            "expr v.unknown_identifier",
46*2238dcc3SJonas Devlieghere            error=True,
47*2238dcc3SJonas Devlieghere            substrs=["no member named 'unknown_identifier'"],
48*2238dcc3SJonas Devlieghere        )
4999b7b41eSRaphael Isemann        # Check that there is no confusing error about failing to build the
5099b7b41eSRaphael Isemann        # module.
51*2238dcc3SJonas Devlieghere        self.expect(
52*2238dcc3SJonas Devlieghere            "expr v.unknown_identifier",
53*2238dcc3SJonas Devlieghere            error=True,
54*2238dcc3SJonas Devlieghere            matching=False,
55*2238dcc3SJonas Devlieghere            substrs=["could not build module 'std'"],
56*2238dcc3SJonas Devlieghere        )
5799b7b41eSRaphael Isemann
5899b7b41eSRaphael Isemann        # Test the fallback mode. It should also just print the normal
5999b7b41eSRaphael Isemann        # error but not mention a failed module build.
6099b7b41eSRaphael Isemann        self.runCmd("settings set target.import-std-module fallback")
6199b7b41eSRaphael Isemann
62*2238dcc3SJonas Devlieghere        self.expect(
63*2238dcc3SJonas Devlieghere            "expr v.unknown_identifier",
64*2238dcc3SJonas Devlieghere            error=True,
65*2238dcc3SJonas Devlieghere            substrs=["no member named 'unknown_identifier'"],
66*2238dcc3SJonas Devlieghere        )
67*2238dcc3SJonas Devlieghere        self.expect(
68*2238dcc3SJonas Devlieghere            "expr v.unknown_identifier",
69*2238dcc3SJonas Devlieghere            error=True,
70*2238dcc3SJonas Devlieghere            matching=False,
71*2238dcc3SJonas Devlieghere            substrs=["could not build module 'std'"],
72*2238dcc3SJonas Devlieghere        )
73