mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Add file reporting to planner
This commit is contained in:
parent
13d2c55206
commit
c6ad532b94
2 changed files with 34 additions and 1 deletions
|
@ -2,8 +2,20 @@ package hugolib
|
|||
|
||||
import (
|
||||
"io"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *Site) ShowPlan(out io.Writer) (err error) {
|
||||
if len(s.Files) <= 0 {
|
||||
fmt.Fprintf(out, "No source files provided.\n")
|
||||
}
|
||||
|
||||
for _, file := range s.Files {
|
||||
fmt.Fprintf(out, "%s\n", file)
|
||||
if s.Target == nil {
|
||||
fmt.Fprintf(out, " *implicit* => %s\n", "!no target specified!")
|
||||
continue
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,14 +1,35 @@
|
|||
package hugolib
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
func checkShowPlanExpected(t *testing.T, expected, got string) {
|
||||
if got != expected {
|
||||
t.Errorf("ShowPlan expected:\n%q\ngot\n%q", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDegenerateNoFiles(t *testing.T) {
|
||||
s := new(Site)
|
||||
out := new(bytes.Buffer)
|
||||
if err := s.ShowPlan(out); err != nil {
|
||||
t.Errorf("ShowPlan unexpectedly returned an error: %s", err)
|
||||
}
|
||||
expected := "No source files provided.\n"
|
||||
got := out.String()
|
||||
checkShowPlanExpected(t, expected, got)
|
||||
}
|
||||
|
||||
func TestDegenerateNoTarget(t *testing.T) {
|
||||
s := new(Site)
|
||||
s.Files = append(s.Files, "foo/bar/file.md")
|
||||
out := new(bytes.Buffer)
|
||||
if err := s.ShowPlan(out); err != nil {
|
||||
t.Errorf("ShowPlan unexpectedly returned an error: %s", err)
|
||||
}
|
||||
|
||||
expected := "foo/bar/file.md\n *implicit* => !no target specified!\n"
|
||||
checkShowPlanExpected(t, expected, out.String())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue