Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
3ffbe2d7
D
delve
项目概览
HugeYuan
/
delve
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
delve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3ffbe2d7
编写于
4月 27, 2015
作者:
D
Dan Mace
提交者:
Derek Parker
4月 29, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Precompile fixtures
上级
2954e03a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
35 deletion
+51
-35
service/rest/integration_test.go
service/rest/integration_test.go
+51
-35
未找到文件。
service/rest/integration_test.go
浏览文件 @
3ffbe2d7
...
@@ -3,36 +3,59 @@ package rest
...
@@ -3,36 +3,59 @@ package rest
import
(
import
(
"crypto/rand"
"crypto/rand"
"encoding/hex"
"encoding/hex"
"fmt"
"io/ioutil"
"net"
"net"
"os"
"os"
"os/exec"
"os/exec"
"path/filepath"
"path/filepath"
"strings"
"testing"
"testing"
"github.com/derekparker/delve/service"
"github.com/derekparker/delve/service"
"github.com/derekparker/delve/service/api"
"github.com/derekparker/delve/service/api"
)
)
const
(
var
fixtures
map
[
string
]
string
=
make
(
map
[
string
]
string
)
continuetestprog
=
"../../_fixtures/continuetestprog"
testprog
=
"../../_fixtures/testprog"
testnextprog
=
"../../_fixtures/testnextprog"
testthreads
=
"../../_fixtures/testthreads"
)
func
withTestClient
(
name
string
,
t
*
testing
.
T
,
fn
func
(
c
service
.
Client
))
{
func
TestMain
(
m
*
testing
.
M
)
{
// Make a (good enough) random temporary file name
fixturesDir
:=
"../../_fixtures"
r
:=
make
([]
byte
,
4
)
sources
,
err
:=
ioutil
.
ReadDir
(
fixturesDir
)
rand
.
Read
(
r
)
if
err
!=
nil
{
file
:=
filepath
.
Join
(
os
.
TempDir
(),
filepath
.
Base
(
name
)
+
hex
.
EncodeToString
(
r
))
fmt
.
Printf
(
"Couldn't read fixtures dir: %v
\n
"
,
err
)
os
.
Exit
(
1
)
// Build the test binary
if
err
:=
exec
.
Command
(
"go"
,
"build"
,
"-gcflags=-N -l"
,
"-o"
,
file
,
name
+
".go"
)
.
Run
();
err
!=
nil
{
t
.
Fatalf
(
"Could not compile %s due to %s"
,
name
,
err
)
}
}
t
.
Logf
(
"Compiled test binary %s"
,
file
)
defer
os
.
Remove
(
file
)
for
_
,
src
:=
range
sources
{
if
src
.
IsDir
()
{
continue
}
// Make a (good enough) random temporary file name
r
:=
make
([]
byte
,
4
)
rand
.
Read
(
r
)
path
:=
filepath
.
Join
(
fixturesDir
,
src
.
Name
())
name
:=
strings
.
TrimSuffix
(
src
.
Name
(),
filepath
.
Ext
(
src
.
Name
()))
tmpfile
:=
filepath
.
Join
(
os
.
TempDir
(),
fmt
.
Sprintf
(
"%s.%s"
,
name
,
hex
.
EncodeToString
(
r
)))
// Build the test binary
if
err
:=
exec
.
Command
(
"go"
,
"build"
,
"-gcflags=-N -l"
,
"-o"
,
tmpfile
,
path
)
.
Run
();
err
!=
nil
{
fmt
.
Printf
(
"Error compiling %s: %s
\n
"
,
path
,
err
)
os
.
Exit
(
1
)
}
fmt
.
Printf
(
"Compiled test binary %s: %s
\n
"
,
name
,
tmpfile
)
fixtures
[
name
]
=
tmpfile
}
status
:=
m
.
Run
()
for
_
,
f
:=
range
fixtures
{
os
.
Remove
(
f
)
}
os
.
Exit
(
status
)
}
func
withTestClient
(
name
string
,
t
*
testing
.
T
,
fn
func
(
c
service
.
Client
))
{
listener
,
err
:=
net
.
Listen
(
"tcp"
,
"localhost:0"
)
listener
,
err
:=
net
.
Listen
(
"tcp"
,
"localhost:0"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't start listener: %s
\n
"
,
err
)
t
.
Fatalf
(
"couldn't start listener: %s
\n
"
,
err
)
...
@@ -40,7 +63,7 @@ func withTestClient(name string, t *testing.T, fn func(c service.Client)) {
...
@@ -40,7 +63,7 @@ func withTestClient(name string, t *testing.T, fn func(c service.Client)) {
server
:=
NewServer
(
&
Config
{
server
:=
NewServer
(
&
Config
{
Listener
:
listener
,
Listener
:
listener
,
ProcessArgs
:
[]
string
{
fi
le
},
ProcessArgs
:
[]
string
{
fi
xtures
[
name
]
},
})
})
go
server
.
Run
()
go
server
.
Run
()
...
@@ -51,7 +74,7 @@ func withTestClient(name string, t *testing.T, fn func(c service.Client)) {
...
@@ -51,7 +74,7 @@ func withTestClient(name string, t *testing.T, fn func(c service.Client)) {
}
}
func
TestClientServer_exit
(
t
*
testing
.
T
)
{
func
TestClientServer_exit
(
t
*
testing
.
T
)
{
withTestClient
(
continuetestprog
,
t
,
func
(
c
service
.
Client
)
{
withTestClient
(
"continuetestprog"
,
t
,
func
(
c
service
.
Client
)
{
state
,
err
:=
c
.
GetState
()
state
,
err
:=
c
.
GetState
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
...
@@ -73,7 +96,7 @@ func TestClientServer_exit(t *testing.T) {
...
@@ -73,7 +96,7 @@ func TestClientServer_exit(t *testing.T) {
}
}
func
TestClientServer_step
(
t
*
testing
.
T
)
{
func
TestClientServer_step
(
t
*
testing
.
T
)
{
withTestClient
(
testprog
,
t
,
func
(
c
service
.
Client
)
{
withTestClient
(
"testprog"
,
t
,
func
(
c
service
.
Client
)
{
_
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.helloworld"
})
_
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.helloworld"
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
...
@@ -95,19 +118,12 @@ func TestClientServer_step(t *testing.T) {
...
@@ -95,19 +118,12 @@ func TestClientServer_step(t *testing.T) {
})
})
}
}
//func TestClientServer_next(t *testing.T) {
type
nextTest
struct
{
type
nextTest
struct
{
begin
,
end
int
begin
,
end
int
}
}
func
testnext
(
testcases
[]
nextTest
,
initialLocation
string
,
t
*
testing
.
T
)
{
func
testnext
(
testcases
[]
nextTest
,
initialLocation
string
,
t
*
testing
.
T
)
{
fp
,
err
:=
filepath
.
Abs
(
testnextprog
)
withTestClient
(
"testnextprog"
,
t
,
func
(
c
service
.
Client
)
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
fp
=
fp
+
".go"
withTestClient
(
testnextprog
,
t
,
func
(
c
service
.
Client
)
{
bp
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
initialLocation
})
bp
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
initialLocation
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
...
@@ -125,7 +141,7 @@ func testnext(testcases []nextTest, initialLocation string, t *testing.T) {
...
@@ -125,7 +141,7 @@ func testnext(testcases []nextTest, initialLocation string, t *testing.T) {
for
_
,
tc
:=
range
testcases
{
for
_
,
tc
:=
range
testcases
{
if
state
.
CurrentThread
.
Line
!=
tc
.
begin
{
if
state
.
CurrentThread
.
Line
!=
tc
.
begin
{
t
.
Fatalf
(
"Program not stopped at correct spot expected %d was %
s:%d"
,
tc
.
begin
,
filepath
.
Base
(
fp
)
,
state
.
CurrentThread
.
Line
)
t
.
Fatalf
(
"Program not stopped at correct spot expected %d was %
d"
,
tc
.
begin
,
state
.
CurrentThread
.
Line
)
}
}
t
.
Logf
(
"Next for scenario %#v"
,
tc
)
t
.
Logf
(
"Next for scenario %#v"
,
tc
)
...
@@ -135,7 +151,7 @@ func testnext(testcases []nextTest, initialLocation string, t *testing.T) {
...
@@ -135,7 +151,7 @@ func testnext(testcases []nextTest, initialLocation string, t *testing.T) {
}
}
if
state
.
CurrentThread
.
Line
!=
tc
.
end
{
if
state
.
CurrentThread
.
Line
!=
tc
.
end
{
t
.
Fatalf
(
"Program did not continue to correct next location expected %d was %
s:%d"
,
tc
.
end
,
filepath
.
Base
(
fp
)
,
state
.
CurrentThread
.
Line
)
t
.
Fatalf
(
"Program did not continue to correct next location expected %d was %
d"
,
tc
.
end
,
state
.
CurrentThread
.
Line
)
}
}
}
}
})
})
...
@@ -179,7 +195,7 @@ func TestNextFunctionReturn(t *testing.T) {
...
@@ -179,7 +195,7 @@ func TestNextFunctionReturn(t *testing.T) {
}
}
func
TestClientServer_breakpointInMainThread
(
t
*
testing
.
T
)
{
func
TestClientServer_breakpointInMainThread
(
t
*
testing
.
T
)
{
withTestClient
(
testprog
,
t
,
func
(
c
service
.
Client
)
{
withTestClient
(
"testprog"
,
t
,
func
(
c
service
.
Client
)
{
bp
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.helloworld"
})
bp
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.helloworld"
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
...
@@ -200,7 +216,7 @@ func TestClientServer_breakpointInMainThread(t *testing.T) {
...
@@ -200,7 +216,7 @@ func TestClientServer_breakpointInMainThread(t *testing.T) {
}
}
func
TestClientServer_breakpointInSeparateGoroutine
(
t
*
testing
.
T
)
{
func
TestClientServer_breakpointInSeparateGoroutine
(
t
*
testing
.
T
)
{
withTestClient
(
testthreads
,
t
,
func
(
c
service
.
Client
)
{
withTestClient
(
"testthreads"
,
t
,
func
(
c
service
.
Client
)
{
_
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.anotherthread"
})
_
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.anotherthread"
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
...
@@ -219,7 +235,7 @@ func TestClientServer_breakpointInSeparateGoroutine(t *testing.T) {
...
@@ -219,7 +235,7 @@ func TestClientServer_breakpointInSeparateGoroutine(t *testing.T) {
}
}
func
TestClientServer_breakAtNonexistentPoint
(
t
*
testing
.
T
)
{
func
TestClientServer_breakAtNonexistentPoint
(
t
*
testing
.
T
)
{
withTestClient
(
testprog
,
t
,
func
(
c
service
.
Client
)
{
withTestClient
(
"testprog"
,
t
,
func
(
c
service
.
Client
)
{
_
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"nowhere"
})
_
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"nowhere"
})
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"Should not be able to break at non existent function"
)
t
.
Fatal
(
"Should not be able to break at non existent function"
)
...
@@ -228,7 +244,7 @@ func TestClientServer_breakAtNonexistentPoint(t *testing.T) {
...
@@ -228,7 +244,7 @@ func TestClientServer_breakAtNonexistentPoint(t *testing.T) {
}
}
func
TestClientServer_clearBreakpoint
(
t
*
testing
.
T
)
{
func
TestClientServer_clearBreakpoint
(
t
*
testing
.
T
)
{
withTestClient
(
testprog
,
t
,
func
(
c
service
.
Client
)
{
withTestClient
(
"testprog"
,
t
,
func
(
c
service
.
Client
)
{
bp
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.sleepytime"
})
bp
,
err
:=
c
.
CreateBreakPoint
(
&
api
.
BreakPoint
{
FunctionName
:
"main.sleepytime"
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
...
@@ -256,7 +272,7 @@ func TestClientServer_clearBreakpoint(t *testing.T) {
...
@@ -256,7 +272,7 @@ func TestClientServer_clearBreakpoint(t *testing.T) {
}
}
func
TestClientServer_switchThread
(
t
*
testing
.
T
)
{
func
TestClientServer_switchThread
(
t
*
testing
.
T
)
{
withTestClient
(
testnextprog
,
t
,
func
(
c
service
.
Client
)
{
withTestClient
(
"testnextprog"
,
t
,
func
(
c
service
.
Client
)
{
// With invalid thread id
// With invalid thread id
_
,
err
:=
c
.
SwitchThread
(
-
1
)
_
,
err
:=
c
.
SwitchThread
(
-
1
)
if
err
==
nil
{
if
err
==
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录