zenity/internal/zenutil/run_unix_test.go

54 lines
986 B
Go
Raw Normal View History

2021-06-18 11:16:04 -04:00
// +build !windows,!darwin
package zenutil
import (
"context"
2021-07-06 20:01:22 -04:00
"fmt"
2021-06-18 11:16:04 -04:00
"os"
"os/exec"
"testing"
)
func TestRun(t *testing.T) {
_, err := Run(nil, []string{"--version"})
2021-07-06 20:01:22 -04:00
if skip, err := skip(err); skip {
2021-06-18 11:16:04 -04:00
t.Skip("skipping:", err)
}
if err != nil {
t.Fatal(err)
}
}
func TestRun_context(t *testing.T) {
_, err := Run(context.TODO(), []string{"--version"})
2021-07-06 20:01:22 -04:00
if skip, err := skip(err); skip {
2021-06-18 11:16:04 -04:00
t.Skip("skipping:", err)
}
if err != nil {
t.Fatal(err)
}
}
func TestRunProgress(t *testing.T) {
_, err := RunProgress(nil, 100, nil, []string{"--version"})
2021-07-06 20:01:22 -04:00
if skip, err := skip(err); skip {
2021-06-18 11:16:04 -04:00
t.Skip("skipping:", err)
}
if err != nil {
t.Fatal(err)
}
}
2021-07-06 20:01:22 -04:00
func skip(err error) (bool, error) {
2021-06-18 11:16:04 -04:00
if _, ok := err.(*exec.Error); ok {
2021-07-06 20:01:22 -04:00
// zenity was not found in path
return true, err
2021-06-18 11:16:04 -04:00
}
2021-07-29 11:20:50 -04:00
if err != nil && os.Getenv("DISPLAY") == "" && os.Getenv("WSL_DISTRO_NAME") == "" {
// no display, not WSL
2021-07-06 20:01:22 -04:00
return true, fmt.Errorf("no display: %w", err)
2021-06-18 11:16:04 -04:00
}
2021-07-06 20:01:22 -04:00
return false, err
2021-06-18 11:16:04 -04:00
}