Improve CI testing.
This commit is contained in:
parent
93936c933a
commit
9e27c73490
10 changed files with 37 additions and 35 deletions
|
@ -31,7 +31,7 @@ func TestSelectColor_timeout(t *testing.T) {
|
|||
defer cancel()
|
||||
|
||||
_, err := zenity.SelectColor(zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !os.IsTimeout(err) {
|
||||
|
@ -45,7 +45,7 @@ func TestSelectColor_cancel(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
_, err := zenity.SelectColor(zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestEntry_timeout(t *testing.T) {
|
|||
defer cancel()
|
||||
|
||||
_, err := zenity.Entry("", zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !os.IsTimeout(err) {
|
||||
|
@ -37,7 +37,7 @@ func TestEntry_cancel(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
_, err := zenity.Entry("", zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
|
|
@ -83,7 +83,7 @@ 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 {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !os.IsTimeout(err) {
|
||||
|
@ -102,7 +102,7 @@ func TestFile_cancel(t *testing.T) {
|
|||
|
||||
for _, f := range fileFuncs {
|
||||
_, err := f(zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
|
|
@ -4,7 +4,7 @@ package zenutil
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
func TestRun(t *testing.T) {
|
||||
_, err := Run(nil, []string{"--version"})
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -22,7 +22,7 @@ func TestRun(t *testing.T) {
|
|||
|
||||
func TestRun_context(t *testing.T) {
|
||||
_, err := Run(context.TODO(), []string{"--version"})
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -32,7 +32,7 @@ func TestRun_context(t *testing.T) {
|
|||
|
||||
func TestRunProgress(t *testing.T) {
|
||||
_, err := RunProgress(nil, 100, nil, []string{"--version"})
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -40,14 +40,14 @@ func TestRunProgress(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func skip(err error) (error, bool) {
|
||||
func skip(err error) (bool, error) {
|
||||
if _, ok := err.(*exec.Error); ok {
|
||||
// zenity/osascript/etc were not found in path
|
||||
return err, true
|
||||
// zenity was not found in path
|
||||
return true, err
|
||||
}
|
||||
if err != nil && os.Getenv("DISPLAY") == "" {
|
||||
// no display
|
||||
return errors.New("no display"), true
|
||||
return true, fmt.Errorf("no display: %w", err)
|
||||
}
|
||||
return nil, false
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func TestList_timeout(t *testing.T) {
|
|||
defer cancel()
|
||||
|
||||
_, err := zenity.List("", nil, zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !os.IsTimeout(err) {
|
||||
|
@ -65,7 +65,7 @@ func TestList_cancel(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
_, err := zenity.List("", nil, zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
|
|
@ -51,7 +51,7 @@ 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 {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !os.IsTimeout(err) {
|
||||
|
@ -70,7 +70,7 @@ func TestMessage_cancel(t *testing.T) {
|
|||
|
||||
for _, f := range msgFuncs {
|
||||
err := f("text", zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
|
|
@ -22,7 +22,7 @@ func TestNotify_cancel(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
err := zenity.Notify("text", zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
|
|
@ -76,7 +76,7 @@ func TestProgress_cancel(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
_, err := zenity.Progress(zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
@ -89,7 +89,7 @@ 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 {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestPassword_timeout(t *testing.T) {
|
|||
defer cancel()
|
||||
|
||||
_, _, err := zenity.Password(zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !os.IsTimeout(err) {
|
||||
|
@ -44,7 +44,7 @@ func TestPassword_cancel(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
_, _, err := zenity.Password(zenity.Context(ctx))
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
@ -58,7 +58,7 @@ func TestPassword_username(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
_, _, err := zenity.Password(zenity.Context(ctx), zenity.Username())
|
||||
if err, skip := skip(err); skip {
|
||||
if skip, err := skip(err); skip {
|
||||
t.Skip("skipping:", err)
|
||||
}
|
||||
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package zenity_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
@ -14,14 +14,16 @@ func TestMain(m *testing.M) {
|
|||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
|
||||
func skip(err error) (error, bool) {
|
||||
func skip(err error) (bool, error) {
|
||||
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
|
||||
if _, ok := err.(*exec.Error); ok {
|
||||
// zenity/osascript/etc were not found in path
|
||||
return err, true
|
||||
// zenity was not found in path
|
||||
return true, err
|
||||
}
|
||||
if err != nil && os.Getenv("DISPLAY") == "" && !(runtime.GOOS == "windows" || runtime.GOOS == "darwin") {
|
||||
if err != nil && os.Getenv("DISPLAY") == "" {
|
||||
// no display
|
||||
return errors.New("no display"), true
|
||||
return true, fmt.Errorf("no display: %w", err)
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue