1""" 2Test default template arguments. 3""" 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10class TestDefaultTemplateArgs(TestBase): 11 12 mydir = TestBase.compute_mydir(__file__) 13 14 @no_debug_info_test 15 def test(self): 16 self.build() 17 lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp")) 18 19 # Declare a template with a template argument that has a default argument. 20 self.expect("expr --top-level -- template<typename T = int> struct $X { int v; };") 21 22 # The type we display to the user should omit the argument with the default 23 # value. 24 result = self.expect_expr("$X<> x; x", result_type="$X<>") 25 # The internal name should also always show all arguments (even if they 26 # have their default value). 27 self.assertEqual(result.GetTypeName(), "$X<int>") 28 29 # Test the template but this time specify a non-default value for the 30 # template argument. 31 # Both internal type name and the one we display to the user should 32 # show the non-default value in the type name. 33 result = self.expect_expr("$X<long> x; x", result_type="$X<long>") 34 self.assertEqual(result.GetTypeName(), "$X<long>") 35 36 # Test that the formatters are using the internal type names that 37 # always include all template arguments. 38 self.expect("type summary add '$X<int>' --summary-string 'summary1'") 39 self.expect_expr("$X<> x; x", result_summary="summary1") 40 self.expect("type summary add '$X<long>' --summary-string 'summary2'") 41 self.expect_expr("$X<long> x; x", result_summary="summary2") 42