feat(debug): print templates

This commit is contained in:
Jan De Dobbeleer 2023-08-25 12:02:49 +02:00 committed by Jan De Dobbeleer
parent a1841d21e2
commit 0f8929ed13
24 changed files with 51 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/gookit/config/v2"
"github.com/mitchellh/mapstructure"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func testClearDefaultConfig() {
@ -125,6 +126,7 @@ func TestGetPalette(t *testing.T) {
Env: map[string]string{},
Shell: "bash",
})
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
cfg := &Config{
env: env,
Palette: tc.Palette,

View file

@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/shell"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestCanWriteRPrompt(t *testing.T) {
@ -66,6 +67,7 @@ func TestPrintPWD(t *testing.T) {
env.On("Shell").Return("shell")
env.On("User").Return("user")
env.On("Host").Return("host", nil)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
Shell: "shell",
@ -163,6 +165,7 @@ func TestGetTitle(t *testing.T) {
env.On("Pwd").Return(tc.Cwd)
env.On("Home").Return("/usr/home")
env.On("PathSeparator").Return(tc.PathSeparator)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{
"USERDOMAIN": "MyCompany",
@ -223,6 +226,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
env := new(mock.MockedEnvironment)
env.On("Pwd").Return(tc.Cwd)
env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{
"USERDOMAIN": "MyCompany",

View file

@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/segments"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
const (
@ -142,6 +143,7 @@ func TestGetColors(t *testing.T) {
}
for _, tc := range cases {
env := new(mock.MockedEnvironment)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestCFSegment(t *testing.T) {
@ -63,6 +64,7 @@ func TestCFSegment(t *testing.T) {
env.On("RunCommand", "cf", []string{"version"}).Return(tc.Version, nil)
env.On("Pwd").Return("/usr/home/dev/my-app")
env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),

View file

@ -9,6 +9,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestDotnetSegment(t *testing.T) {
@ -40,6 +41,7 @@ func TestDotnetSegment(t *testing.T) {
env.On("PathSeparator").Return("")
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -11,6 +11,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
type mockedLanguageParams struct {
@ -30,6 +31,7 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*mock.MockedEnvironment
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
props := properties.Map{
properties.FetchVersion: true,
}

View file

@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestHaskell(t *testing.T) {
@ -78,6 +79,7 @@ func TestHaskell(t *testing.T) {
env.On("HasFiles", "*.hs").Return(true)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -8,6 +8,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
const (
@ -54,6 +55,7 @@ func bootStrapLanguageTest(args *languageArgs) *language {
}
env.On("Pwd").Return(cwd)
env.On("Home").Return(home)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestLua(t *testing.T) {
@ -66,6 +67,7 @@ func TestLua(t *testing.T) {
env.On("HasFiles", "*.lua").Return(true)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -29,6 +29,7 @@ func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate stri
}
env.On("Error", mock2.Anything)
env.On("Debug", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
tmpl := &template.Text{
Template: segmentTemplate,
Context: context,
@ -921,6 +922,7 @@ func TestFullPathCustomMappedLocations(t *testing.T) {
}
env.On("Flags").Return(args)
env.On("Shell").Return(shell.GENERIC)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{
"HOME": "/a/b/c",
@ -957,6 +959,7 @@ func TestPowerlevelMappedLocations(t *testing.T) {
env.On("GOOS").Return(platform.DARWIN)
env.On("PathSeparator").Return("/")
env.On("Shell").Return(shell.GENERIC)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
path := &Path{
env: env,
props: properties.Map{
@ -983,6 +986,7 @@ func TestFolderPathCustomMappedLocations(t *testing.T) {
}
env.On("Flags").Return(args)
env.On("Shell").Return(shell.GENERIC)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
path := &Path{
env: env,
props: properties.Map{
@ -1371,6 +1375,7 @@ func TestGetPwd(t *testing.T) {
}
env.On("Flags").Return(args)
env.On("Shell").Return(shell.PWSH)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
path := &Path{
env: env,
props: properties.Map{
@ -1404,6 +1409,7 @@ func TestGetFolderSeparator(t *testing.T) {
env.On("PathSeparator").Return("/")
env.On("Error", mock2.Anything)
env.On("Debug", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
path := &Path{
env: env,
}
@ -1475,6 +1481,7 @@ func TestReplaceMappedLocations(t *testing.T) {
env.On("Shell").Return(shell.FISH)
env.On("GOOS").Return(platform.DARWIN)
env.On("Home").Return("/a/b/k")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
path := &Path{
env: env,
props: properties.Map{

View file

@ -107,6 +107,7 @@ func TestPythonTemplate(t *testing.T) {
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("ResolveSymlink", mock2.Anything).Return(tc.ResolveSymlink.Path, tc.ResolveSymlink.Err)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
props := properties.Map{
properties.FetchVersion: tc.FetchVersion,
UsePythonVersionFile: true,

View file

@ -9,6 +9,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/mock"
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties"
mock2 "github.com/stretchr/testify/mock"
)
func TestQuasar(t *testing.T) {
@ -62,6 +63,7 @@ func TestQuasar(t *testing.T) {
env.On("RunCommand", "quasar", []string{"--version"}).Return(tc.Version, nil)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -9,6 +9,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestR(t *testing.T) {
@ -45,6 +46,7 @@ func TestR(t *testing.T) {
env.On("HasFiles", "*.R").Return(true)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -30,6 +30,7 @@ func TestStatusWriterEnabled(t *testing.T) {
Code: 133,
})
env.On("Error", mock2.Anything).Return(nil)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
props := properties.Map{}
if len(tc.Template) > 0 {
@ -95,6 +96,7 @@ func TestFormatStatus(t *testing.T) {
Code: 133,
})
env.On("Error", mock2.Anything).Return(nil)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
props := properties.Map{
StatusTemplate: tc.Template,
StatusSeparator: tc.Separator,

View file

@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
const (
@ -131,6 +132,7 @@ func prepareMockedEnvironment(tc *testCase) *mock.MockedEnvironment {
env.On("RunCommand", "ui5", []string{"--version"}).Return(tc.Version, nil)
env.On("Home").Return("/home/user")
env.On("Pwd").Return(WorkingDirRoot)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),

View file

@ -81,6 +81,7 @@ func TestWTTrackedTime(t *testing.T) {
cache.On("Get", FAKEAPIURL).Return(response, !tc.CacheFoundFail)
cache.On("Set", FAKEAPIURL, response, tc.CacheTimeout).Return()
env.On("Cache").Return(cache)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{"HELLO": "hello"},
@ -127,6 +128,7 @@ func TestWTGetUrl(t *testing.T) {
env := &mock.MockedEnvironment{}
env.On("Error", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{"HELLO": "hello"},
})

View file

@ -8,6 +8,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestConsoleBackgroundColorTemplate(t *testing.T) {
@ -22,6 +23,7 @@ func TestConsoleBackgroundColorTemplate(t *testing.T) {
for _, tc := range cases {
env := new(mock.MockedEnvironment)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: map[string]string{
"TERM_PROGRAM": tc.Term,

View file

@ -7,6 +7,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
func TestGlob(t *testing.T) {
@ -22,6 +23,7 @@ func TestGlob(t *testing.T) {
}
env := &mock.MockedEnvironment{}
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -27,6 +27,7 @@ func TestUrl(t *testing.T) {
})
env.On("Error", mock2.Anything)
env.On("Debug", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
for _, tc := range cases {
tmpl := &Text{
Template: tc.Template,
@ -52,6 +53,7 @@ func TestPath(t *testing.T) {
}
env := &mock.MockedEnvironment{}
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
})

View file

@ -27,6 +27,7 @@ func TestHResult(t *testing.T) {
})
env.On("Error", mock2.Anything)
env.On("Debug", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
for _, tc := range cases {
tmpl := &Text{
Template: tc.Template,

View file

@ -34,6 +34,7 @@ func TestRoundSeconds(t *testing.T) {
})
env.On("Error", mock2.Anything)
env.On("Debug", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
for _, tc := range cases {
tmpl := &Text{
Template: tc.Template,

View file

@ -31,6 +31,7 @@ func TestTrunc(t *testing.T) {
})
env.On("Error", mock2.Anything)
env.On("Debug", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
for _, tc := range cases {
tmpl := &Text{
Template: tc.Template,

View file

@ -67,6 +67,7 @@ func (c *Context) init(t *Text) {
}
func (t *Text) Render() (string, error) {
t.Env.DebugF("Rendering template: %s", t.Template)
if !strings.Contains(t.Template, "{{") || !strings.Contains(t.Template, "}}") {
return t.Template, nil
}

View file

@ -160,6 +160,7 @@ func TestRenderTemplate(t *testing.T) {
Env: make(map[string]string),
})
env.On("Error", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
for _, tc := range cases {
tmpl := &Text{
Template: tc.Template,
@ -245,6 +246,7 @@ func TestRenderTemplateEnvVar(t *testing.T) {
OS: "darwin",
})
env.On("Error", mock2.Anything)
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
tmpl := &Text{
Template: tc.Template,
Context: tc.Context,
@ -354,6 +356,7 @@ func TestSegmentContains(t *testing.T) {
env := &mock.MockedEnvironment{}
segments := platform.NewConcurrentMap()
segments.Set("Git", "foo")
env.On("DebugF", mock2.Anything, mock2.Anything).Return(nil)
env.On("TemplateCache").Return(&platform.TemplateCache{
Env: make(map[string]string),
Segments: segments,