From 6db3c8cfc24942cc8a62073c02241a7a0213e698 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 18 Oct 2022 20:00:22 +0200 Subject: [PATCH] feat(language): missing version info in .Error resolves #2957 --- src/segments/language.go | 2 ++ src/segments/language_test.go | 2 +- src/segments/ruby_test.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/segments/language.go b/src/segments/language.go index f23351d6..09e45fee 100644 --- a/src/segments/language.go +++ b/src/segments/language.go @@ -11,6 +11,7 @@ import ( const ( languageTemplate = " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} " + noVersion = "NO VERSION" ) type loadContext func() @@ -162,6 +163,7 @@ func (l *language) setVersion() error { var err error if command.getVersion == nil { if !l.env.HasCommand(command.executable) { + lastError = errors.New(noVersion) continue } versionStr, err = l.env.RunCommand(command.executable, command.args...) diff --git a/src/segments/language_test.go b/src/segments/language_test.go index b791d1a0..3de1eeaf 100644 --- a/src/segments/language_test.go +++ b/src/segments/language_test.go @@ -83,7 +83,7 @@ func TestLanguageFilesFoundButNoCommandAndVersionAndDisplayVersion(t *testing.T) } lang := bootStrapLanguageTest(args) assert.True(t, lang.Enabled()) - assert.Equal(t, "", lang.Error, "unicorn is not available") + assert.Equal(t, noVersion, lang.Error, "unicorn is not available") } func TestLanguageFilesFoundButNoCommandAndVersionAndDontDisplayVersion(t *testing.T) { diff --git a/src/segments/ruby_test.go b/src/segments/ruby_test.go index 643f3e1f..73a92c30 100644 --- a/src/segments/ruby_test.go +++ b/src/segments/ruby_test.go @@ -29,7 +29,7 @@ func TestRuby(t *testing.T) { {Case: "Ruby files", ExpectedString: "", ExpectedEnabled: true, FetchVersion: false, HasRubyFiles: true}, {Case: "Rakefile", ExpectedString: "", ExpectedEnabled: true, FetchVersion: false, HasRakeFile: true}, {Case: "Gemfile", ExpectedString: "", ExpectedEnabled: true, FetchVersion: false, HasGemFile: true}, - {Case: "Gemfile with version", ExpectedString: "", ExpectedEnabled: true, FetchVersion: true, HasGemFile: true}, + {Case: "Gemfile with version", ExpectedString: noVersion, ExpectedEnabled: true, FetchVersion: true, HasGemFile: true}, {Case: "No files with version", ExpectedString: "", ExpectedEnabled: false, FetchVersion: true}, { Case: "Version with chruby",