feat(test): Add unit tests for all themes

Use Tmux itself by spinning up a temporary test server, load the theme,
and use "show-options" to pull out and validate relevant options that
are set by the theme.
This commit is contained in:
2019-11-29 02:47:36 +00:00
parent cae4b67003
commit 6e2e24e0f2
10 changed files with 499 additions and 0 deletions

47
test/basic_test.go Normal file
View File

@@ -0,0 +1,47 @@
package test
import (
"testing"
"github.com/jimeh/go-tmux"
"github.com/stretchr/testify/assert"
)
func TestBasicTheme(t *testing.T) {
tmuxSetup()
defer tmuxTearDown()
theme := "../basic.tmuxtheme"
_, err := tm.Exec("source-file", theme)
assert.NoErrorf(t, err, `%s: Failed to load theme`, theme)
tmuxHasOptions(t, theme, tmux.GlobalWindow, tmux.Options{
"clock-mode-colour": "red",
"clock-mode-style": "24",
"mode-style": "bg=red",
"pane-active-border-style": "fg=green",
"pane-border-style": "default",
"window-status-activity-style": "fg=yellow,bg=black",
"window-status-current-format": " #I:#W#F ",
"window-status-current-style": "fg=black,bg=red",
"window-status-format": " #I:#W#F ",
"window-status-separator": "",
})
tmuxHasOptions(t, theme, tmux.GlobalSession, tmux.Options{
"display-panes-active-colour": "default",
"display-panes-colour": "default",
"message-command-style": "default",
"message-style": "default",
"status-interval": "1",
"status-justify": "centre",
"status-left": "#S #[fg=white]» #[fg=yellow]#I #[fg=cyan]#P",
"status-left-length": "40",
"status-left-style": "fg=green,bg=black",
"status-right": "#H #[fg=white]« #[fg=yellow]%H:%M:%S #[fg=green]%d-%b-%y",
"status-right-length": "40",
"status-right-style": "fg=cyan,bg=black",
"status-style": "fg=cyan,bg=black",
})
}

46
test/default_test.go Normal file
View File

@@ -0,0 +1,46 @@
package test
import (
"testing"
"github.com/jimeh/go-tmux"
"github.com/stretchr/testify/assert"
)
func TestDefaultTheme(t *testing.T) {
tmuxSetup()
defer tmuxTearDown()
theme := "../default.tmuxtheme"
_, err := tm.Exec("source-file", theme)
assert.NoErrorf(t, err, `%s: Failed to load theme`, theme)
tmuxHasOptions(t, theme, tmux.GlobalWindow, tmux.Options{
"clock-mode-colour": "blue",
"clock-mode-style": "24",
"mode-style": "fg=black,bg=yellow",
"pane-active-border-style": "fg=green",
"pane-border-style": "fg=white",
"window-status-activity-style": "fg=green,bg=black",
"window-status-current-format": "#I:#W#F",
"window-status-current-style": "fg=black,bg=green",
"window-status-format": "#I:#W#F",
"window-status-separator": " ",
})
tmuxHasOptions(t, theme, tmux.GlobalSession, tmux.Options{
"display-panes-active-colour": "red",
"display-panes-colour": "blue",
"message-command-style": "fg=black,bg=green",
"message-style": "fg=black,bg=yellow",
"status-interval": "15",
"status-justify": "left",
"status-left": "[#S]",
"status-left-length": "10",
"status-left-style": "fg=black,bg=green",
"status-right": "\"#H\" %H:%M %d-%b-%y",
"status-right-length": "40",
"status-right-style": "fg=black,bg=green",
"status-style": "fg=black,bg=green",
})
}

8
test/go.mod Normal file
View File

@@ -0,0 +1,8 @@
module github.com/jimeh/tmux-themepack/test
go 1.13
require (
github.com/jimeh/go-tmux v0.0.2
github.com/stretchr/testify v1.4.0
)

14
test/go.sum Normal file
View File

@@ -0,0 +1,14 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jimeh/go-tmux v0.0.2 h1:oKM7E2kn+1A11XLWIZD7xVBskynkCX4ouBKcELMuzXY=
github.com/jimeh/go-tmux v0.0.2/go.mod h1:KqcevyuQeWQwdokZLQ2RisV/PYqAXoWVyzhf0ciICbw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@@ -0,0 +1,100 @@
package test
import (
"testing"
"github.com/jimeh/go-tmux"
"github.com/stretchr/testify/assert"
)
func TestPowerlineBlockThemes(t *testing.T) {
tests := []struct {
filename string
color1 string
color2 string
}{
{
filename: "../powerline/block/blue.tmuxtheme",
color1: "colour24",
color2: "colour31",
},
{
filename: "../powerline/block/cyan.tmuxtheme",
color1: "colour39",
color2: "colour75",
},
{
filename: "../powerline/block/gray.tmuxtheme",
color1: "colour245",
color2: "colour245",
},
{
filename: "../powerline/block/green.tmuxtheme",
color1: "colour100",
color2: "colour107",
},
{
filename: "../powerline/block/magenta.tmuxtheme",
color1: "colour125",
color2: "colour129",
},
{
filename: "../powerline/block/orange.tmuxtheme",
color1: "colour130",
color2: "colour130",
},
{
filename: "../powerline/block/purple.tmuxtheme",
color1: "colour90",
color2: "colour141",
},
{
filename: "../powerline/block/red.tmuxtheme",
color1: "colour88",
color2: "colour124",
},
{
filename: "../powerline/block/yellow.tmuxtheme",
color1: "colour227",
color2: "colour229",
},
}
for _, tt := range tests {
tmuxSetup()
_, err := tm.Exec("source-file", tt.filename)
assert.NoErrorf(t, err, `%s: Failed to load theme`, tt.filename)
tmuxHasOptions(t, tt.filename, tmux.GlobalWindow, tmux.Options{
"clock-mode-colour": tt.color1,
"clock-mode-style": "24",
"mode-style": "fg=black,bg=" + tt.color1,
"pane-active-border-style": "fg=" + tt.color1,
"pane-border-style": "fg=colour238",
"window-status-activity-style": "fg=" + tt.color2 + ",bg=colour233",
"window-status-current-format": " #I:#W#F ",
"window-status-current-style": "fg=black,bg=" + tt.color1,
"window-status-format": " #I:#W#F ",
"window-status-separator": "",
})
tmuxHasOptions(t, tt.filename, tmux.GlobalSession, tmux.Options{
"display-panes-active-colour": "colour245",
"display-panes-colour": "colour233",
"message-command-style": "fg=black,bg=" + tt.color1,
"message-style": "fg=black,bg=" + tt.color1,
"status-interval": "1",
"status-justify": "centre",
"status-left": "#[fg=colour233,bg=" + tt.color1 + ",bold] #S #[fg=" + tt.color1 + ",bg=colour240,nobold]\ue0b0#[fg=colour233,bg=colour240] #(whoami) #[fg=colour240,bg=colour235]\ue0b0#[fg=colour240,bg=colour235] #I:#P #[fg=colour235,bg=colour233,nobold]\ue0b0",
"status-left-length": "40",
"status-left-style": "fg=colour243,bg=colour233",
"status-right": "#[fg=colour235,bg=colour233]\ue0b2#[fg=colour240,bg=colour235] %H:%M:%S #[fg=colour240,bg=colour235]\ue0b2#[fg=colour233,bg=colour240] %d-%b-%y #[fg=colour245,bg=colour240]\ue0b2#[fg=colour233,bg=colour245,bold] #H ",
"status-right-length": "150",
"status-right-style": "fg=colour243,bg=colour233",
"status-style": "fg=colour240,bg=colour233",
})
tmuxTearDown()
}
}

View File

