mirror of https://github.com/liamg/aminal.git
Introduce TestMain to run gui tests in goroutine locked to main app thread; Call LockOSThread only once. (#199)
This commit is contained in:
parent
a7ed53c45a
commit
1ca1b7c246
|
@ -1107,27 +1107,27 @@ func (buffer *Buffer) getMaxLines() uint64 {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (buffer *Buffer) Save(path string) {
|
func (buffer *Buffer) SaveViewLines(path string) {
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
for _, line := range buffer.lines {
|
for i := uint16(0); i <= buffer.ViewHeight(); i++ {
|
||||||
f.WriteString(line.String())
|
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)
|
f, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferContent := []byte{}
|
bufferContent := []byte{}
|
||||||
for _, line := range buffer.lines {
|
for i := uint16(0); i <= buffer.ViewHeight(); i++ {
|
||||||
lineBytes := []byte(line.String())
|
lineBytes := []byte(buffer.getViewLine(i).String())
|
||||||
bufferContent = append(bufferContent, lineBytes...)
|
bufferContent = append(bufferContent, lineBytes...)
|
||||||
}
|
}
|
||||||
return bytes.Equal(f, bufferContent)
|
return bytes.Equal(f, bufferContent)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"image/png"
|
"image/png"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -296,9 +295,6 @@ func (gui *GUI) Close() {
|
||||||
|
|
||||||
func (gui *GUI) Render() error {
|
func (gui *GUI) Render() error {
|
||||||
|
|
||||||
gui.logger.Debugf("Locking OS thread...")
|
|
||||||
runtime.LockOSThread()
|
|
||||||
|
|
||||||
gui.logger.Debugf("Creating window...")
|
gui.logger.Debugf("Creating window...")
|
||||||
var err error
|
var err error
|
||||||
gui.window, err = gui.createWindow()
|
gui.window, err = gui.createWindow()
|
||||||
|
|
6
main.go
6
main.go
|
@ -12,13 +12,15 @@ import (
|
||||||
|
|
||||||
type callback func(terminal *terminal.Terminal, g *gui.GUI)
|
type callback func(terminal *terminal.Terminal, g *gui.GUI)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
initialize(nil)
|
initialize(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialize(fn callback) {
|
func initialize(fn callback) {
|
||||||
runtime.LockOSThread()
|
|
||||||
|
|
||||||
conf := getConfig()
|
conf := getConfig()
|
||||||
logger, err := getLogger(conf)
|
logger, err := getLogger(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -53,8 +53,11 @@ func enter(terminal *terminal.Terminal) {
|
||||||
terminal.Write([]byte("\n"))
|
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) {
|
testFunc := func(term *terminal.Terminal, g *gui.GUI) {
|
||||||
sleep()
|
sleep()
|
||||||
send(term, "vttest\n")
|
send(term, "vttest\n")
|
||||||
|
@ -62,8 +65,8 @@ func TestCursorMovement(t *testing.T) {
|
||||||
send(term, "1\n")
|
send(term, "1\n")
|
||||||
sleep()
|
sleep()
|
||||||
|
|
||||||
if term.ActiveBuffer().Compare("vttest/test-cursor-movement-1") == false {
|
if term.ActiveBuffer().CompareViewLines("vttest/test-cursor-movement-1") == false {
|
||||||
t.Error(fmt.Sprint("ActiveBuffer doesn't match vttest template"))
|
os.Exit(terminate(fmt.Sprintf("ActiveBuffer doesn't match vttest template vttest/test-cursor-movement-1")))
|
||||||
}
|
}
|
||||||
g.Screenshot ("test-cursor-movement-1.png")
|
g.Screenshot ("test-cursor-movement-1.png")
|
||||||
compareImages("vttest/test-cursor-movement-1.png", "test-cursor-movement-1.png")
|
compareImages("vttest/test-cursor-movement-1.png", "test-cursor-movement-1.png")
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue