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
10class TestCase(TestBase):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    @skipUnlessDarwin
15    def test(self):
16        self.build()
17        lldbutil.run_to_source_breakpoint(self,"// break here", lldb.SBFileSpec("main.c"))
18
19        # Import foundation to get some ObjC types.
20        self.expect("expr --lang objc -- @import Foundation")
21        # Do something with NSString (which requires special handling when
22        # preparing to run in the target). The expression most likely can't
23        # be prepared to run in the target but it should at least not crash LLDB.
24        self.expect('expr --lang objc -- [NSString stringWithFormat:@"%d", 1];',
25                    error=True,
26                    substrs=["Rewriting an Objective-C constant string requires CFStringCreateWithBytes"])
27