From c6ad532b940fa07e5f32a3d1427348f5c4aaf12b Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Sun, 1 Sep 2013 07:43:29 -0700 Subject: [PATCH] Add file reporting to planner --- hugolib/planner.go | 12 ++++++++++++ hugolib/site_show_plan_test.go | 23 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/hugolib/planner.go b/hugolib/planner.go index 5b1d42327..826572493 100644 --- a/hugolib/planner.go +++ b/hugolib/planner.go @@ -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 } diff --git a/hugolib/site_show_plan_test.go b/hugolib/site_show_plan_test.go index de9d7363e..272297940 100644 --- a/hugolib/site_show_plan_test.go +++ b/hugolib/site_show_plan_test.go @@ -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()) }