mirror of
https://github.com/Cheviiot/Vintner.git
synced 2026-08-03 15:57:24 +00:00
Make the wine-not-found error actionable
FindWine's error used to just say wine64/wine weren't on PATH, with no
next step - surface the exact install fix ("install the wine
package") instead of leaving the reader to figure that out
themselves.
This commit is contained in:
@@ -14,5 +14,5 @@ func FindWine() (string, error) {
|
|||||||
if p, err := exec.LookPath("wine"); err == nil {
|
if p, err := exec.LookPath("wine"); err == nil {
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("neither wine64 nor wine found in PATH")
|
return "", fmt.Errorf("neither wine64 nor wine found in PATH (install the wine package)")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package wineenv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func fakeBinary(t *testing.T, name string) {
|
||||||
|
t.Helper()
|
||||||
|
bin := t.TempDir()
|
||||||
|
path := filepath.Join(bin, name)
|
||||||
|
if err := os.WriteFile(path, []byte("#!/bin/sh\n"), 0o755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Setenv("PATH", bin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindWinePrefersWine64(t *testing.T) {
|
||||||
|
bin := t.TempDir()
|
||||||
|
for _, name := range []string{"wine64", "wine"} {
|
||||||
|
if err := os.WriteFile(filepath.Join(bin, name), []byte("#!/bin/sh\n"), 0o755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.Setenv("PATH", bin)
|
||||||
|
|
||||||
|
got, err := FindWine()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if filepath.Base(got) != "wine64" {
|
||||||
|
t.Errorf("FindWine() = %q, want wine64 to be preferred over wine", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindWineFallsBackToWine(t *testing.T) {
|
||||||
|
fakeBinary(t, "wine")
|
||||||
|
|
||||||
|
got, err := FindWine()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if filepath.Base(got) != "wine" {
|
||||||
|
t.Errorf("FindWine() = %q, want wine", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindWineErrorIsActionable(t *testing.T) {
|
||||||
|
t.Setenv("PATH", t.TempDir()) // empty dir, neither binary present
|
||||||
|
|
||||||
|
_, err := FindWine()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected an error when neither wine64 nor wine is on PATH")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "install") {
|
||||||
|
t.Errorf("FindWine() error = %q, want it to say what to install (matching msiextract/cabextract's error style)", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user