-
Notifications
You must be signed in to change notification settings - Fork 4
/
14_error_channel_test.go
53 lines (45 loc) · 1.33 KB
/
14_error_channel_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
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Čtyřicátá čtvrtá část
// Použití Go pro automatizaci práce s aplikacemi s interaktivním příkazovým řádkem (dokončení)
// https://www.root.cz/clanky/pouziti-go-pro-automatizaci-prace-s-aplikacemi-s-interaktivnim-prikazovym-radkem-dokonceni/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů ze čtyřicáté čtvrté části:
// https://github.com/tisnik/go-root/blob/master/article_44/README.md
package main
import (
"regexp"
"testing"
"time"
"github.com/google/goexpect"
)
func TestPythonInterpreter(t *testing.T) {
child, errChannel, err := expect.Spawn("python", 2*time.Second)
if err != nil {
t.Fatal(err)
}
t.Log("Python interpreter has been started")
defer child.Close()
_, err = child.ExpectBatch([]expect.Batcher{
&expect.BCas{[]expect.Caser{
&expect.Case{R: regexp.MustCompile("Python 2"), T: expect.OK()},
&expect.Case{R: regexp.MustCompile("Python 3"), T: expect.OK()}}},
&expect.BExp{R: ">>> "},
&expect.BSnd{S: "import sys\n"},
&expect.BExp{R: ">>> "},
&expect.BSnd{S: "sys.exit(0)\n"}},
2*time.Second)
if err != nil {
log.Fatal(err)
}
t.Log("OK")
err = <-errChannel
if err != nil {
t.Fatal(err)
}
t.Log("Exit: success")
}