mirror of https://github.com/liamg/aminal.git
Decouple vttest tests from user's config (#258)
* Make DefaultConfig safer Instead of having a global mutable DefaultConfig which might be changed by anything during run/test time turn DefaultConfig into a function which returns a fresh DefaultConfig. This is safer and more convenient. * Decouple vttest tests from user's config The screen capture tests were failing on my machine because the screen capture based vttest tests were using my personal config in ~/.config/aminal/config.toml. This had different colours and a fixed DPI scaling factor which mean the screen captures didn't match. The sixel tests were also failing because my login shell is a highly customised zsh. A static test config is now passed by the vttest tests and the shell is set to "/bin/sh" on Linux, OSX etc to help avoid problems due to differences between shells and shell configs.
This commit is contained in:
parent
05c45c0892
commit
4710948cd1
17
config.go
17
config.go
|
@ -22,6 +22,13 @@ func getActuallyProvidedFlags() map[string]bool {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func maybeGetConfig(override *config.Config) *config.Config {
|
||||||
|
if override != nil {
|
||||||
|
return override
|
||||||
|
}
|
||||||
|
return getConfig()
|
||||||
|
}
|
||||||
|
|
||||||
func getConfig() *config.Config {
|
func getConfig() *config.Config {
|
||||||
showVersion := false
|
showVersion := false
|
||||||
ignoreConfig := false
|
ignoreConfig := false
|
||||||
|
@ -53,7 +60,7 @@ func getConfig() *config.Config {
|
||||||
|
|
||||||
var conf *config.Config
|
var conf *config.Config
|
||||||
if ignoreConfig {
|
if ignoreConfig {
|
||||||
conf = &config.DefaultConfig
|
conf = config.DefaultConfig()
|
||||||
} else {
|
} else {
|
||||||
conf = loadConfigFile()
|
conf = loadConfigFile()
|
||||||
}
|
}
|
||||||
|
@ -83,12 +90,12 @@ func loadConfigFile() *config.Config {
|
||||||
usr, err := user.Current()
|
usr, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to get current user information: %s\n", err)
|
fmt.Printf("Failed to get current user information: %s\n", err)
|
||||||
return &config.DefaultConfig
|
return config.DefaultConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
home := usr.HomeDir
|
home := usr.HomeDir
|
||||||
if home == "" {
|
if home == "" {
|
||||||
return &config.DefaultConfig
|
return config.DefaultConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
places := []string{}
|
places := []string{}
|
||||||
|
@ -111,7 +118,7 @@ func loadConfigFile() *config.Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if b, err := config.DefaultConfig.Encode(); err != nil {
|
if b, err := config.DefaultConfig().Encode(); err != nil {
|
||||||
fmt.Printf("Failed to encode config file: %s\n", err)
|
fmt.Printf("Failed to encode config file: %s\n", err)
|
||||||
} else {
|
} else {
|
||||||
err = os.MkdirAll(filepath.Dir(places[0]), 0744)
|
err = os.MkdirAll(filepath.Dir(places[0]), 0744)
|
||||||
|
@ -124,5 +131,5 @@ func loadConfigFile() *config.Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &config.DefaultConfig
|
return config.DefaultConfig()
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,12 @@ type Config struct {
|
||||||
type KeyMappingConfig map[string]string
|
type KeyMappingConfig map[string]string
|
||||||
|
|
||||||
func Parse(data []byte) (*Config, error) {
|
func Parse(data []byte) (*Config, error) {
|
||||||
c := DefaultConfig
|
c := DefaultConfig()
|
||||||
err := toml.Unmarshal(data, &c)
|
err := toml.Unmarshal(data, c)
|
||||||
if c.KeyMapping == nil {
|
if c.KeyMapping == nil {
|
||||||
c.KeyMapping = KeyMappingConfig(map[string]string{})
|
c.KeyMapping = KeyMappingConfig(map[string]string{})
|
||||||
}
|
}
|
||||||
return &c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Encode() ([]byte, error) {
|
func (c *Config) Encode() ([]byte, error) {
|
||||||
|
|
|
@ -2,7 +2,8 @@ package config
|
||||||
|
|
||||||
import "runtime"
|
import "runtime"
|
||||||
|
|
||||||
var DefaultConfig = Config{
|
func DefaultConfig() *Config {
|
||||||
|
return &Config{
|
||||||
DebugMode: false,
|
DebugMode: false,
|
||||||
ColourScheme: ColourScheme{
|
ColourScheme: ColourScheme{
|
||||||
Cursor: strToColourNoErr("#e8dfd6"),
|
Cursor: strToColourNoErr("#e8dfd6"),
|
||||||
|
@ -26,28 +27,25 @@ var DefaultConfig = Config{
|
||||||
White: strToColourNoErr("#ffffff"),
|
White: strToColourNoErr("#ffffff"),
|
||||||
Selection: strToColourNoErr("#333366"),
|
Selection: strToColourNoErr("#333366"),
|
||||||
},
|
},
|
||||||
KeyMapping: KeyMappingConfig(map[string]string{}),
|
KeyMapping: KeyMappingConfig(map[string]string{
|
||||||
|
string(ActionCopy): addMod("c"),
|
||||||
|
string(ActionPaste): addMod("v"),
|
||||||
|
string(ActionSearch): addMod("g"),
|
||||||
|
string(ActionToggleDebug): addMod("d"),
|
||||||
|
string(ActionToggleSlomo): addMod(";"),
|
||||||
|
string(ActionReportBug): addMod("r"),
|
||||||
|
string(ActionBufferClear): addMod("k"),
|
||||||
|
}),
|
||||||
SearchURL: "https://www.google.com/search?q=$QUERY",
|
SearchURL: "https://www.google.com/search?q=$QUERY",
|
||||||
MaxLines: 1000,
|
MaxLines: 1000,
|
||||||
CopyAndPasteWithMouse: true,
|
CopyAndPasteWithMouse: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
DefaultConfig.KeyMapping[string(ActionCopy)] = addMod("c")
|
|
||||||
DefaultConfig.KeyMapping[string(ActionPaste)] = addMod("v")
|
|
||||||
DefaultConfig.KeyMapping[string(ActionSearch)] = addMod("g")
|
|
||||||
DefaultConfig.KeyMapping[string(ActionToggleDebug)] = addMod("d")
|
|
||||||
DefaultConfig.KeyMapping[string(ActionToggleSlomo)] = addMod(";")
|
|
||||||
DefaultConfig.KeyMapping[string(ActionReportBug)] = addMod("r")
|
|
||||||
DefaultConfig.KeyMapping[string(ActionBufferClear)] = addMod("k")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addMod(keys string) string {
|
func addMod(keys string) string {
|
||||||
standardMod := "ctrl + shift + "
|
standardMod := "ctrl + shift + "
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
standardMod = "super + "
|
standardMod = "super + "
|
||||||
}
|
}
|
||||||
|
|
||||||
return standardMod + keys
|
return standardMod + keys
|
||||||
}
|
}
|
||||||
|
|
8
main.go
8
main.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
|
||||||
|
"github.com/liamg/aminal/config"
|
||||||
"github.com/liamg/aminal/gui"
|
"github.com/liamg/aminal/gui"
|
||||||
"github.com/liamg/aminal/platform"
|
"github.com/liamg/aminal/platform"
|
||||||
"github.com/liamg/aminal/terminal"
|
"github.com/liamg/aminal/terminal"
|
||||||
|
@ -20,11 +21,12 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
initialize(nil)
|
initialize(nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialize(unitTestfunc callback) {
|
func initialize(unitTestfunc callback, configOverride *config.Config) {
|
||||||
conf := getConfig()
|
conf := maybeGetConfig(configOverride)
|
||||||
|
|
||||||
logger, err := getLogger(conf)
|
logger, err := getLogger(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to create logger: %s\n", err)
|
fmt.Printf("Failed to create logger: %s\n", err)
|
||||||
|
|
19
main_test.go
19
main_test.go
|
@ -6,10 +6,12 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/liamg/aminal/config"
|
||||||
"github.com/liamg/aminal/gui"
|
"github.com/liamg/aminal/gui"
|
||||||
"github.com/liamg/aminal/terminal"
|
"github.com/liamg/aminal/terminal"
|
||||||
|
|
||||||
|
@ -123,7 +125,7 @@ func TestCursorMovement(t *testing.T) {
|
||||||
g.Close()
|
g.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(testFunc)
|
initialize(testFunc, testConfig())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +161,7 @@ func TestScreenFeatures(t *testing.T) {
|
||||||
g.Close()
|
g.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(testFunc)
|
initialize(testFunc, testConfig())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +186,7 @@ func TestSixel(t *testing.T) {
|
||||||
g.Close()
|
g.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(testFunc)
|
initialize(testFunc, testConfig())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,3 +194,14 @@ func TestSixel(t *testing.T) {
|
||||||
func TestExit(t *testing.T) {
|
func TestExit(t *testing.T) {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testConfig() *config.Config {
|
||||||
|
c := config.DefaultConfig()
|
||||||
|
|
||||||
|
// Use a vanilla shell on POSIX to help ensure consistency.
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
c.Shell = "/bin/sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue