1"""
2Tests that bool types work
3"""
4import lldb
5from lldbtest import *
6import lldbutil
7
8class CPPBoolTestCase(TestBase):
9
10    mydir = os.path.join("lang", "cpp", "bool")
11
12    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
13    @dsym_test
14    def test_with_dsym_and_run_command(self):
15        """Test that bool types work in the expression parser"""
16        self.buildDsym()
17        self.static_method_commands()
18
19    @expectedFailureFreeBSD('llvm.org/pr16697') # Expression fails with 'there is no JIT compiled function'
20    @dwarf_test
21    def test_with_dwarf_and_run_command(self):
22        """Test that bool types work in the expression parser"""
23        self.buildDwarf()
24        self.static_method_commands()
25
26    def setUp(self):
27        TestBase.setUp(self)
28
29    def set_breakpoint(self, line):
30        # Some compilers (for example GCC 4.4.7 and 4.6.1) emit multiple locations for the statement with the ternary
31        # operator in the test program, while others emit only 1.
32        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, num_expected_locations=-1, loc_exact=False)
33
34    def static_method_commands(self):
35        """Test that bool types work in the expression parser"""
36        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
37
38        self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
39
40        self.runCmd("process launch", RUN_SUCCEEDED)
41
42        self.expect("expression -- bool second_bool = my_bool; second_bool",
43                    startstr = "(bool) $0 = false")
44
45        self.expect("expression -- my_bool = true",
46                    startstr = "(bool) $1 = true")
47
48if __name__ == '__main__':
49    import atexit
50    lldb.SBDebugger.Initialize()
51    atexit.register(lambda: lldb.SBDebugger.Terminate())
52    unittest2.main()
53