| 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 requiredF 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 debug_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
"github.com/gohugoio/hugo/hugolib" |
| 20 |
) |
| 21 |
|
| 22 |
func TestTimer(t *testing.T) { |
| 23 |
files := ` |
| 24 |
-- hugo.toml -- |
| 25 |
baseURL = "https://example.org/" |
| 26 |
disableKinds = ["taxonomy", "term"] |
| 27 |
-- layouts/home.html -- |
| 28 |
{{ range seq 5 }} |
| 29 |
{{ $t := debug.Timer "foo" }} |
| 30 |
{{ seq 1 1000 }} |
| 31 |
{{ $t.Stop }} |
| 32 |
{{ end }} |
| 33 |
|
| 34 |
` |
| 35 |
b := hugolib.Test(t, files, hugolib.TestOptInfo()) |
| 36 |
|
| 37 |
b.AssertLogContains("timer: name foo count 5 duration") |
| 38 |
} |
| 39 |
|
| 40 |
func TestDebugDumpPage(t *testing.T) { |
| 41 |
files := ` |
| 42 |
-- hugo.toml -- |
| 43 |
baseURL = "https://example.org/" |
| 44 |
disableLiveReload = true |
| 45 |
[taxonomies] |
| 46 |
tag = "tags" |
| 47 |
-- content/_index.md -- |
| 48 |
--- |
| 49 |
title: "The Index" |
| 50 |
date: 2012-03-15 |
| 51 |
--- |
| 52 |
-- content/p1.md -- |
| 53 |
--- |
| 54 |
title: "The First" |
| 55 |
tags: ["a", "b"] |
| 56 |
--- |
| 57 |
-- layouts/list.html -- |
| 58 |
Dump: {{ debug.Dump . | safeHTML }} |
| 59 |
Dump Site: {{ debug.Dump site }} |
| 60 |
Dum site.Taxonomies: {{ debug.Dump site.Taxonomies | safeHTML }} |
| 61 |
-- layouts/single.html -- |
| 62 |
Dump: {{ debug.Dump . | safeHTML }} |
| 63 |
|
| 64 |
|
| 65 |
` |
| 66 |
b := hugolib.TestRunning(t, files) |
| 67 |
b.AssertFileContent("public/index.html", "Dump: {\n \"Date\": \"2012-03-15T00:00:00Z\"") |
| 68 |
} |