~eliasnaur/gio-patches

cmd/gogio: join all endtoend tests as subtests v1 PROPOSED

First patch! :) Merged.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/8994/mbox | git am -3
Learn more about email & git

[PATCH] cmd/gogio: join all endtoend tests as subtests Export this patch

This means we can deduplicate some of the logic, and keep it all in one
place.

Start expanding the logic too; the tests are slow, so they should be
skipped on 'go test -short'. The ones we have so far all run in a matter
of seconds on an average laptop today, but future tests will probably
require heavier work like wine or kvm.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
---
 cmd/gogio/e2e_test.go     | 26 ++++++++++++++++++++++++++
 cmd/gogio/js_test.go      |  6 ------
 cmd/gogio/wayland_test.go |  6 ------
 cmd/gogio/x11_test.go     |  6 ------
 4 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/cmd/gogio/e2e_test.go b/cmd/gogio/e2e_test.go
index e269c5f..88df7b8 100644
--- a/cmd/gogio/e2e_test.go
+++ b/cmd/gogio/e2e_test.go
@@ -39,6 +39,32 @@ type TestDriver interface {
 	Click(x, y int)
 }
 
+func TestEndToEnd(t *testing.T) {
+	if testing.Short() {
+		t.Skipf("end-to-end tests tend to be slow")
+	}
+
+	t.Parallel()
+
+	// Keep this list local, to not reuse TestDriver objects.
+	subtests := []struct{
+		name   string
+		driver TestDriver
+	}{
+		{"X11", &X11TestDriver{}},
+		{"Wayland", &WaylandTestDriver{}},
+		{"JS", &JSTestDriver{}},
+	}
+
+	for _, subtest := range subtests {
+		t.Run(subtest.name, func(t *testing.T) {
+			subtest := subtest // copy the changing loop variable
+			t.Parallel()
+			runEndToEndTest(t, subtest.driver)
+		})
+	}
+}
+
 func runEndToEndTest(t *testing.T, driver TestDriver) {
 	size := image.Point{X: 800, Y: 600}
 	cleanups := driver.Start(t, "testdata/red.go", size.X, size.Y)
diff --git a/cmd/gogio/js_test.go b/cmd/gogio/js_test.go
index 92cb588..d74bc02 100644
--- a/cmd/gogio/js_test.go
+++ b/cmd/gogio/js_test.go
@@ -152,9 +152,3 @@ func (d *JSTestDriver) Click(x, y int) {
 	// TODO(mvdan): synchronize with the app instead
 	time.Sleep(200 * time.Millisecond)
 }
-
-func TestJS(t *testing.T) {
-	t.Parallel()
-
-	runEndToEndTest(t, &JSTestDriver{})
-}
diff --git a/cmd/gogio/wayland_test.go b/cmd/gogio/wayland_test.go
index 6e71821..143e5bc 100644
--- a/cmd/gogio/wayland_test.go
+++ b/cmd/gogio/wayland_test.go
@@ -231,9 +231,3 @@ func (d *WaylandTestDriver) Click(x, y int) {
 	// Wait for the gio app to render after this click.
 	<-d.frameNotifs
 }
-
-func TestWayland(t *testing.T) {
-	t.Parallel()
-
-	runEndToEndTest(t, &WaylandTestDriver{})
-}
diff --git a/cmd/gogio/x11_test.go b/cmd/gogio/x11_test.go
index 008c496..4aba665 100644
--- a/cmd/gogio/x11_test.go
+++ b/cmd/gogio/x11_test.go
@@ -204,9 +204,3 @@ func (d *X11TestDriver) Click(x, y int) {
 	// Wait for the gio app to render after this click.
 	<-d.frameNotifs
 }
-
-func TestX11(t *testing.T) {
-	t.Parallel()
-
-	runEndToEndTest(t, &X11TestDriver{})
-}
-- 
2.24.0
First patch! :) Merged.
View this thread in the archives