@@ -0,0 +1,100 @@
package test
import (
"testing"
"github.com/jimeh/go-tmux"
"github.com/stretchr/testify/assert"
)
func TestPowerlineDefaultThemes(t *testing.T) {
tests := []struct {
filename string
color1 string
color2 string
}{
{
filename: "../powerline/default/blue.tmuxtheme",
color1: "colour24",
color2: "colour33",
},
{
filename: "../powerline/default/cyan.tmuxtheme",
color1: "colour39",
color2: "colour81",
},
{
filename: "../powerline/default/gray.tmuxtheme",
color1: "colour245",
color2: "colour250",
},
{
filename: "../powerline/default/green.tmuxtheme",
color1: "colour100",
color2: "colour190",
},
{
filename: "../powerline/default/magenta.tmuxtheme",
color1: "colour125",
color2: "colour127",
},
{
filename: "../powerline/default/orange.tmuxtheme",
color1: "colour130",
color2: "colour166",
},
{
filename: "../powerline/default/purple.tmuxtheme",
color1: "colour90",
color2: "colour129",
},
{
filename: "../powerline/default/red.tmuxtheme",
color1: "colour88",
color2: "colour160",
},
{
filename: "../powerline/default/yellow.tmuxtheme",
color1: "colour227",
color2: "colour227",
},
}
for _, tt := range tests {
tmuxSetup()
_, err := tm.Exec("source-file", tt.filename)
assert.NoErrorf(t, err, `%s: Failed to load theme`, tt.filename)
tmuxHasOptions(t, tt.filename, tmux.GlobalWindow, tmux.Options{
"clock-mode-colour": tt.color1,
"clock-mode-style": "24",
"mode-style": "fg=black,bg=" + tt.color1,
"pane-active-border-style": "fg=" + tt.color1,
"pane-border-style": "fg=colour238",
"window-status-activity-style": "fg=colour245,bg=colour233",
"window-status-current-format": "#[fg=colour233,bg=black]\ue0b0#[fg=" + tt.color2 + ",nobold] #I:#W#F #[fg=colour233,bg=black,nobold]\ue0b2",
"window-status-current-style": "fg=colour235,bg=colour100",
"window-status-format": " #I:#W#F ",
"window-status-separator": "",
})
tmuxHasOptions(t, tt.filename, tmux.GlobalSession, tmux.Options{
"display-panes-active-colour": "colour245",
"display-panes-colour": "colour233",
"message-command-style": "fg=black,bg=" + tt.color1,
"message-style": "fg=black,bg=" + tt.color1,
"status-interval": "1",
"status-justify": "centre",
"status-left": "#[fg=colour233,bg=" + tt.color1 + ",bold] #S #[fg=" + tt.color1 + ",bg=colour240,nobold]\ue0b0#[fg=colour233,bg=colour240] #(whoami) #[fg=colour240,bg=colour235]\ue0b0#[fg=colour240,bg=colour235] #I:#P #[fg=colour235,bg=colour233,nobold]\ue0b0",
"status-left-length": "40",
"status-left-style": "fg=colour243,bg=colour233",
"status-right": "#[fg=colour235,bg=colour233]\ue0b2#[fg=colour240,bg=colour235] %H:%M:%S #[fg=colour240,bg=colour235]\ue0b2#[fg=colour233,bg=colour240] %d-%b-%y #[fg=colour245,bg=colour240]\ue0b2#[fg=colour233,bg=colour245,bold] #H ",
"status-right-length": "150",
"status-right-style": "fg=colour243,bg=colour233",
"status-style": "fg=colour240,bg=colour233",
})
tmuxTearDown()
}
}

View File

