/*
Test caveats:
Stuff like enabling DXVK/VKD3D aren't tested due to the Github API ratelimit,
I'd hate to have tests fail because of hitting that, but maybe I should just do it.
Additionally, proton and other (future) wine binaries won't be tested for the same reason.
The tutorial also isn't tested. Maybe I can add a no-pager option to enable this.
Last but not least, building wine isn't tested for obvious reasons.
*/
package cli_test
import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
"git.sr.ht/~hristoast/wem/exe"
)
// Fully (or as close to fully as is reasonably possible) test WEM via the cli by
// calling the executable and examining the output and results. The coverage report
// says "coverage: 0.0% of statements" but that is false.
// TODO: Test a 64-bit executable
func TestCli(t *testing.T) {
// Setup
dir := t.TempDir()
os.Setenv("HOME", dir)
// The installer.exe and hello-world.exe files are 32-bit Windows executables.
// See here (or the `test` dir in this repo): https://git.sr.ht/~hristoast/wem-test
helloWorldExe := fmt.Sprintf("%s/TestPrefixDir/drive_c/wem-test/hello-world.exe", dir)
helloWorldExeSpaces := fmt.Sprintf("%s/TestPrefixDir/drive_c/wem-test/hello world.exe", dir)
installerExe, _ := filepath.Abs(filepath.Join("..", "test", "installer.exe"))
installerDest := filepath.Join(dir, "installer.exe")
wemExe := filepath.Join("..", "wem")
t.Run("Does the test installer exist?", func(t *testing.T) {
stat, err := os.Stat(installerExe)
if err != nil || stat.IsDir() {
fmt.Println()
fmt.Println()
fmt.Println()
fmt.Println("The test installer executable can't be found!")
fmt.Println("Do you need to run `git submodule update && git submodule update`?")
fmt.Println()
fmt.Println()
fmt.Println()
t.Errorf("Can't find the installer exe: %s", err)
}
})
t.Run("Copy installer.exe into the test dir", func(t *testing.T) {
orig, err := os.Open(installerExe)
if err != nil {
t.Errorf("Got an error: %s", err)
}
defer orig.Close()
dest, err := os.Create(installerDest)
if err != nil {
t.Errorf("Got an error: %s", err)
}
defer dest.Close()
_, err = io.Copy(dest, orig)
if err != nil {
t.Errorf("Got an error: %s", err)
}
})
t.Run("Init an env", func(t *testing.T) {
expected := fmt.Sprintf(`Env "TEST-ENV" initialized: %s/.config/wem/TEST-ENV.cfg
`, dir)
out, err := exe.QuickExe(wemExe, []string{"init", "TEST-ENV"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if !strings.HasSuffix(out, expected) {
t.Errorf("got %s; expected: %s", out, expected)
}
splitOut := strings.Split(out, " ")
cfgFile := strings.TrimSuffix(splitOut[len(splitOut)-1], "\n")
stat, err := os.Stat(cfgFile)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("The expected cfg file is a dir!")
}
}
})
t.Run("Cfg an env", func(t *testing.T) {
expected := fmt.Sprintf(`Saved: %s/.config/wem/TEST-ENV.cfg
`, dir)
out, err := exe.QuickExe(wemExe, []string{
"cfg", "TEST-ENV",
"--info-date", "0000-00-00",
"--install-args", "c:\\\\\\wem-test",
"--install-exe", fmt.Sprintf("%s/installer.exe", dir),
"--install-expected", helloWorldExe,
"--install-workdir", dir,
"--run-exe", "hello-world.exe",
"--run-workdir", "{{.WinePrefix}}/drive_c/wem-test",
"--save",
"--wine-exe", "/usr/bin/wine",
"--wine-prefix", fmt.Sprintf("%s/TestPrefixDir", dir),
"--winetricks-path", "/usr/bin/winetricks"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if !strings.HasSuffix(out, expected) {
t.Errorf("got %s; expected: %s", out, expected)
}
expected = fmt.Sprintf(`Date = "0000-00-00"
DxvkVersion = ""
Esync = false
Fsync = false
GogSilentInstall = false
InstallArgs = ["c:\\\\\\wem-test"]
InstallExe = "%s/installer.exe"
InstallExpected = "%s"
InstallWorkDir = "%s"
Name = "TEST-ENV"
QuietRun = false
ReducePulseLatency = false
RestartPulse = false
RestoreResolution = false
RunArgs = []
RunExe = "hello-world.exe"
RunPost = ""
RunPre = ""
RunPrefix = ""
RunSuffix = ""
RunWorkDir = "%s/TestPrefixDir/drive_c/wem-test"
Sandbox = false
SandboxBlacklist = []
SandboxCpu = 0
SandboxDns = ""
SandboxIpcNamespace = false
SandboxMachineId = false
SandboxNetNone = false
SandboxNoDbus = false
SandboxNoPrinters = false
SandboxNoU2f = false
SandboxPrivateCache = false
SandboxPrivateCwd = false
SandboxPrivateTmp = false
SandboxWhitelist = []
SingleCore = false
SysEnvVars = []
VirtualDesktop = ""
Vkd3dVersion = ""
VulkanIcdLoader = ""
WineArch = "win64"
WineArgs = []
WineDllOverrides = ""
WineExe = "/usr/bin/wine"
WinePrefix = "%s/TestPrefixDir"
WinetricksPath = "/usr/bin/winetricks"
`, dir, helloWorldExe, dir, dir, dir)
out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST-ENV"}...)
if out != expected {
t.Errorf("got: %s; expected: %s", out, expected)
}
// Test --no-unchanged
expected = fmt.Sprintf(`Date = "0000-00-00"
InstallArgs = ["c:\\\\\\wem-test"]
InstallExe = "%s/installer.exe"
InstallExpected = "%s"
InstallWorkDir = "%s"
Name = "TEST-ENV"
RunExe = "hello-world.exe"
RunWorkDir = "%s/TestPrefixDir/drive_c/wem-test"
WineArch = "win64"
WineExe = "/usr/bin/wine"
WinePrefix = "%s/TestPrefixDir"
WinetricksPath = "/usr/bin/winetricks"
`, dir, helloWorldExe, dir, dir, dir)
out, _ = exe.QuickExe(wemExe, []string{"cfg", "--no-unchanged", "TEST-ENV"}...)
if out != expected {
t.Errorf("got: %s; expected: %s", out, expected)
}
})
//TODO: Test run with skip-install
//TODO: Test with no install expected and other "bad" conditions
t.Run("Install an env", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"install", "TEST-ENV"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
stat, err := os.Stat(helloWorldExe)
if err != nil {
t.Errorf("Got an error while checking for hello-world.exe's existence: %s", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("Got an error while checking for hello-world.exe's existence: it is apparently a directory")
}
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "Welcome to the WEM Test Installer!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Installing 'c:\\wem-test\\hello-world.exe' ..."
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = fmt.Sprintf("Install completed! Wrote: %d bytes.", stat.Size())
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Exited without any errors"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Install an env (again)", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"install", "TEST-ENV"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "INFO: The \"InstallExpected\" file was found!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = fmt.Sprintf("----> %s", helloWorldExe)
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "INFO: \"TEST-ENV\" is installed."
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Install an env (again) with run", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--skip-run"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "INFO: The \"InstallExpected\" file was found!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = fmt.Sprintf("----> %s", helloWorldExe)
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "INFO: \"TEST-ENV\" is installed."
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Install an env (again) with run (again, but actually install this time)", func(t *testing.T) {
err := os.Remove(helloWorldExe)
if err != nil {
t.Errorf("Got an error: %s", err)
}
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--skip-run"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
stat, err := os.Stat(helloWorldExe)
if err != nil {
t.Errorf("Got an error while checking for hello-world.exe's existence: %s", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("Got an error while checking for hello-world.exe's existence: it is apparently a directory")
}
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "Welcome to the WEM Test Installer!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Installing 'c:\\wem-test\\hello-world.exe' ..."
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = fmt.Sprintf("Install completed! Wrote: %d bytes.", stat.Size())
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Exited without any errors"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
//TODO: Test winecfg and winetricks
//TODO: Test using args with run and other commands to change configured values
t.Run("Run an env", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "Hello, world!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Exited without any errors"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Exec in an env", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", helloWorldExe}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "Hello, world!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Exec in an env with an arg", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", helloWorldExe, "--exec-args", "test"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "Hello, testing!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Exec in an env with rendering", func(t *testing.T) {
exeStr := "{{.RunWorkDir}}/hello-world.exe"
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", exeStr}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "Hello, world!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Exec in an env (dry-run)", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", installerExe, "--exec-args", "C:\\execTest\\Path\\One", "--dry-run"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := fmt.Sprintf("/usr/bin/wine %s C:\\execTest\\Path\\One", installerExe)
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Install an env (again) with exec", func(t *testing.T) {
expectedExe := fmt.Sprintf("%s/TestPrefixDir/drive_c/execTest/Path/One/hello-world.exe", dir)
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", installerExe, "--exec-args", "C:\\execTest\\Path\\One"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
stat, err := os.Stat(expectedExe)
if err != nil {
t.Errorf("Got an error while checking for hello-world.exe's existence: %s", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("Got an error while checking for hello-world.exe's existence: it is apparently a directory")
}
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := fmt.Sprintf("Exec: %s C:\\execTest\\Path\\One", installerExe)
if !strings.Contains(out, expected) {
t.Errorf("got: %s; expected: %s", out, expected)
}
expected = "Welcome to the WEM Test Installer!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Installing 'C:\\execTest\\Path\\One\\hello-world.exe' ..."
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = fmt.Sprintf("Install completed! Wrote: %d bytes.", stat.Size())
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Completed without errors"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Generate completions", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"completion", "--fish", "--bash"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
bashFile := fmt.Sprintf("%s/.config/bash/completions/wem.bash", dir)
fishFile := fmt.Sprintf("%s/.config/fish/completions/wem.fish", dir)
stat, err := os.Stat(bashFile)
if err != nil {
t.Errorf("Got an error checking for the bash file's existence: %v", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("The bash file is apparently a dir!")
}
}
stat, err = os.Stat(fishFile)
if err != nil {
t.Errorf("Got an error checking for the fish file's existence: %v", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("The fish file is apparently a dir!")
}
}
bashContent, err := os.ReadFile(bashFile)
if err != nil {
t.Errorf("Got an error reading the bash file: %s", err)
}
bashText := string(bashContent)
expected := " Generated by WEM "
if !strings.Contains(bashText, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "complete -W \"build completion init install cfg ge-wine list man run tutorial\" wem"
if !strings.Contains(bashText, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
fishContent, err := os.ReadFile(fishFile)
if err != nil {
t.Errorf("Got an error reading the fish file: %s", err)
}
fishText := string(fishContent)
expected = " Generated by WEM "
if !strings.Contains(fishText, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "# Regenerate completions after installing GE Wine to complete them!"
if !strings.Contains(fishText, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "# Regenerate completions after building wine to complete them!"
if !strings.Contains(fishText, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
//TODO: is it worth it to test more of the fish file's output?
if !strings.Contains(out, fmt.Sprintf("Bash completions have been generated at: %s", bashFile)) {
t.Errorf("got: missing expected output; expected: %s", fmt.Sprintf("Bash completions have been generated at: %s", bashFile))
}
if !strings.Contains(out, fmt.Sprintf("Add this to your .bashrc to use: source %s", bashFile)) {
t.Errorf("got: missing expected output; expected: %s", fmt.Sprintf("Add this to your .bashrc to use: source %s", bashFile))
}
if !strings.Contains(out, fmt.Sprintf("Fish completions have been generated at: %s", fishFile)) {
t.Errorf("got: missing expected output; expected: %s", fmt.Sprintf("Fish completions have been generated at: %s", fishFile))
}
})
//TODO: test list
//TODO: I can't actually get expected to be the right value...
// t.Run("List envs", func(t *testing.T) {
// out, err := exe.QuickExe(wemExe, []string{"list"}...)
// if err != nil {
// t.Errorf("Got an error: %s", err)
// }
// expected := fmt.Sprintf(`========== Envs:
// TEST-ENV: %s/.config/wem/TEST-ENV.cfg
// `, dir)
// if out != expected {
// t.Errorf("expected: %s; got: %s", expected, out)
// }
// })
t.Run("Test the manpage", func(t *testing.T) {
manpageFile := filepath.Join(dir, "wem.6")
out, err := exe.QuickExe(wemExe, []string{"man", "--out", manpageFile}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
expected := "WEM manpage written to: " + manpageFile
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
stat, err := os.Stat(manpageFile)
if err != nil {
t.Errorf("Got an error checking for the manpage file's existence: %v", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("The manpage file is apparently a dir!")
}
}
manpageContent, err := os.ReadFile(manpageFile)
if err != nil {
t.Errorf("Got an error reading the manpage file: %s", err)
}
manpageText := string(manpageContent)
expected = ".SH BUGS"
if !strings.Contains(manpageText, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
expected = "Please see the project issue tracker \\[la]https://todo.sr.ht/~hristoast/WEM\\[ra] for all known bugs and planned features."
if !strings.Contains(manpageText, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
// Installing without the right options configured should return an error
t.Run("Cfg an env (with no install opts)", func(t *testing.T) {
expected := fmt.Sprintf(`Saved: %s/.config/wem/TEST-ENV.cfg
`, dir)
out, err := exe.QuickExe(wemExe, []string{
"cfg", "TEST-ENV",
"--info-date", "0000-00-00",
"--no-install-args",
"--no-install-exe",
"--no-install-expected",
"--no-install-workdir",
"--run-exe", "hello-world.exe",
"--run-workdir", "{{.WinePrefix}}/drive_c/wem-test",
"--save",
"--wine-exe", "/usr/bin/wine",
"--wine-prefix", fmt.Sprintf("%s/TestPrefixDir", dir),
"--winetricks-path", "/usr/bin/winetricks"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if !strings.HasSuffix(out, expected) {
t.Errorf("got %s; expected: %s", out, expected)
}
expected = fmt.Sprintf(`Date = "0000-00-00"
DxvkVersion = ""
Esync = false
Fsync = false
GogSilentInstall = false
InstallArgs = []
InstallExe = ""
InstallExpected = ""
InstallWorkDir = ""
Name = "TEST-ENV"
QuietRun = false
ReducePulseLatency = false
RestartPulse = false
RestoreResolution = false
RunArgs = []
RunExe = "hello-world.exe"
RunPost = ""
RunPre = ""
RunPrefix = ""
RunSuffix = ""
RunWorkDir = "%s/TestPrefixDir/drive_c/wem-test"
Sandbox = false
SandboxBlacklist = []
SandboxCpu = 0
SandboxDns = ""
SandboxIpcNamespace = false
SandboxMachineId = false
SandboxNetNone = false
SandboxNoDbus = false
SandboxNoPrinters = false
SandboxNoU2f = false
SandboxPrivateCache = false
SandboxPrivateCwd = false
SandboxPrivateTmp = false
SandboxWhitelist = []
SingleCore = false
SysEnvVars = []
VirtualDesktop = ""
Vkd3dVersion = ""
VulkanIcdLoader = ""
WineArch = "win64"
WineArgs = []
WineDllOverrides = ""
WineExe = "/usr/bin/wine"
WinePrefix = "%s/TestPrefixDir"
WinetricksPath = "/usr/bin/winetricks"
`, dir, dir)
out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST-ENV"}...)
if out != expected {
t.Errorf("got: %s; expected: %s", out, expected)
}
})
t.Run("Install an env (no opts)", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"install", "TEST-ENV"}...)
if err == nil {
t.Error("Installing with no options should return an error")
}
stat, err := os.Stat(helloWorldExe)
if err != nil {
t.Errorf("Got an error while checking for hello-world.exe's existence: %s", err)
}
if stat != nil {
if stat.IsDir() {
t.Error("Got an error while checking for hello-world.exe's existence: it is apparently a directory")
}
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
if strings.Contains(out, "INFO: The \"InstallExpected\" file was found!") {
t.Error("got: InstallExpected found message; expected: don't get that message")
}
if strings.Contains(out, "----> ") {
t.Error("got: ----> ; expected: don't get that")
}
if strings.Contains(out, "INFO: \"TEST-ENV\" is installed.") {
t.Error("got: is installed message; expected: don't get that message")
}
})
// Changing the InfoName field should not change the name of the cfg file for the env
t.Run("Cfg an env (change InfoName)", func(t *testing.T) {
expected := fmt.Sprintf(`Saved: %s/.config/wem/TEST-ENV.cfg
`, dir)
out, err := exe.QuickExe(wemExe, []string{
"cfg", "TEST-ENV",
"--info-date", "0000-00-00",
"--info-name", "NEW NAME",
"--run-exe", "hello-world.exe",
"--run-workdir", "{{.WinePrefix}}/drive_c/wem-test",
"--save",
"--wine-exe", "/usr/bin/wine",
"--wine-prefix", fmt.Sprintf("%s/TestPrefixDir", dir),
"--winetricks-path", "/usr/bin/winetricks"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if !strings.HasSuffix(out, expected) {
t.Errorf("got %s; expected: %s", out, expected)
}
expected = fmt.Sprintf(`Date = "0000-00-00"
DxvkVersion = ""
Esync = false
Fsync = false
GogSilentInstall = false
InstallArgs = []
InstallExe = ""
InstallExpected = ""
InstallWorkDir = ""
Name = "NEW NAME"
QuietRun = false
ReducePulseLatency = false
RestartPulse = false
RestoreResolution = false
RunArgs = []
RunExe = "hello-world.exe"
RunPost = ""
RunPre = ""
RunPrefix = ""
RunSuffix = ""
RunWorkDir = "%s/TestPrefixDir/drive_c/wem-test"
Sandbox = false
SandboxBlacklist = []
SandboxCpu = 0
SandboxDns = ""
SandboxIpcNamespace = false
SandboxMachineId = false
SandboxNetNone = false
SandboxNoDbus = false
SandboxNoPrinters = false
SandboxNoU2f = false
SandboxPrivateCache = false
SandboxPrivateCwd = false
SandboxPrivateTmp = false
SandboxWhitelist = []
SingleCore = false
SysEnvVars = []
VirtualDesktop = ""
Vkd3dVersion = ""
VulkanIcdLoader = ""
WineArch = "win64"
WineArgs = []
WineDllOverrides = ""
WineExe = "/usr/bin/wine"
WinePrefix = "%s/TestPrefixDir"
WinetricksPath = "/usr/bin/winetricks"
`, dir, dir)
out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST-ENV"}...)
if out != expected {
t.Errorf("got: %s; expected: %s", out, expected)
}
})
t.Run("Copy hello-world.exe to a new file with a space in the name", func(t *testing.T) {
orig, err := os.Open(helloWorldExe)
if err != nil {
t.Errorf("Got an error: %s", err)
}
defer orig.Close()
dest, err := os.Create(helloWorldExeSpaces)
if err != nil {
t.Errorf("Got an error: %s", err)
}
defer dest.Close()
_, err = io.Copy(dest, orig)
if err != nil {
t.Errorf("Got an error: %s", err)
}
})
t.Run("Exec an exe with a space in the name", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", helloWorldExeSpaces}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := "Hello, world!"
if !strings.Contains(out, expected) {
t.Errorf("got: missing expected output; expected: %s", expected)
}
})
t.Run("Exec an exe with a space in the name dry run to ensure it is quoted", func(t *testing.T) {
out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", helloWorldExeSpaces, "--dry-run"}...)
if err != nil {
t.Errorf("Got an error: %s", err)
}
if strings.Contains(out, "Disable DXVK") {
t.Error("got: Disable DXVK message; expected: don't get that message")
}
if strings.Contains(out, "Disable VKD3D") {
t.Error("got: Disable VKD3D message; expected: don't get that message")
}
expected := fmt.Sprintf("cd %s/TestPrefixDir/drive_c/wem-test; WINEARCH=win64 WINEPREFIX=%s/TestPrefixDir /usr/bin/wine %s/TestPrefixDir/drive_c/wem-test/hello\\ world.exe\n", dir, dir, dir)
if !strings.HasSuffix(out, expected) {
t.Errorf("got: %s; expected: %s", out, expected)
}
})
// Clean everything up
os.RemoveAll(dir)
}