Debian Codegraph @

tpl/fmt/fmt_integration_test.go

raw
1 // Copyright 2024 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package fmt_test
15
16 import (
17 "testing"
18
19 qt "github.com/frankban/quicktest"
20 "github.com/gohugoio/hugo/hugolib"
21 )
22
23 // Issue #11506
24 func TestErroridf(t *testing.T) {
25 t.Parallel()
26
27 files := `
28 -- hugo.toml --
29 disableKinds = ['page','rss','section','sitemap','taxonomy','term']
30 ignoreErrors = ['error-b','error-C']
31 -- layouts/home.html --
32 {{ erroridf "error-a" "%s" "a"}}
33 {{ erroridf "error-b" "%s" "b"}}
34 {{ erroridf "error-C" "%s" "C"}}
35 {{ erroridf "error-c" "%s" "c"}}
36 {{ erroridf "error-d" "%s" "D"}}
37 `
38
39 b, err := hugolib.TestE(t, files)
40
41 b.Assert(err, qt.IsNotNil)
42 b.AssertLogMatches(`ERROR a\nYou can suppress this error by adding the following to your project configuration:\nignoreLogs = \['error-a'\]`)
43 b.AssertLogMatches(`ERROR D`)
44 b.AssertLogMatches(`! ERROR C`)
45 b.AssertLogMatches(`! ERROR c`)
46 }
47
48 func TestWarnidf(t *testing.T) {
49 t.Parallel()
50
51 files := `
52 -- hugo.toml --
53 disableKinds = ['page','rss','section','sitemap','taxonomy','term']
54 ignoreLogs = ['warning-b', 'WarniNg-C']
55 -- layouts/home.html --
56 {{ warnidf "warning-a" "%s" "a"}}
57 {{ warnidf "warning-b" "%s" "b"}}
58 {{ warnidf "warNing-C" "%s" "c"}}
59 `
60
61 b := hugolib.Test(t, files, hugolib.TestOptWarn())
62 b.AssertLogContains("WARN a", "You can suppress this warning", "ignoreLogs", "['warning-a']")
63 b.AssertLogContains("! ['warning-b']")
64 b.AssertLogContains("! ['warning-c']")
65 }