@@ -0,0 +1,95 @@
package test
import (
"testing"
"github.com/jimeh/go-tmux"
"github.com/stretchr/testify/assert"
)
func TestPowerlineDoubleThemes(t *testing.T) {
tests := []struct {
filename string
color1 string
color2 string
}{
{
filename: "../powerline/double/blue.tmuxtheme",
color1: "colour24",
color2: "colour33",
},
{
filename: "../powerline/double/cyan.tmuxtheme",
color1: "colour39",
color2: "colour81",
},
{
filename: "../powerline/double/green.tmuxtheme",
color1: "colour100",
color2: "colour190",
},
{
filename: "../powerline/double/magenta.tmuxtheme",
color1: "colour125",
color2: "colour127",
},
{
filename: "../powerline/double/orange.tmuxtheme",
color1: "colour130",
color2: "colour166",
},
{
filename: "../powerline/double/purple.tmuxtheme",
color1: "colour90",
color2: "colour129",
},
{
filename: "../powerline/double/red.tmuxtheme",
color1: "colour88",
color2: "colour160",
},
{
filename: "../powerline/double/yellow.tmuxtheme",
color1: "colour227",
color2: "colour227",
},
}
for _, tt := range tests {
tmuxSetup()
_, err := tm.Exec("source-file", tt.filename)
assert.NoErrorf(t, err, `%s: Failed to load theme`, tt.filename)
tmuxHasOptions(t, tt.filename, tmux.GlobalWindow, tmux.Options{
"clock-mode-colour": tt.color1,
"clock-mode-style": "24",
"mode-style": "fg=black,bg=" + tt.color1,
"pane-active-border-style": "fg=" + tt.color1,
"pane-border-style": "fg=colour238",
"window-status-activity-style": "fg=colour245,bg=colour233",
"window-status-current-format": "#[fg=colour233,bg=black]\ue0b0#[fg=" + tt.color2 + ",nobold] #I:#W#F #[fg=colour233,bg=black,nobold]\ue0b2",
"window-status-current-style": "fg=colour235,bg=colour100",
"window-status-format": " #I:#W#F ",
"window-status-separator": "",
})
tmuxHasOptions(t, tt.filename, tmux.GlobalSession, tmux.Options{
"display-panes-active-colour": "colour245",
"display-panes-colour": "colour233",
"message-command-style": "fg=black,bg=" + tt.color1,
"message-style": "fg=black,bg=" + tt.color1,
"status-interval": "1",
"status-justify": "centre",
"status-left": "#[fg=colour233,bg=" + tt.color1 + ",bold] #S #[fg=" + tt.color1 + ",bg=colour240,nobold]\ue0b0#[fg=colour233,bg=colour240] #(whoami) #[fg=colour240,bg=colour235]\ue0b0#[fg=colour240,bg=colour235] #I:#P #[fg=colour235,bg=colour233,nobold]\ue0b0",
"status-left-length": "40",
"status-left-style": "fg=colour243,bg=colour233",
"status-right": "#[fg=colour235,bg=colour233]\ue0b2#[fg=colour240,bg=colour235] %H:%M:%S #[fg=colour240,bg=colour235]\ue0b2#[fg=colour233,bg=colour240] %d-%b-%y #[fg=" + tt.color1 + ",bg=colour240]\ue0b2#[fg=colour233,bg=" + tt.color1 + ",bold] #H ",
"status-right-length": "150",
"status-right-style": "fg=colour243,bg=colour233",
"status-style": "fg=colour240,bg=colour233",
})
tmuxTearDown()
}
}

63
test/setup_test.go Normal file
View File

@@ -0,0 +1,63 @@
package test
import (
"log"
"os"
"testing"
"github.com/jimeh/go-tmux"
"github.com/stretchr/testify/assert"
)
var tm = tmux.New()
var tmuxVersion = os.Getenv("TMUX_VERSION")
var tmuxBinPath = os.Getenv("TMUX_BIN_PATH")
var tmuxConfig = os.Getenv("TMUX_CONFIG")
func tmuxSetup() {
if tmuxBinPath != "" {
tm.BinPath = tmuxBinPath
}
tm.SocketPath = "./tmux-test-socket"
if tmuxConfig != "" {
tmuxConfig = "./tmux.conf"
}
_, err := tm.Exec("-f", tmuxConfig, "new-session", "-d", "sleep", "30")
if err != nil {
log.Fatal(err)
}
}
func tmuxTearDown() {
_, err := tm.Exec("kill-server")
if err != nil {
log.Fatal(err)
}
if tm.SocketPath != "" {
err = os.Remove(tm.SocketPath)
if err != nil {
log.Fatal(err)
}
}
}
func tmuxHasOptions(t *testing.T, theme string, s tmux.Scope, m tmux.Options) {
opts, err := tm.GetOptions(s)
assert.NoErrorf(t, err, `%s: Failed to get options`, theme)
if err == nil {
for k, v := range m {
_, ok := opts[k]
assert.Truef(t, ok, `%s: Key "%s" is not available`, theme, k)
if ok {
assert.Equalf(t,
v, opts[k],
`%s: Key "%s" is not "%s"`, theme, k, v,
)
}
}
}
}

1
test/tmux.conf Normal file
View File

@@ -0,0 +1 @@
# Empty config used for tests

25
test/version_test.go Normal file
View File

@@ -0,0 +1,25 @@
package test
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTmuxVersion(t *testing.T) {
tmuxSetup()
defer tmuxTearDown()
if tmuxVersion != "" {
out, err := tm.Exec("-V")
require.NoError(t, err)
assert.Equal(
t,
"tmux "+tmuxVersion,
string(bytes.TrimSpace(out)),
)
}
}