mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-27 13:48:49 +08:00
Merge pull request #235 from mum4k/234-tcell_test
Stub out tcell.NewScreen so tests can pass headless.
This commit is contained in:
commit
448d494391
@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [0.12.0] - 10-Apr-2020
|
## [0.12.0] - 10-Apr-2020
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- the `tcell` unit test can now pass in headless mode (when TERM="") which
|
||||||
|
happens under bazel.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Migrating to [Go modules](https://blog.golang.org/using-go-modules).
|
- Migrating to [Go modules](https://blog.golang.org/using-go-modules).
|
||||||
|
@ -16,6 +16,7 @@ package tcell
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
@ -79,11 +80,14 @@ type Terminal struct {
|
|||||||
clearStyle *cell.Options
|
clearStyle *cell.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tcellNewScreen can be overridden from tests.
|
||||||
|
var tcellNewScreen = tcell.NewScreen
|
||||||
|
|
||||||
// newTerminal creates the terminal and applies the options.
|
// newTerminal creates the terminal and applies the options.
|
||||||
func newTerminal(opts ...Option) (*Terminal, error) {
|
func newTerminal(opts ...Option) (*Terminal, error) {
|
||||||
screen, err := tcell.NewScreen()
|
screen, err := tcellNewScreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("tcell.NewScreen => %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t := &Terminal{
|
t := &Terminal{
|
||||||
|
@ -17,6 +17,7 @@ package tcell
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
"github.com/kylelemons/godebug/pretty"
|
"github.com/kylelemons/godebug/pretty"
|
||||||
"github.com/mum4k/termdash/cell"
|
"github.com/mum4k/termdash/cell"
|
||||||
"github.com/mum4k/termdash/terminal/terminalapi"
|
"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 {
|
for _, tc := range tests {
|
||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
got, err := newTerminal(tc.opts...)
|
got, err := newTerminal(tc.opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("newTerminal => unexpected error:\n%v", err)
|
t.Errorf("newTerminal => unexpected error:\n%v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore these fields.
|
// Ignore these fields.
|
||||||
@ -96,11 +99,13 @@ func TestNewTerminalClearStyle(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tcellNewScreen = func() (tcell.Screen, error) { return nil, nil }
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
got, err := newTerminal(tc.opts...)
|
got, err := newTerminal(tc.opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("newTerminal => unexpected error:\n%v", err)
|
t.Errorf("newTerminal => unexpected error:\n%v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore these fields.
|
// Ignore these fields.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user