Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/templater/funcs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package templater

import (
stdos "os"
"maps"
"math/rand/v2"
"path/filepath"
Expand Down Expand Up @@ -33,6 +34,7 @@ func init() {
"splitArgs": splitArgs,
"IsSH": IsSH, // Deprecated
"joinPath": filepath.Join,
"joinEnv": joinEnv,
"relPath": filepath.Rel,
"merge": merge,
"spew": spew.Sdump,
Expand Down Expand Up @@ -89,6 +91,10 @@ func splitArgs(s string) ([]string, error) {
return shell.Fields(s, nil)
}

func joinEnv(elems ...string) string {
return strings.Join(elems, string(stdos.PathListSeparator))
}

// Deprecated: now always returns true
func IsSH() bool {
return true
Expand Down
31 changes: 31 additions & 0 deletions internal/templater/funcs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package templater

import (
stdos "os"
"testing"
)

func TestJoinEnv(t *testing.T) {
t.Parallel()

got := joinEnv("/tmp/tools/bin", "/usr/local/bin", "/usr/bin")
want := "/tmp/tools/bin" + string(stdos.PathListSeparator) + "/usr/local/bin" + string(stdos.PathListSeparator) + "/usr/bin"
if got != want {
t.Fatalf("joinEnv() = %q, want %q", got, want)
}
}

func TestJoinEnvTemplateFunc(t *testing.T) {
t.Parallel()

joinEnvFunc, ok := templateFuncs["joinEnv"].(func(...string) string)
if !ok {
t.Fatalf("joinEnv template function has unexpected type: %T", templateFuncs["joinEnv"])
}

got := joinEnvFunc("a", "b")
want := "a" + string(stdos.PathListSeparator) + "b"
if got != want {
t.Fatalf("template joinEnv() = %q, want %q", got, want)
}
}