@@ -1575,6 +1575,58 @@ func testCallFunctionIntl(t *testing.T, grp *proc.TargetGroup, p *proc.Target, t
15751575 }
15761576}
15771577
1578+ func TestIssue4051 (t * testing.T ) {
1579+ protest .MustSupportFunctionCalls (t , testBackend )
1580+ protest .AllowRecording (t )
1581+ withTestProcess ("issue4051" , t , func (p * proc.Target , grp * proc.TargetGroup , fixture protest.Fixture ) {
1582+ err := grp .Continue ()
1583+ assertNoError (err , t , "initial continue to breakpoint failed" )
1584+
1585+ err = proc .EvalExpressionWithCalls (grp , p .SelectedGoroutine (), `main.Hello("world")` , pnormalLoadConfig , true )
1586+ if err == nil {
1587+ t .Fatal ("expected error, got nil" )
1588+ }
1589+ expectedError := "package main has no function Hello"
1590+ if err .Error () != expectedError {
1591+ t .Fatalf ("expected error %q, got %q" , expectedError , err )
1592+ }
1593+
1594+ err = grp .Continue ()
1595+ assertNoError (err , t , "initial continue to breakpoint failed" )
1596+
1597+ err = proc .EvalExpressionWithCalls (grp , p .SelectedGoroutine (), `main.Hello("world")` , pnormalLoadConfig , true )
1598+ if err == nil {
1599+ t .Fatal ("expected error, got nil" )
1600+ }
1601+ expectedError = `expression "main.Hello" is not a function`
1602+ if err .Error () != expectedError {
1603+ t .Fatalf ("expected error %q, got %q" , expectedError , err )
1604+ }
1605+
1606+ v , err := evalVariableWithCfg (p , "main.Hello" , pshortLoadConfig )
1607+ assertNoError (err , t , "eval of main.Hello returned an error" )
1608+ assertVariable (t , v , varTest {"main.Hello" , true , `"World"` , `` , `string` , nil })
1609+
1610+ v , err = evalVariableWithCfg (p , "os.a" , pshortLoadConfig )
1611+ assertNoError (err , t , "eval of os.a returned an error" )
1612+ assertVariable (t , v , varTest {"os.a" , true , "1" , `` , `int` , nil })
1613+
1614+ // TODO(deparker): we *should* get an error here, but the one we expect in this test
1615+ // is not the ideal error. We should really improve type checking in the evaluator.
1616+ v , err = evalVariableWithCfg (p , "main.f.func1.i" , pshortLoadConfig )
1617+ expectedError = `main.f has no member func1`
1618+ if err .Error () != expectedError {
1619+ t .Fatalf ("expected error %q, got %q" , expectedError , err )
1620+ }
1621+
1622+ _ , err = evalVariableWithCfg (p , "main.f.func1.somethingthatdoesntexist" , pshortLoadConfig )
1623+ expectedError = `main.f has no member func1`
1624+ if err .Error () != expectedError {
1625+ t .Fatalf ("expected error %q, got %q" , expectedError , err )
1626+ }
1627+ })
1628+ }
1629+
15781630func TestIssue1531 (t * testing.T ) {
15791631 // Go 1.12 introduced a change to the map representation where empty cells can be marked with 1 instead of just 0.
15801632 withTestProcess ("issue1531" , t , func (p * proc.Target , grp * proc.TargetGroup , fixture protest.Fixture ) {
0 commit comments