~pali/llvm/lldb-trunk

« back to all changes in this revision

Viewing changes to packages/Python/lldbsuite/test/commands/expression/static-initializers/TestStaticInitializers.py

  • Committer: teemperor
  • Date: 2019-10-21 16:07:45 UTC
  • Revision ID: svn-v4:91177308-0d34-0410-b5e6-96231b3b80d8:lldb/trunk:375422
[lldb] Add test for executing static initializers in expression command

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import lldb
 
2
from lldbsuite.test.decorators import *
 
3
from lldbsuite.test.lldbtest import *
 
4
from lldbsuite.test import lldbutil
 
5
 
 
6
class StaticInitializers(TestBase):
 
7
 
 
8
    mydir = TestBase.compute_mydir(__file__)
 
9
 
 
10
    def test(self):
 
11
        """ Test a static initializer. """
 
12
        self.build()
 
13
 
 
14
        lldbutil.run_to_source_breakpoint(self, '// break here',
 
15
                lldb.SBFileSpec("main.cpp", False))
 
16
 
 
17
        # We use counter to observe if the initializer was called.
 
18
        self.expect("expr counter", substrs=["(int) $", " = 0"])
 
19
        self.expect("expr -p -- struct Foo { Foo() { inc_counter(); } }; Foo f;")
 
20
        self.expect("expr counter", substrs=["(int) $", " = 1"])
 
21
 
 
22
    def test_failing_init(self):
 
23
        """ Test a static initializer that fails to execute. """
 
24
        self.build()
 
25
 
 
26
        lldbutil.run_to_source_breakpoint(self, '// break here',
 
27
                lldb.SBFileSpec("main.cpp", False))
 
28
 
 
29
        # FIXME: This error message is not even remotely helpful.
 
30
        self.expect("expr -p -- struct Foo2 { Foo2() { do_abort(); } }; Foo2 f;", error=True,
 
31
                    substrs=["error: couldn't run static initializers: couldn't run static initializer:"])