Skip to content

Commit

Permalink
service/dap: add test that verifies output path is relative to wd (go…
Browse files Browse the repository at this point in the history
…-delve#2656)

* service/dap: add test that verifies output path is relative to wd

* Use cleanExeName to get the right output name on Win

Co-authored-by: Polina Sokolova <[email protected]>
  • Loading branch information
polinasok and polinasok authored Aug 17, 2021
1 parent 694b45c commit a4d416d
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions service/dap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4059,9 +4059,8 @@ func TestLaunchDebugRequest(t *testing.T) {
// We reuse the harness that builds, but ignore the built binary,
// only relying on the source to be built in response to LaunchRequest.
runDebugSession(t, client, "launch", func() {
wd, _ := os.Getwd()
client.LaunchRequestWithArgs(map[string]interface{}{
"mode": "debug", "program": fixture.Source, "output": filepath.Join(wd, tmpBin)})
"mode": "debug", "program": fixture.Source, "output": tmpBin})
}, fixture.Source)
})
// Wait for the test to finish to capture all stderr
Expand All @@ -4084,6 +4083,7 @@ func TestLaunchDebugRequest(t *testing.T) {
t.Fatalf("Binary removal failure:\n%s\n", rmErr)
}
} else {
tmpBin = cleanExeName(tmpBin)
// We did not get a removal error, but did we even try to remove before exiting?
// Confirm that the binary did get removed.
if _, err := os.Stat(tmpBin); err == nil || os.IsExist(err) {
Expand All @@ -4102,7 +4102,6 @@ func TestLaunchRequestDefaults(t *testing.T) {
})
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
runDebugSession(t, client, "launch", func() {
// Use the default output directory.
client.LaunchRequestWithArgs(map[string]interface{}{
/*"mode":"debug" by default*/ "program": fixture.Source, "output": "__mybin"})
}, fixture.Source)
Expand All @@ -4125,6 +4124,33 @@ func TestLaunchRequestDefaults(t *testing.T) {
})
}

// TestLaunchRequestOutputPath verifies that relative output binary path
// is mapped to server's, not target's, working directory.
func TestLaunchRequestOutputPath(t *testing.T) {
runTest(t, "testargs", func(client *daptest.Client, fixture protest.Fixture) {
inrel := "__somebin"
wd, _ := os.Getwd()
outabs := cleanExeName(filepath.Join(wd, inrel))
runDebugSessionWithBPs(t, client, "launch",
// Launch
func() {
client.LaunchRequestWithArgs(map[string]interface{}{
"mode": "debug", "program": fixture.Source, "output": inrel,
"cwd": filepath.Dir(wd)})
},
// Set breakpoints
fixture.Source, []int{12},
[]onBreakpoint{{
execute: func() {
checkStop(t, client, 1, "main.main", 12)
client.EvaluateRequest("os.Args[0]", 1000, "repl")
checkEval(t, client.ExpectEvaluateResponse(t), fmt.Sprintf("%q", outabs), noChildren)
},
disconnect: true,
}})
})
}

func TestNoDebug_GoodExitStatus(t *testing.T) {
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
runNoDebugSession(t, client, func() {
Expand Down

0 comments on commit a4d416d

Please sign in to comment.