From 531f98293ebd7f313f0a0b21cb10fa01a4e8b3c0 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 29 Jul 2021 16:20:50 +0100 Subject: [PATCH] WSL test improvements. --- cmd/zenity/main.go | 1 + color_test.go | 2 +- entry_test.go | 2 +- file_test.go | 2 +- internal/zenutil/run_unix_test.go | 4 ++-- list_test.go | 2 +- main_test.go | 4 ++-- msg_test.go | 2 +- pwd_test.go | 2 +- pwd_unix.go | 8 ++++++-- 10 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/zenity/main.go b/cmd/zenity/main.go index 262c43e..b347dd9 100644 --- a/cmd/zenity/main.go +++ b/cmd/zenity/main.go @@ -191,6 +191,7 @@ func setupFlags() { flag.StringVar(&icon, "icon-name", "", "Set the dialog `icon` (dialog-error, dialog-information, dialog-question, dialog-warning)") flag.BoolVar(&noWrap, "no-wrap", false, "Do not enable text wrapping") flag.BoolVar(&ellipsize, "ellipsize", false, "Enable ellipsizing in the dialog text") + flag.Bool("no-markup", true, "Do not enable Pango markup") // Entry options flag.StringVar(&entryText, "entry-text", "", "Set the entry `text`") diff --git a/color_test.go b/color_test.go index c499591..66c7d57 100644 --- a/color_test.go +++ b/color_test.go @@ -27,7 +27,7 @@ func ExampleSelectColor_palette() { func TestSelectColor_timeout(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithTimeout(context.Background(), time.Second/10) + ctx, cancel := context.WithTimeout(context.Background(), time.Second/5) defer cancel() _, err := zenity.SelectColor(zenity.Context(ctx)) diff --git a/entry_test.go b/entry_test.go index c8e77cb..a116258 100644 --- a/entry_test.go +++ b/entry_test.go @@ -19,7 +19,7 @@ func ExampleEntry() { func TestEntry_timeout(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithTimeout(context.Background(), time.Second/10) + ctx, cancel := context.WithTimeout(context.Background(), time.Second/5) defer cancel() _, err := zenity.Entry("", zenity.Context(ctx)) diff --git a/file_test.go b/file_test.go index 25f565c..d1d5219 100644 --- a/file_test.go +++ b/file_test.go @@ -82,7 +82,7 @@ func TestSelectFile_timeout(t *testing.T) { for _, tt := range fileFuncs { t.Run(tt.name, func(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithTimeout(context.Background(), time.Second/10) + ctx, cancel := context.WithTimeout(context.Background(), time.Second/5) defer cancel() _, err := tt.fn(zenity.Context(ctx)) diff --git a/internal/zenutil/run_unix_test.go b/internal/zenutil/run_unix_test.go index 000801b..d06e44c 100644 --- a/internal/zenutil/run_unix_test.go +++ b/internal/zenutil/run_unix_test.go @@ -45,8 +45,8 @@ func skip(err error) (bool, error) { // zenity was not found in path return true, err } - if err != nil && os.Getenv("DISPLAY") == "" { - // no display + if err != nil && os.Getenv("DISPLAY") == "" && os.Getenv("WSL_DISTRO_NAME") == "" { + // no display, not WSL return true, fmt.Errorf("no display: %w", err) } return false, err diff --git a/list_test.go b/list_test.go index 3a04f9f..58d178c 100644 --- a/list_test.go +++ b/list_test.go @@ -45,7 +45,7 @@ func ExampleListMultipleItems() { func TestList_timeout(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithTimeout(context.Background(), time.Second/10) + ctx, cancel := context.WithTimeout(context.Background(), time.Second/5) defer cancel() _, err := zenity.List("", nil, zenity.Context(ctx)) diff --git a/main_test.go b/main_test.go index 931eb3d..4f599e6 100644 --- a/main_test.go +++ b/main_test.go @@ -20,8 +20,8 @@ func skip(err error) (bool, error) { // zenity was not found in path return true, err } - if err != nil && os.Getenv("DISPLAY") == "" { - // no display + if err != nil && os.Getenv("DISPLAY") == "" && os.Getenv("WSL_DISTRO_NAME") == "" { + // no display, not WSL return true, fmt.Errorf("no display: %w", err) } } diff --git a/msg_test.go b/msg_test.go index 07b8f1f..bd787dd 100644 --- a/msg_test.go +++ b/msg_test.go @@ -54,7 +54,7 @@ func TestMessage_timeout(t *testing.T) { for _, tt := range msgFuncs { t.Run(tt.name, func(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithTimeout(context.Background(), time.Second/10) + ctx, cancel := context.WithTimeout(context.Background(), time.Second/5) defer cancel() err := tt.fn("text", zenity.Context(ctx)) diff --git a/pwd_test.go b/pwd_test.go index 4cd6b2d..0cfb210 100644 --- a/pwd_test.go +++ b/pwd_test.go @@ -25,7 +25,7 @@ func ExamplePassword_username() { func TestPassword_timeout(t *testing.T) { defer goleak.VerifyNone(t) - ctx, cancel := context.WithTimeout(context.Background(), time.Second/10) + ctx, cancel := context.WithTimeout(context.Background(), time.Second/5) defer cancel() _, _, err := zenity.Password(zenity.Context(ctx)) diff --git a/pwd_unix.go b/pwd_unix.go index bb77a46..b90fe32 100644 --- a/pwd_unix.go +++ b/pwd_unix.go @@ -3,6 +3,7 @@ package zenity import ( + "os/exec" "strings" "github.com/ncruces/zenity/internal/zenutil" @@ -18,8 +19,11 @@ func password(opts options) (string, string, error) { out, err := zenutil.Run(opts.ctx, args) str, err := strResult(opts, out, err) - if err == nil && opts.username { - if split := strings.SplitN(str, "|", 2); len(split) == 2 { + if opts.username { + if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 255 { + return "", "", ErrUnsupported + } + if split := strings.SplitN(str, "|", 2); err == nil && len(split) == 2 { return split[0], split[1], nil } }