forked from cyrus-and/gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_test.go
64 lines (54 loc) · 1.34 KB
/
commands_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package gdb
import (
"reflect"
"testing"
)
var consoleRecordCount = 0
func onNotification(t *testing.T, notification map[string]interface{}) {
if notification["type"] != "console" {
consoleRecordCount++
}
}
func TestSend(t *testing.T) {
var expected, result map[string]interface{}
// start gdb
gdb, err := New(func(notification map[string]interface{}) {
onNotification(t, notification)
})
if err != nil {
t.Fatal(err)
}
// try sending a command
result, err = gdb.Send("gdb-version")
expected = map[string]interface{}{"class": "done"}
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(result, expected) {
t.Fatal(result, "!=", expected)
}
// gdb-version should generate some console records
if consoleRecordCount == 0 {
t.Fatal("no console records received")
}
// try sending a command with an argument containing a space
result, err = gdb.Send("var-create", "foo", "@", "40 + 2")
if err != nil {
t.Fatal(err)
}
if class, hasClass := result["class"]; !hasClass || class != "done" {
t.Fatal(result, "has not class 'done'")
}
// try sending a wrong command
result, err = gdb.Send("foobarbaz")
if err != nil {
t.Fatal(err)
}
if class, hasClass := result["class"]; !hasClass || class != "error" {
t.Fatal(result, "has not class 'error'")
}
// exit gdb
if err := gdb.Exit(); err != nil {
t.Fatal(err)
}
}