xref: /llvm-project/lldb/test/API/lang/objc/modules-non-objc-target/TestObjCModulesNonObjCTarget.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Tests that importing ObjC modules in a non-ObjC target doesn't crash LLDB.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestCase(TestBase):
12    def test(self):
13        self.build()
14        lldbutil.run_to_source_breakpoint(
15            self, "// break here", lldb.SBFileSpec("main.c")
16        )
17
18        # Import foundation to get some ObjC types.
19        self.expect("expr --lang objc -- @import Foundation")
20        # Do something with NSString (which requires special handling when
21        # preparing to run in the target). The expression most likely can't
22        # be prepared to run in the target but it should at least not crash LLDB.
23        self.expect(
24            'expr --lang objc -- [NSString stringWithFormat:@"%d", 1];',
25            error=True,
26            substrs=[
27                "Rewriting an Objective-C constant string requires CFStringCreateWithBytes"
28            ],
29        )
30