Automate ci running of vttest Test of screen features (#209)

Signed-off-by: Max Risuhin <risuhin.max@gmail.com>
This commit is contained in:
Max Risuhin 2019-02-12 10:10:51 +02:00 committed by Liam Galvin
parent fcd5625a34
commit 6ded551de9
17 changed files with 128 additions and 62 deletions

View File

@ -28,6 +28,7 @@ func getConfig() *config.Config {
debugMode := false debugMode := false
slomo := false slomo := false
if flag.Parsed() == false {
flag.BoolVar(&showVersion, "version", showVersion, "Output version information") flag.BoolVar(&showVersion, "version", showVersion, "Output version information")
flag.BoolVar(&ignoreConfig, "ignore-config", ignoreConfig, "Ignore user config files and use defaults") flag.BoolVar(&ignoreConfig, "ignore-config", ignoreConfig, "Ignore user config files and use defaults")
flag.StringVar(&shell, "shell", shell, "Specify the shell to use") flag.StringVar(&shell, "shell", shell, "Specify the shell to use")
@ -35,6 +36,7 @@ func getConfig() *config.Config {
flag.BoolVar(&slomo, "slomo", slomo, "Render in slow motion (useful for debugging)") flag.BoolVar(&slomo, "slomo", slomo, "Render in slow motion (useful for debugging)")
flag.Parse() // actual parsing and fetching flags from the command line flag.Parse() // actual parsing and fetching flags from the command line
}
actuallyProvidedFlags := getActuallyProvidedFlags() actuallyProvidedFlags := getActuallyProvidedFlags()
if showVersion { if showVersion {

10
main.go
View File

@ -20,7 +20,7 @@ func main() {
initialize(nil) initialize(nil)
} }
func initialize(fn callback) { func initialize(unitTestfunc callback) {
conf := getConfig() conf := getConfig()
logger, err := getLogger(conf) logger, err := getLogger(conf)
if err != nil { if err != nil {
@ -63,16 +63,16 @@ func initialize(fn callback) {
logger.Fatalf("Cannot start: %s", err) logger.Fatalf("Cannot start: %s", err)
} }
if fn != nil { if unitTestfunc != nil {
go fn(terminal, g) go unitTestfunc(terminal, g)
} } else {
go func() { go func() {
if err := guestProcess.Wait(); err != nil { if err := guestProcess.Wait(); err != nil {
logger.Fatalf("Failed to wait for guest process: %s", err) logger.Fatalf("Failed to wait for guest process: %s", err)
} }
g.Close() g.Close()
}() }()
}
if err := g.Render(); err != nil { if err := g.Render(); err != nil {
logger.Fatalf("Render error: %s", err) logger.Fatalf("Render error: %s", err)

View File

@ -3,8 +3,10 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"strings"
"testing" "testing"
"time" "time"
@ -14,6 +16,9 @@ import (
"github.com/carlogit/phash" "github.com/carlogit/phash"
) )
var termRef *terminal.Terminal
var guiRef *gui.GUI
func terminate(msg string) int { func terminate(msg string) int {
defer fmt.Print(msg) defer fmt.Print(msg)
return 1 return 1
@ -36,12 +41,13 @@ func hash(path string) string {
return imageHash return imageHash
} }
func compareImages(img1 string, img2 string) { func compareImages(expected string, actual string) {
template := hash(img1) template := hash(expected)
screen := hash(img2) screen := hash(actual)
distance := phash.GetDistance(template, screen) distance := phash.GetDistance(template, screen)
if distance != 0 { if distance != 0 {
os.Exit(terminate(fmt.Sprintf("Screenshot doesn't match expected image. Distance of hashes difference: %d\n", distance))) os.Exit(terminate(fmt.Sprintf("Screenshot \"%s\" doesn't match expected image \"%s\". Distance of hashes difference: %d\n",
actual, expected, distance)))
} }
} }
@ -53,12 +59,41 @@ func enter(terminal *terminal.Terminal) {
terminal.Write([]byte("\n")) terminal.Write([]byte("\n"))
} }
func TestMain(m *testing.M) { func validateScreen(img string) {
testCursorMovement() guiRef.Screenshot(img)
compareImages(strings.Join([]string{"vttest/", img}, ""), img)
enter(termRef)
sleep()
} }
func testCursorMovement() { func TestMain(m *testing.M) {
flag.Parse()
go m.Run()
for f := range tests {
f()
}
}
var tests = make(chan func())
func runMain(f func()) {
complete := make(chan bool, 1)
tests <- func() {
f()
complete <- true
}
<-complete
}
func TestCursorMovement(t *testing.T) {
runMain(func() {
testFunc := func(term *terminal.Terminal, g *gui.GUI) { testFunc := func(term *terminal.Terminal, g *gui.GUI) {
termRef = term; guiRef = g
sleep() sleep()
send(term, "vttest\n") send(term, "vttest\n")
sleep() sleep()
@ -68,35 +103,64 @@ func testCursorMovement() {
if term.ActiveBuffer().CompareViewLines("vttest/test-cursor-movement-1") == false { 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"))) 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")
enter(term) validateScreen("test-cursor-movement-1.png")
sleep() validateScreen("test-cursor-movement-2.png")
g.Screenshot ("test-cursor-movement-2.png") validateScreen("test-cursor-movement-3.png")
compareImages("vttest/test-cursor-movement-2.png", "test-cursor-movement-2.png") validateScreen("test-cursor-movement-4.png")
validateScreen("test-cursor-movement-5.png")
validateScreen("test-cursor-movement-6.png")
enter(term) g.Close()
sleep()
g.Screenshot ("test-cursor-movement-3.png")
compareImages("vttest/test-cursor-movement-3.png", "test-cursor-movement-3.png")
enter(term)
sleep()
g.Screenshot ("test-cursor-movement-4.png")
compareImages("vttest/test-cursor-movement-4.png", "test-cursor-movement-4.png")
enter(term)
sleep()
g.Screenshot ("test-cursor-movement-5.png")
compareImages("vttest/test-cursor-movement-5.png", "test-cursor-movement-5.png")
enter(term)
sleep()
g.Screenshot ("test-cursor-movement-6.png")
compareImages("vttest/test-cursor-movement-6.png", "test-cursor-movement-6.png")
os.Exit(0)
} }
initialize(testFunc) initialize(testFunc)
})
}
func TestScreenFeatures(t *testing.T) {
runMain(func() {
testFunc := func(term *terminal.Terminal, g *gui.GUI) {
termRef = term; guiRef = g
sleep()
send(term, "vttest\n")
sleep()
send(term, "2\n")
sleep()
validateScreen("test-screen-features-1.png")
validateScreen("test-screen-features-2.png")
validateScreen("test-screen-features-3.png")
validateScreen("test-screen-features-4.png")
validateScreen("test-screen-features-5.png")
validateScreen("test-screen-features-6.png")
validateScreen("test-screen-features-7.png")
validateScreen("test-screen-features-8.png")
validateScreen("test-screen-features-9.png")
validateScreen("test-screen-features-10.png")
// 11th screen test is not passing https://github.com/liamg/aminal/issues/207
//g.Screenshot("vttest/test-screen-features-11.png")
//compareImages("vttest/test-screen-features-11.png", "vttest/test-screen-features-11.png")
enter(term)
sleep()
validateScreen("test-screen-features-12.png")
validateScreen("test-screen-features-13.png")
validateScreen("test-screen-features-14.png")
validateScreen("test-screen-features-15.png")
g.Close()
}
initialize(testFunc)
})
}
// Last Test should terminate main goroutine since it's infinity looped to execute others GUI tests in main goroutine
func TestExit(t *testing.T) {
os.Exit(0)
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB