mirror of https://github.com/mum4k/termdash.git
Stub out tcell.NewScreen so tests can pass headless.
This commit is contained in:
parent
d7aef3106b
commit
4beaac9cca
|
@ -16,6 +16,7 @@ package tcell
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"image"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
|
@ -79,11 +80,14 @@ type Terminal struct {
|
|||
clearStyle *cell.Options
|
||||
}
|
||||
|
||||
// tcellNewScreen can be overridden from tests.
|
||||
var tcellNewScreen = tcell.NewScreen
|
||||
|
||||
// newTerminal creates the terminal and applies the options.
|
||||
func newTerminal(opts ...Option) (*Terminal, error) {
|
||||
screen, err := tcell.NewScreen()
|
||||
screen, err := tcellNewScreen()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("tcell.NewScreen => %v", err)
|
||||
}
|
||||
|
||||
t := &Terminal{
|
||||
|
|
|
@ -17,6 +17,7 @@ package tcell
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/mum4k/termdash/cell"
|
||||
"github.com/mum4k/termdash/terminal/terminalapi"
|
||||
|
@ -45,11 +46,13 @@ func TestNewTerminalColorMode(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
tcellNewScreen = func() (tcell.Screen, error) { return nil, nil }
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
got, err := newTerminal(tc.opts...)
|
||||
if err != nil {
|
||||
t.Errorf("newTerminal => unexpected error:\n%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Ignore these fields.
|
||||
|
@ -96,11 +99,13 @@ func TestNewTerminalClearStyle(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
tcellNewScreen = func() (tcell.Screen, error) { return nil, nil }
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
got, err := newTerminal(tc.opts...)
|
||||
if err != nil {
|
||||
t.Errorf("newTerminal => unexpected error:\n%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Ignore these fields.
|
||||
|
|
Loading…
Reference in New Issue