diff --git a/pkg/cmd/template/regular_input_test.go b/pkg/cmd/template/regular_input_test.go index 1d232f7b..b94e3f13 100644 --- a/pkg/cmd/template/regular_input_test.go +++ b/pkg/cmd/template/regular_input_test.go @@ -11,6 +11,7 @@ import ( "os" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/vmware-tanzu/carvel-ytt/pkg/cmd/template" cmdtpl "github.com/vmware-tanzu/carvel-ytt/pkg/cmd/template" @@ -87,6 +88,24 @@ organization=Acme Widgets Inc.`) assertStdoutAndStderr(t, stdout, stderr, expectedStdOut, expectedStdErr) } +func Test_Input_Marked_As_Starlark_Is_Evaluated_As_Starlark(t *testing.T) { + starlarkData := []byte(`fail("hello")`) + + filesToProcess := []*files.File{ + files.MustNewFileFromSource(files.NewBytesSource("print.star1", starlarkData)), + } + + stdout := bytes.NewBufferString("") + stderr := bytes.NewBufferString("") + testUI := ui.NewCustomWriterTTY(false, stdout, stderr) + opts := cmdtpl.NewOptions() + opts.FileMarksOpts.FileMarks = []string{"print.star1:type=starlark"} + + out := opts.RunWithFiles(cmdtpl.Input{Files: filesToProcess}, testUI) + require.Error(t, out.Err) + assert.ErrorContains(t, out.Err, "fail: hello") +} + func Test_FileMark_YAML_Shows_No_Warning(t *testing.T) { yamlData := []byte(`foo: bar`) diff --git a/pkg/files/file.go b/pkg/files/file.go index 26a6a990..5c17c448 100644 --- a/pkg/files/file.go +++ b/pkg/files/file.go @@ -246,8 +246,8 @@ func (r *File) IsLibrary() bool { return true } - // make exception for starlark files as they are just pure code - return r.matchesExt(starlarkExts) + // Starlark files are always libraries + return r.Type() == TypeStarlark } func (r *File) matchesExt(exts []string) bool {