From b83ac53cce0a8d6d524b8a9f638cef342bfdb18b Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Fri, 18 Jun 2021 15:04:09 +0100 Subject: [PATCH] Allow testing on CI (linux). --- cmd/zenity/notify.go | 2 ++ color_test.go | 6 ++++++ entry_test.go | 6 ++++++ file_test.go | 6 ++++++ list_test.go | 6 ++++++ msg_test.go | 6 ++++++ notify_test.go | 3 +++ progress_test.go | 11 ++++++++--- pwd_test.go | 6 ++++++ zenity_test.go | 16 ++++++++++++++++ 10 files changed, 65 insertions(+), 3 deletions(-) diff --git a/cmd/zenity/notify.go b/cmd/zenity/notify.go index 18ca6d3..e583c40 100644 --- a/cmd/zenity/notify.go +++ b/cmd/zenity/notify.go @@ -1,3 +1,5 @@ +// +build windows darwin dev + package main import ( diff --git a/color_test.go b/color_test.go index acf1aa4..51c781f 100644 --- a/color_test.go +++ b/color_test.go @@ -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) } diff --git a/entry_test.go b/entry_test.go index 1c72a09..ca7e7ec 100644 --- a/entry_test.go +++ b/entry_test.go @@ -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) } diff --git a/file_test.go b/file_test.go index 65d6a8d..9312cf8 100644 --- a/file_test.go +++ b/file_test.go @@ -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) } diff --git a/list_test.go b/list_test.go index 9f23f29..e92063b 100644 --- a/list_test.go +++ b/list_test.go @@ -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) } diff --git a/msg_test.go b/msg_test.go index 0d70191..bc49883 100644 --- a/msg_test.go +++ b/msg_test.go @@ -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) } diff --git a/notify_test.go b/notify_test.go index 45e02f8..1ad79c0 100644 --- a/notify_test.go +++ b/notify_test.go @@ -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) } diff --git a/progress_test.go b/progress_test.go index b1657dd..61ac512 100644 --- a/progress_test.go +++ b/progress_test.go @@ -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) } diff --git a/pwd_test.go b/pwd_test.go index 7ed751b..c385984 100644 --- a/pwd_test.go +++ b/pwd_test.go @@ -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) } diff --git a/zenity_test.go b/zenity_test.go index f5df56c..9f20427 100644 --- a/zenity_test.go +++ b/zenity_test.go @@ -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 +}