Remove ShowPlan

It is out of sync with reality, has some disabled tests, and the cost
of getting it up-to-date is too high to be worth it.
This commit is contained in:
Bjørn Erik Pedersen 2016-11-23 16:35:49 +01:00
parent a6d584bfb6
commit ff2498ee89
4 changed files with 1 additions and 249 deletions

View file

@ -19,24 +19,5 @@ import (
var checkCmd = &cobra.Command{ var checkCmd = &cobra.Command{
Use: "check", Use: "check",
Short: "Check content in the source directory", Short: "Contains some verification checks",
Long: `Hugo will perform some basic analysis on the content provided
and will give feedback.`,
}
func init() {
initHugoBuilderFlags(checkCmd)
checkCmd.RunE = check
}
func check(cmd *cobra.Command, args []string) error {
if err := InitializeConfig(checkCmd); err != nil {
return err
}
if err := initSites(); err != nil {
return err
}
return Hugo.Analyze()
} }

View file

@ -15,7 +15,6 @@ package hugolib
import ( import (
"fmt" "fmt"
"os"
"strings" "strings"
"sync" "sync"
@ -151,16 +150,6 @@ type BuildCfg struct {
whatChanged *whatChanged whatChanged *whatChanged
} }
// Analyze prints a build report to Stdout.
// Useful for debugging.
func (h *HugoSites) Analyze() error {
if err := h.Build(BuildCfg{SkipRender: true}); err != nil {
return err
}
s := h.Sites[0]
return s.ShowPlan(os.Stdout)
}
func (h *HugoSites) renderCrossSitesArtifacts() error { func (h *HugoSites) renderCrossSitesArtifacts() error {
if !h.multilingual.enabled() { if !h.multilingual.enabled() {

View file

@ -1,67 +0,0 @@
// Copyright 2015 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hugolib
import (
"fmt"
"io"
)
// ShowPlan prints a build plan to the given Writer.
// Useful for debugging.
func (s *Site) ShowPlan(out io.Writer) (err error) {
if s.Source == nil || len(s.Source.Files()) <= 0 {
fmt.Fprintf(out, "No source files provided.\n")
}
for _, p := range s.AllPages {
fmt.Fprintf(out, "%s", p.Source.Path())
if p.IsRenderable() {
fmt.Fprintf(out, " (renderer: markdown)")
} else {
fmt.Fprintf(out, " (renderer: n/a)")
}
if s.owner.tmpl != nil {
for _, l := range p.layouts() {
fmt.Fprintf(out, " (layout: %s, exists: %t)", l, s.owner.tmpl.Lookup(l) != nil)
}
}
fmt.Fprintf(out, "\n")
fmt.Fprintf(out, " canonical => ")
if s.targets.page == nil {
fmt.Fprintf(out, "%s\n\n", "!no target specified!")
continue
}
trns, err := s.pageTarget().Translate(p.TargetPath())
if err != nil {
return err
}
fmt.Fprintf(out, "%s\n", trns)
if s.targets.alias == nil {
continue
}
for _, alias := range p.Aliases {
aliasTrans, err := s.aliasTarget().Translate(alias)
if err != nil {
return err
}
fmt.Fprintf(out, " %s => %s\n", alias, aliasTrans)
}
fmt.Fprintln(out)
}
return
}

View file

@ -1,151 +0,0 @@
// Copyright 2015 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hugolib
import (
"bytes"
"path/filepath"
"strings"
"testing"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/target"
"github.com/spf13/viper"
)
const aliasDoc1 = "---\ntitle: alias doc\naliases:\n - \"alias1/\"\n - \"alias-2/\"\n---\naliases\n"
var fakeSource = []source.ByteSource{
{
Name: filepath.FromSlash("foo/bar/file.md"),
Content: []byte(simplePage),
},
{
Name: filepath.FromSlash("alias/test/file1.md"),
Content: []byte(aliasDoc1),
},
{
Name: filepath.FromSlash("section/somecontent.html"),
Content: []byte(renderNoFrontmatter),
},
}
func checkShowPlanExpected(t *testing.T, s *Site, expected string) {
out := new(bytes.Buffer)
if err := s.ShowPlan(out); err != nil {
t.Fatalf("ShowPlan unexpectedly returned an error: %s", err)
}
got := out.String()
expected = filepath.FromSlash(expected)
// hackety hack: alias is an Url
expected = strings.Replace(expected, (helpers.FilePathSeparator + " =>"), "/ =>", -1)
expected = strings.Replace(expected, "n"+(helpers.FilePathSeparator+"a"), "n/a", -1)
gotList := strings.Split(got, "\n")
expectedList := strings.Split(expected, "\n")
diff := helpers.DiffStringSlices(gotList, expectedList)
if len(diff) > 0 {
t.Errorf("Got diff in show plan: %v", diff)
}
}
// TODO(bep) The tests below fail in a multilanguage setup. They can be fixed, but they
// feel fragile and old. Suggest delete.
func _TestDegenerateNoFiles(t *testing.T) {
checkShowPlanExpected(t, new(Site), "No source files provided.\n")
}
func _TestDegenerateNoTarget(t *testing.T) {
s := &Site{
Source: &source.InMemorySource{ByteSource: fakeSource},
}
must(s.createPages())
expected := "foo/bar/file.md (renderer: markdown)\n canonical => !no target specified!\n\n" +
"alias/test/file1.md (renderer: markdown)\n canonical => !no target specified!\n\n" +
"section/somecontent.html (renderer: n/a)\n canonical => !no target specified!\n\n"
checkShowPlanExpected(t, s, expected)
}
func _TestFileTarget(t *testing.T) {
testCommonResetState()
viper.Set("defaultExtension", "html")
s := &Site{
Source: &source.InMemorySource{ByteSource: fakeSource},
}
s.aliasTarget()
s.pageTarget()
must(s.createPages())
expected := "foo/bar/file.md (renderer: markdown)\n canonical => public/foo/bar/file/index.html\n\n" +
"alias/test/file1.md (renderer: markdown)\n" +
" canonical => public/alias/test/file1/index.html\n" +
" alias1/ => public/alias1/index.html\n" +
" alias-2/ => public/alias-2/index.html\n\n" +
"section/somecontent.html (renderer: n/a)\n canonical => public/section/somecontent/index.html\n\n"
checkShowPlanExpected(t, s, expected)
}
func _TestPageTargetUgly(t *testing.T) {
testCommonResetState()
viper.Set("defaultExtension", "html")
viper.Set("uglyURLs", true)
s := &Site{
targets: targetList{page: &target.PagePub{UglyURLs: true, PublishDir: "public"}},
Source: &source.InMemorySource{ByteSource: fakeSource},
Language: helpers.NewDefaultLanguage(),
}
if err := buildAndRenderSite(s); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
expected := "foo/bar/file.md (renderer: markdown)\n canonical => public/foo/bar/file.html\n\n" +
"alias/test/file1.md (renderer: markdown)\n" +
" canonical => public/alias/test/file1.html\n" +
" alias1/ => public/alias1/index.html\n" +
" alias-2/ => public/alias-2/index.html\n\n" +
"public/section/somecontent.html (renderer: n/a)\n canonical => public/section/somecontent.html\n\n"
checkShowPlanExpected(t, s, expected)
}
func _TestFileTargetPublishDir(t *testing.T) {
testCommonResetState()
viper.Set("defaultExtension", "html")
s := &Site{
targets: targetList{
page: &target.PagePub{PublishDir: "../public"},
alias: &target.HTMLRedirectAlias{PublishDir: "../public"},
},
Source: &source.InMemorySource{ByteSource: fakeSource},
}
must(s.createPages())
expected := "foo/bar/file.md (renderer: markdown)\n canonical => ../foo/bar/file/index.html\n\n" +
"alias/test/file1.md (renderer: markdown)\n" +
" canonical => ../alias/test/file1/index.html\n" +
" alias1/ => ../alias1/index.html\n" +
" alias-2/ => ../alias-2/index.html\n\n" +
"section/somecontent.html (renderer: n/a)\n canonical => ../section/somecontent/index.html\n\n"
checkShowPlanExpected(t, s, expected)
}