WSL test improvements.

This commit is contained in:
Nuno Cruces 2021-07-29 16:20:50 +01:00
parent 0290d566d4
commit 531f98293e
10 changed files with 17 additions and 12 deletions

View file

@ -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`")

View file

@ -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))

View file

@ -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))

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -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)
}
}

View file

@ -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))

View file

@ -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))

View file

@ -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
}
}