Introduce TestMain to run gui tests in goroutine locked to main app thread; Call LockOSThread only once. (#199)

This commit is contained in:
Max Risuhin 2019-02-06 00:58:31 -08:00 committed by Liam Galvin
parent a7ed53c45a
commit 1ca1b7c246
5 changed files with 16 additions and 15 deletions

View File

@ -1107,27 +1107,27 @@ func (buffer *Buffer) getMaxLines() uint64 {
return result
}
func (buffer *Buffer) Save(path string) {
func (buffer *Buffer) SaveViewLines(path string) {
f, err := os.Create(path)
if err != nil {
panic(err)
}
defer f.Close()
for _, line := range buffer.lines {
f.WriteString(line.String())
for i := uint16(0); i <= buffer.ViewHeight(); i++ {
f.WriteString(buffer.getViewLine(i).String())
}
}
func (buffer *Buffer) Compare(path string) bool {
func (buffer *Buffer) CompareViewLines(path string) bool {
f, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
bufferContent := []byte{}
for _, line := range buffer.lines {
lineBytes := []byte(line.String())
for i := uint16(0); i <= buffer.ViewHeight(); i++ {
lineBytes := []byte(buffer.getViewLine(i).String())
bufferContent = append(bufferContent, lineBytes...)
}
return bytes.Equal(f, bufferContent)

View File

@ -6,7 +6,6 @@ import (
"image/png"
"math"
"os"
"runtime"
"strconv"
"strings"
"sync"
@ -296,9 +295,6 @@ func (gui *GUI) Close() {
func (gui *GUI) Render() error {
gui.logger.Debugf("Locking OS thread...")
runtime.LockOSThread()
gui.logger.Debugf("Creating window...")
var err error
gui.window, err = gui.createWindow()

View File

@ -12,13 +12,15 @@ import (
type callback func(terminal *terminal.Terminal, g *gui.GUI)
func init() {
runtime.LockOSThread()
}
func main() {
initialize(nil)
}
func initialize(fn callback) {
runtime.LockOSThread()
conf := getConfig()
logger, err := getLogger(conf)
if err != nil {

View File

@ -53,8 +53,11 @@ func enter(terminal *terminal.Terminal) {
terminal.Write([]byte("\n"))
}
func TestCursorMovement(t *testing.T) {
func TestMain(m *testing.M) {
testCursorMovement()
}
func testCursorMovement() {
testFunc := func(term *terminal.Terminal, g *gui.GUI) {
sleep()
send(term, "vttest\n")
@ -62,8 +65,8 @@ func TestCursorMovement(t *testing.T) {
send(term, "1\n")
sleep()
if term.ActiveBuffer().Compare("vttest/test-cursor-movement-1") == false {
t.Error(fmt.Sprint("ActiveBuffer doesn't match vttest template"))
if term.ActiveBuffer().CompareViewLines("vttest/test-cursor-movement-1") == false {
os.Exit(terminate(fmt.Sprintf("ActiveBuffer doesn't match vttest template vttest/test-cursor-movement-1")))
}
g.Screenshot ("test-cursor-movement-1.png")
compareImages("vttest/test-cursor-movement-1.png", "test-cursor-movement-1.png")

Binary file not shown.