~hristoast/wem

870706716578c50986d8f63eaa7c754c557f6086 — Hristos N. Triantafillou 1 year, 20 days ago 945a2a2
Allow - in env names, and properly handle names on init
3 files changed, 36 insertions(+), 32 deletions(-)

M cli/main.go
M cli/main_test.go
M env/main.go
M cli/main.go => cli/main.go +6 -2
@@ 104,9 104,13 @@ func ProcessArgs() {
				SysOpts:     &env.SysOpts{},
			}
			a.applyArgs(we)
			err := cmd.Init(c, we, envName)
			name, err := env.Slugify(envName)
			if err != nil {
				log.Fatal(err)
				log.Fatal(err.Error())
			}
			err = cmd.Init(c, we, name)
			if err != nil {
				log.Fatal(err.Error())
			}
		}


M cli/main_test.go => cli/main_test.go +29 -29
@@ 76,9 76,9 @@ func TestCli(t *testing.T) {
	})

	t.Run("Init an env", func(t *testing.T) {
		expected := fmt.Sprintf(`Env "TEST" initialized: %s/.config/wem/TEST.cfg
		expected := fmt.Sprintf(`Env "TEST-ENV" initialized: %s/.config/wem/TEST-ENV.cfg
`, dir)
		out, err := exe.QuickExe(wemExe, []string{"init", "TEST"}...)
		out, err := exe.QuickExe(wemExe, []string{"init", "TEST-ENV"}...)
		if err != nil {
			t.Errorf("Got an error: %s", err)
		}


@@ 100,10 100,10 @@ func TestCli(t *testing.T) {
	})

	t.Run("Cfg an env", func(t *testing.T) {
		expected := fmt.Sprintf(`Saved: %s/.config/wem/TEST.cfg
		expected := fmt.Sprintf(`Saved: %s/.config/wem/TEST-ENV.cfg
`, dir)
		out, err := exe.QuickExe(wemExe, []string{
			"cfg", "TEST",
			"cfg", "TEST-ENV",
			"--info-date", "0000-00-00",
			"--install-args", "c:\\\\\\wem-test",
			"--install-exe", fmt.Sprintf("%s/installer.exe", dir),


@@ 131,7 131,7 @@ InstallArgs = ["c:\\\\\\wem-test"]
InstallExe = "%s/installer.exe"
InstallExpected = "%s"
InstallWorkDir = "%s"
Name = "TEST"
Name = "TEST-ENV"
QuietRun = false
ReducePulseLatency = false
RestartPulse = false


@@ 156,7 156,7 @@ WinePrefix = "%s/TestPrefixDir"
WinetricksPath = "/usr/bin/winetricks"

`, dir, helloWorldExe, dir, dir, dir)
		out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST"}...)
		out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST-ENV"}...)
		if out != expected {
			t.Errorf("got: %s; expected: %s", out, expected)
		}


@@ 165,7 165,7 @@ WinetricksPath = "/usr/bin/winetricks"
	//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"}...)
		out, err := exe.QuickExe(wemExe, []string{"install", "TEST-ENV"}...)
		if err != nil {
			t.Errorf("Got an error: %s", err)
		}


@@ 203,14 203,14 @@ WinetricksPath = "/usr/bin/winetricks"
			t.Errorf("got: missing expected output; expected: %s", expected)
		}

		expected = "Install \"TEST\" (0000-00-00) exited without any errors"
		expected = "Install \"TEST-ENV\" (0000-00-00) 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"}...)
		out, err := exe.QuickExe(wemExe, []string{"install", "TEST-ENV"}...)
		if err != nil {
			t.Errorf("Got an error: %s", err)
		}


@@ 233,14 233,14 @@ WinetricksPath = "/usr/bin/winetricks"
			t.Errorf("got: missing expected output; expected: %s", expected)
		}

		expected = "INFO: \"TEST\" is installed."
		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", "--skip-run"}...)
		out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--skip-run"}...)
		if err != nil {
			t.Errorf("Got an error: %s", err)
		}


@@ 263,7 263,7 @@ WinetricksPath = "/usr/bin/winetricks"
			t.Errorf("got: missing expected output; expected: %s", expected)
		}

		expected = "INFO: \"TEST\" is installed."
		expected = "INFO: \"TEST-ENV\" is installed."
		if !strings.Contains(out, expected) {
			t.Errorf("got: missing expected output; expected: %s", expected)
		}


@@ 275,7 275,7 @@ WinetricksPath = "/usr/bin/winetricks"
			t.Errorf("Got an error: %s", err)
		}

		out, err := exe.QuickExe(wemExe, []string{"run", "TEST", "--skip-run"}...)
		out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--skip-run"}...)
		if err != nil {
			t.Errorf("Got an error: %s", err)
		}


@@ 313,7 313,7 @@ WinetricksPath = "/usr/bin/winetricks"
			t.Errorf("got: missing expected output; expected: %s", expected)
		}

		expected = "Install \"TEST\" (0000-00-00) exited without any errors"
		expected = "Install \"TEST-ENV\" (0000-00-00) exited without any errors"
		if !strings.Contains(out, expected) {
			t.Errorf("got: missing expected output; expected: %s", expected)
		}


@@ 322,7 322,7 @@ WinetricksPath = "/usr/bin/winetricks"
	//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"}...)
		out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV"}...)
		if err != nil {
			t.Errorf("Got an error: %s", err)
		}


@@ 340,14 340,14 @@ WinetricksPath = "/usr/bin/winetricks"
			t.Errorf("got: missing expected output; expected: %s", expected)
		}

		expected = "Run \"TEST\" (0000-00-00) exited without any errors"
		expected = "Run \"TEST-ENV\" (0000-00-00) 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", "--exec", helloWorldExe}...)
		out, err := exe.QuickExe(wemExe, []string{"run", "TEST-ENV", "--exec", helloWorldExe}...)
		if err != nil {
			t.Errorf("Got an error: %s", err)
		}


@@ 367,7 367,7 @@ WinetricksPath = "/usr/bin/winetricks"
	})

	t.Run("Exec in an env (dry-run)", func(t *testing.T) {
		out, err := exe.QuickExe(wemExe, []string{"run", "TEST", "--exec", installerExe, "--exec-args", "C:\\execTest\\Path\\One", "--dry-run"}...)
		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)
		}


@@ 388,7 388,7 @@ WinetricksPath = "/usr/bin/winetricks"

	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", "--exec", installerExe, "--exec-args", "C:\\execTest\\Path\\One"}...)
		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)


@@ 522,7 522,7 @@ WinetricksPath = "/usr/bin/winetricks"
	// 			t.Errorf("Got an error: %s", err)
	// 		}
	// 		expected := fmt.Sprintf(`========== Envs:
	// TEST:	%s/.config/wem/TEST.cfg
	// TEST-ENV:	%s/.config/wem/TEST-ENV.cfg
	// `, dir)
	// 		if out != expected {
	// 			t.Errorf("expected: %s; got: %s", expected, out)


@@ 570,10 570,10 @@ WinetricksPath = "/usr/bin/winetricks"

	// 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.cfg
		expected := fmt.Sprintf(`Saved: %s/.config/wem/TEST-ENV.cfg
`, dir)
		out, err := exe.QuickExe(wemExe, []string{
			"cfg", "TEST",
			"cfg", "TEST-ENV",
			"--info-date", "0000-00-00",
			"--no-install-args",
			"--no-install-exe",


@@ 601,7 601,7 @@ InstallArgs = []
InstallExe = ""
InstallExpected = ""
InstallWorkDir = ""
Name = "TEST"
Name = "TEST-ENV"
QuietRun = false
ReducePulseLatency = false
RestartPulse = false


@@ 626,14 626,14 @@ WinePrefix = "%s/TestPrefixDir"
WinetricksPath = "/usr/bin/winetricks"

`, dir, dir)
		out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST"}...)
		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"}...)
		out, err := exe.QuickExe(wemExe, []string{"install", "TEST-ENV"}...)
		if err == nil {
			t.Error("Installing with no options should return an error")
		}


@@ 664,17 664,17 @@ WinetricksPath = "/usr/bin/winetricks"
			t.Error("got: ----> ; expected: don't get that")
		}

		if strings.Contains(out, "INFO: \"TEST\" is installed.") {
		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.cfg
		expected := fmt.Sprintf(`Saved: %s/.config/wem/TEST-ENV.cfg
`, dir)
		out, err := exe.QuickExe(wemExe, []string{
			"cfg", "TEST",
			"cfg", "TEST-ENV",
			"--info-date", "0000-00-00",
			"--info-name", "NEW NAME",
			"--run-exe", "hello-world.exe",


@@ 724,7 724,7 @@ WinePrefix = "%s/TestPrefixDir"
WinetricksPath = "/usr/bin/winetricks"

`, dir, dir)
		out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST"}...)
		out, _ = exe.QuickExe(wemExe, []string{"cfg", "TEST-ENV"}...)
		if out != expected {
			t.Errorf("got: %s; expected: %s", out, expected)
		}

M env/main.go => env/main.go +1 -1
@@ 667,7 667,7 @@ func (e *WineEnv) Slug() (string, error) {
}

func Slugify(name string) (string, error) {
	reg, err := regexp.Compile("[^a-zA-Z0-9]+")
	reg, err := regexp.Compile(`[^a-zA-Z0-9\-]+`)
	if err != nil {
		return "", err
	}