/*
* Copyright (c) 2013 Dario Castañé.
* This file is part of Zas.
*
* Zas is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zas is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zas. If not, see .
*/
package zas
import (
thtml "html/template"
"os"
"path/filepath"
"strings"
"testing"
"github.com/PuerkitoBio/goquery"
"github.com/darccio/zas/internal/i18n"
)
// captureStderr is defined in symlink_test.go and reused here.
// newRenderTestGenerator builds a minimal Generator suitable for calling
// render() directly, deploying into ./deploy under a fresh chdir'd temp
// directory.
func newRenderTestGenerator(t *testing.T) *Generator {
t.Helper()
t.Chdir(t.TempDir())
if err := os.MkdirAll("deploy", 0o755); err != nil {
t.Fatal(err)
}
gen := &Generator{
Config: ConfigSection{"zas": ConfigSection{"deploy": "deploy"}},
I18n: &i18n.Build{Index: i18n.Strings{}, Origin: "en"},
}
layout, err := thtml.New("layout").Funcs(helpers).Parse(`
{{.Body}}`)
if err != nil {
t.Fatal(err)
}
gen.Layout = layout
return gen
}
// render's own call to parseAndReplace used to both print the error
// directly (gen.printLine(err)) and return it as render's error, which its
// caller renderAsync already aggregates into gen.errs and reports through
// the normal single-report-per-error path - so this one error type was
// reported twice. It must now be reported exactly once, by the caller.
func TestRenderParseAndReplaceErrorNotPrintedInline(t *testing.T) {
gen := newRenderTestGenerator(t)
// An embed type nothing resolves a plugin for makes handleEmbedTags -
// and therefore render's own top-level parseAndReplace call - fail.
src := `