Skip to content

Commit

Permalink
introduce unit tests, drop auto_kill_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Nov 3, 2023
1 parent d528dbc commit daf60c7
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 37 deletions.
1 change: 0 additions & 1 deletion .github/workflows/close_stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: "Close Stale Issues"
on:
schedule:
- cron: "0 0 * * *"

jobs:
cleanup:
runs-on: ubuntu-latest
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/build.yml → .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
name: Build
name: Go
on:
push:
pull_request:
permissions:
contents: read
pull-requests: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 'Setup Go'
uses: actions/setup-go@v4
with:
go-version: '^1.20'
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Setup Go'
uses: actions/setup-go@v4
with:
go-version: '^1.21'
- name: 'Run tests'
run: make tests
- name: 'Build Vinegar'
run: make VINEGAR_GOFLAGS="--tags nogui"
2 changes: 0 additions & 2 deletions .github/workflows/vendor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
uses: actions/checkout@v3
- name: 'Setup Go'
uses: actions/setup-go@v4
with:
go-version: '^1.21'
- name: 'Make the vendor directory'
run: go mod vendor
- name: 'Package the source directory'
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ mime:
xdg-mime default $(FLATPAK).studio.desktop application/x-roblox-rbxl
xdg-mime default $(FLATPAK).studio.desktop application/x-roblox-rbxlx

tests:
$(GO) test $(GOFLAGS) ./...

clean:
rm -f vinegar robloxmutexer.exe

.PHONY: all install install-vinegar install-robloxmutexer install-desktop install-icons uninstall icons mime clean
.PHONY: all install install-vinegar install-robloxmutexer install-desktop install-icons uninstall icons mime tests clean
4 changes: 1 addition & 3 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ func (b *Binary) Run(args ...string) error {
return
}

if b.Config.AutoKillPrefix {
b.Prefix.Kill()
}
b.Prefix.Kill()
}()

if err := cmd.Run(); err != nil {
Expand Down
46 changes: 23 additions & 23 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ type Splash struct {
}

type Binary struct {
Channel string `toml:"channel"`
Launcher string `toml:"launcher"`
Renderer string `toml:"renderer"`
DiscordRPC bool `toml:"discord_rpc"`
ForcedVersion string `toml:"forced_version"`
AutoKillPrefix bool `toml:"auto_kill_prefix"`
Dxvk bool `toml:"dxvk"`
FFlags roblox.FFlags `toml:"fflags"`
Env Environment `toml:"env"`
ForcedGpu string `toml:"gpu"`
Channel string `toml:"channel"`
Launcher string `toml:"launcher"`
Renderer string `toml:"renderer"`
DiscordRPC bool `toml:"discord_rpc"`
ForcedVersion string `toml:"forced_version"`
Dxvk bool `toml:"dxvk"`
FFlags roblox.FFlags `toml:"fflags"`
Env Environment `toml:"env"`
ForcedGpu string `toml:"gpu"`
}

type Config struct {
Expand All @@ -50,6 +49,13 @@ type Config struct {
Splash Splash `toml:"splash"`
}

var (
ErrInvalidRenderer = errors.New("invalid renderer given")
ErrNeedDXVKRenderer = errors.New("dxvk is only valid with d3d renderers")
ErrWineRootAbs = errors.New("ensure that the wine root given is an absolute path")
ErrWineRootInvalid = errors.New("invalid wine root given")
)

func Load(path string) (Config, error) {
cfg := Default()

Expand All @@ -63,10 +69,6 @@ func Load(path string) (Config, error) {
return cfg, err
}

if err := cfg.globalize(); err != nil {
return cfg, err
}

return cfg, cfg.setup()
}

Expand Down Expand Up @@ -108,16 +110,14 @@ func Default() Config {
},
},
Player: Binary{
DiscordRPC: true,
Dxvk: true,
AutoKillPrefix: true,
DiscordRPC: true,
Dxvk: true,
FFlags: roblox.FFlags{
"DFIntTaskSchedulerTargetFps": 640,
},
},
Studio: Binary{
Dxvk: true,
AutoKillPrefix: true,
Dxvk: true,
},

Splash: Splash{
Expand All @@ -134,15 +134,15 @@ func Default() Config {

func (b *Binary) setup() error {
if !roblox.ValidRenderer(b.Renderer) {
return errors.New("invalid renderer given")
return ErrInvalidRenderer
}

if err := b.pickCard(); err != nil {
return err
}

if !strings.HasPrefix(b.Renderer, "D3D11") && b.Dxvk {
return errors.New("dxvk is only valid with d3d renderers")
return ErrNeedDXVKRenderer
}

b.Env.Setenv()
Expand All @@ -163,12 +163,12 @@ func (c *Config) setup() error {
bin := filepath.Join(c.WineRoot, "bin")

if !filepath.IsAbs(c.WineRoot) {
return errors.New("ensure that the wine root given is an absolute path")
return ErrWineRootAbs
}

_, err := os.Stat(filepath.Join(bin, "wine"))
if err != nil {
return fmt.Errorf("invalid wine root given: %s", err)
return fmt.Errorf("%w: %s", ErrWineRootInvalid, err)
}

c.Global.Env["PATH"] = bin + ":" + os.Getenv("PATH")
Expand Down
81 changes: 81 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package config

import (
"errors"
"path/filepath"
"testing"
)

func TestGlobal(t *testing.T) {
c := Config{
env: Environment{
"MEOW": "DEPRECATED",
},
Global: Binary{
Launcher: "meow",
Env: Environment{
"MEOW": "GLOBAL",
},
},
Player: Binary{
Env: Environment{
"MEOW": "PLAYER",
},
},
}

if err := c.globalize(); err != nil {
t.Fatal(err)
}

if c.Global.Env["MEOW"] != "DEPRECATED" {
t.Error("expected env overrides global env")
}

if c.Player.Launcher != "meow" && c.Studio.Launcher != "meow" {
t.Error("expected player or/and studio applies global launcher")
}

if c.Player.Env["MEOW"] != "PLAYER" {
t.Error("expected player overrides global env")
}

if c.Studio.Env["MEOW"] != "DEPRECATED" {
t.Error("expected studio applies global env")
}
}

func TestBinarySetup(t *testing.T) {
var b Binary

if err := b.setup(); err != nil {
t.Fatal(err)
}

b.Renderer = "Meow"
if err := b.setup(); !errors.Is(err, ErrInvalidRenderer) {
t.Error("expected renderer check")
}

b.Dxvk = true
b.Renderer = "Vulkan"
if err := b.setup(); !errors.Is(err, ErrNeedDXVKRenderer) {
t.Error("expected dxvk appropiate renderer check")
}
}

func TestSetup(t *testing.T) {
wr := t.TempDir()
c := Config{
WineRoot: wr,
}

if err := c.setup(); !errors.Is(err, ErrWineRootInvalid) {
t.Error("expected wine root wine check")
}

c.WineRoot = filepath.Join(".", wr)
if err := c.setup(); !errors.Is(err, ErrWineRootAbs) {
t.Error("expected wine root absolute path")
}
}

0 comments on commit daf60c7

Please sign in to comment.