test-prettyprinters.py (1652B)
1 # Ignore flake8 errors "undefined name 'assert_pretty'" 2 # As it caused by the way we instanciate this file 3 # flake8: noqa: F821 4 5 import mozilla.prettyprinters 6 7 run_fragment("prettyprinters.implemented_types") 8 9 10 def implemented_type_names(expr): 11 v = gdb.parse_and_eval(expr) 12 it = mozilla.prettyprinters.implemented_types(v.type) 13 return [str(_) for _ in it] 14 15 16 assert_eq(implemented_type_names("i"), ["int"]) 17 assert_eq(implemented_type_names("a"), ["A", "int"]) 18 assert_eq(implemented_type_names("b"), ["B", "A", "int"]) 19 assert_eq(implemented_type_names("c"), ["C"]) 20 assert_eq(implemented_type_names("c_"), ["C_", "C"]) 21 assert_eq(implemented_type_names("e"), ["E", "C", "D"]) 22 assert_eq(implemented_type_names("e_"), ["E_", "E", "C", "D"]) 23 24 # Some compilers strip trivial typedefs in the debuginfo from classes' base 25 # classes. Sometimes this can be fixed with -fno-eliminate-unused-debug-types, 26 # but not always. Allow this test to pass if the typedefs are stripped. 27 # 28 # It would probably be better to figure out how to make the compiler emit them, 29 # since I think this test is here for a reason. 30 if gdb.lookup_type("F").fields()[0].name == "C_": 31 # We have the typedef info. 32 assert_eq(implemented_type_names("f"), ["F", "C_", "D_", "C", "D"]) 33 assert_eq(implemented_type_names("h"), ["H", "F", "G", "C_", "D_", "C", "D"]) 34 else: 35 assert_eq(implemented_type_names("f"), ["F", "C", "D"]) 36 assert_eq(implemented_type_names("h"), ["H", "F", "G", "C", "D"]) 37 38 # Check that our pretty-printers aren't interfering with printing other types. 39 assert_pretty("10", "10") 40 assert_pretty("(void*) 0", "") # Because of 'set print address off'