edit: skip test when pty open failed (#711)

Closes: #708
Signed-off-by: Shengjing Zhu <i@zhsj.me>
This commit is contained in:
zhsj 2018-07-03 07:05:58 +08:00 committed by Qi Xiao
parent 9b53f3bacf
commit 35eabd3f0b
2 changed files with 10 additions and 7 deletions

View File

@ -60,8 +60,11 @@ func TestReadLine(t *testing.T) {
var outputs []byte
sigs := make(chan os.Signal, 10)
defer close(sigs)
master, lineChan, errChan := run(ev, sigs, &outputs)
master, lineChan, errChan, err := run(ev, sigs, &outputs)
defer master.Close()
if err != nil {
t.Skip(err)
}
write(master, sigs, test.input, test.sigints)
@ -86,11 +89,11 @@ func TestReadLine(t *testing.T) {
// connected to, and two channels onto which the result of ReadLine will be
// delivered. The caller is responsible for closing the master file.
func run(ev *eval.Evaler, sigs <-chan os.Signal, ptrOutputs *[]byte) (*os.File,
<-chan string, <-chan error) {
<-chan string, <-chan error, error) {
master, tty, err := pty.Open()
if err != nil {
panic(err)
return nil, nil, nil, err
}
// Continually consume tty outputs so that the editor is not blocked on
// writing.
@ -113,7 +116,7 @@ func run(ev *eval.Evaler, sigs <-chan os.Signal, ptrOutputs *[]byte) (*os.File,
close(errChan)
}()
return master, lineChan, errChan
return master, lineChan, errChan, nil
}
// drain drains the given reader. If a non-nil []byte pointer is passed, it also

View File

@ -1,4 +1,4 @@
// +build !windows,plan9
// +build !windows,!plan9
package tty
@ -11,12 +11,12 @@ import (
func TestSetupTerminal(t *testing.T) {
pty, tty, err := pty.Open()
if err != nil {
t.Errorf("cannot open pty for testing setupTerminal")
t.Skip("cannot open pty for testing setupTerminal")
}
defer pty.Close()
defer tty.Close()
_, err = setup(tty)
_, err = setup(tty, tty)
if err != nil {
t.Errorf("setupTerminal returns an error")
}