diff --git a/cmd/gogio/android_test.go b/cmd/gogio/android_test.go index e9045012..a0e2a7f1 100644 --- a/cmd/gogio/android_test.go +++ b/cmd/gogio/android_test.go @@ -14,7 +14,6 @@ import ( "path/filepath" "regexp" "strings" - "time" ) type AndroidTestDriver struct { @@ -55,13 +54,7 @@ func (d *AndroidTestDriver) Start(path string, width, height int) { // First, build the app. apk := filepath.Join(d.tempDir("gio-endtoend-android"), "e2e.apk") - - // TODO(mvdan): This is inefficient, as we link the gogio tool every time. - // Consider options in the future. On the plus side, this is simple. - cmd := exec.Command("go", "run", ".", "-target=android", "-appid="+appid, "-o="+apk, path) - if out, err := cmd.CombinedOutput(); err != nil { - d.Fatalf("could not build app: %s:\n%s", err, out) - } + d.gogio("-target=android", "-appid="+appid, "-o="+apk, path) // Make sure the app isn't installed already, and try to uninstall it // when we finish. Previous failed test runs might have left the app. @@ -110,13 +103,6 @@ func (d *AndroidTestDriver) Start(path string, width, height int) { // Start the app. d.adb("shell", "monkey", "-p", appid, "1") - // Unfortunately, it seems like waiting for the initial frame isn't - // enough. Most Android versions have animations when opening apps that - // run for hundreds of milliseconds, so that's probably the reason. - // TODO(mvdan): any way to wait for the screen to be ready without a - // static sleep? - time.Sleep(500 * time.Millisecond) - // Wait for the gio app to render. d.waitForFrame() } diff --git a/cmd/gogio/e2e_test.go b/cmd/gogio/e2e_test.go index 79d6b259..54797929 100644 --- a/cmd/gogio/e2e_test.go +++ b/cmd/gogio/e2e_test.go @@ -280,3 +280,16 @@ func (d *driverBase) tempDir(name string) string { d.Cleanup(func() { os.RemoveAll(dir) }) return dir } + +func (d *driverBase) gogio(args ...string) { + d.Helper() + prog, err := os.Executable() + if err != nil { + d.Fatal(err) + } + cmd := exec.Command(prog, args...) + cmd.Env = append(os.Environ(), "RUN_GOGIO=1") + if out, err := cmd.CombinedOutput(); err != nil { + d.Fatalf("gogio error: %s:\n%s", err, out) + } +} diff --git a/cmd/gogio/js_test.go b/cmd/gogio/js_test.go index 3ccf7a2d..1760bc14 100644 --- a/cmd/gogio/js_test.go +++ b/cmd/gogio/js_test.go @@ -33,12 +33,7 @@ func (d *JSTestDriver) Start(path string, width, height int) { // First, build the app. dir := d.tempDir("gio-endtoend-js") - // TODO(mvdan): This is inefficient, as we link the gogio tool every time. - // Consider options in the future. On the plus side, this is simple. - cmd := exec.Command("go", "run", ".", "-target=js", "-o="+dir, path) - if out, err := cmd.CombinedOutput(); err != nil { - d.Fatalf("could not build app: %s:\n%s", err, out) - } + d.gogio("-target=js", "-o="+dir, path) // Second, start Chrome. opts := append(chromedp.DefaultExecAllocatorOptions[:], diff --git a/cmd/gogio/main_test.go b/cmd/gogio/main_test.go index efb441e0..9e072180 100644 --- a/cmd/gogio/main_test.go +++ b/cmd/gogio/main_test.go @@ -1,9 +1,21 @@ package main import ( + "os" "testing" ) +func TestMain(m *testing.M) { + if os.Getenv("RUN_GOGIO") != "" { + // Allow the end-to-end tests to call the gogio tool without + // having to build it from scratch, nor having to refactor the + // main function to avoid using global variables. + main() + os.Exit(0) // main already exits, but just in case. + } + os.Exit(m.Run()) +} + type expval struct { in, out string }