Add file reporting to planner

This commit is contained in:
Noah Campbell 2013-09-01 07:43:29 -07:00
parent 13d2c55206
commit c6ad532b94
2 changed files with 34 additions and 1 deletions

View file

@ -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
}

View file

@ -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())
}