Allow testing on CI (linux).

This commit is contained in:
Nuno Cruces 2021-06-18 15:04:09 +01:00
parent 78d6d30475
commit b83ac53cce
10 changed files with 65 additions and 3 deletions

View File

@ -1,3 +1,5 @@
// +build windows darwin dev
package main
import (

View File

@ -31,6 +31,9 @@ func TestSelectColor_timeout(t *testing.T) {
defer cancel()
_, err := zenity.SelectColor(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
@ -42,6 +45,9 @@ func TestSelectColor_cancel(t *testing.T) {
cancel()
_, err := zenity.SelectColor(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}

View File

@ -23,6 +23,9 @@ func TestEntry_timeout(t *testing.T) {
defer cancel()
_, err := zenity.Entry("", zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
@ -34,6 +37,9 @@ func TestEntry_cancel(t *testing.T) {
cancel()
_, err := zenity.Entry("", zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}

View File

@ -83,6 +83,9 @@ func TestFile_timeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second/10)
_, err := f(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
@ -99,6 +102,9 @@ func TestFile_cancel(t *testing.T) {
for _, f := range fileFuncs {
_, err := f(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}

View File

@ -51,6 +51,9 @@ func TestList_timeout(t *testing.T) {
defer cancel()
_, err := zenity.List("", nil, zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
@ -62,6 +65,9 @@ func TestList_cancel(t *testing.T) {
cancel()
_, err := zenity.List("", nil, zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}

View File

@ -51,6 +51,9 @@ func TestMessage_timeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second/10)
err := f("text", zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
@ -67,6 +70,9 @@ func TestMessage_cancel(t *testing.T) {
for _, f := range msgFuncs {
err := f("text", zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}

View File

@ -22,6 +22,9 @@ func TestNotify_cancel(t *testing.T) {
cancel()
err := zenity.Notify("text", zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}

View File

@ -3,7 +3,6 @@ package zenity_test
import (
"context"
"errors"
"log"
"testing"
"time"
@ -15,7 +14,7 @@ func ExampleProgress() {
dlg, err := zenity.Progress(
zenity.Title("Update System Logs"))
if err != nil {
log.Fatal(err)
return
}
defer dlg.Close()
@ -49,7 +48,7 @@ func ExampleProgress_pulsate() {
zenity.Title("Update System Logs"),
zenity.Pulsate())
if err != nil {
log.Fatal(err)
return
}
defer dlg.Close()
@ -77,6 +76,9 @@ func TestProgress_cancel(t *testing.T) {
cancel()
_, err := zenity.Progress(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}
@ -87,6 +89,9 @@ func TestProgress_cancelAfter(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
dlg, err := zenity.Progress(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if err != nil {
t.Fatal(err)
}

View File

@ -22,6 +22,9 @@ func TestPassword_timeout(t *testing.T) {
defer cancel()
_, _, err := zenity.Password(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
@ -33,6 +36,9 @@ func TestPassword_cancel(t *testing.T) {
cancel()
_, _, err := zenity.Password(zenity.Context(ctx))
if err, skip := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}

View File

@ -1,6 +1,10 @@
package zenity_test
import (
"errors"
"os"
"os/exec"
"runtime"
"testing"
"go.uber.org/goleak"
@ -9,3 +13,15 @@ import (
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func skip(err error) (error, bool) {
if _, ok := err.(*exec.Error); ok {
// zenity/osascript/etc were not found in path
return err, true
}
if err != nil && os.Getenv("DISPLAY") == "" && !(runtime.GOOS == "windows" || runtime.GOOS == "darwin") {
// no display
return errors.New("no display"), true
}
return nil, false
}