Make readFile return nil when file not found (note)

Fixes #9620
This commit is contained in:
Bjørn Erik Pedersen
2022-12-30 11:10:49 +01:00
parent dd6d0a6de1
commit 3c51625c71
2 changed files with 32 additions and 1 deletions

View File

@@ -49,3 +49,29 @@ START:|{{ range $entry := $entries }}{{ if not $entry.IsDir }}{{ $entry.Name }}|
START:|config.toml|myproject.txt|:END:
`)
}
// Issue 9620
func TestReadFileNotExists(t *testing.T) {
t.Parallel()
files := `
-- config.toml --
-- layouts/index.html --
{{ $fi := (readFile "doesnotexist") }}
{{ if $fi }}Failed{{ else }}OK{{ end }}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
},
).Build()
b.AssertFileContent("public/index.html", `
OK
`)
}