shithub: hugo

Download patch

ref: c6ad532b940fa07e5f32a3d1427348f5c4aaf12b
parent: 13d2c552060a2e0339e1ac7c6a523f8837d77e09
author: Noah Campbell <[email protected]>
date: Sun Sep 1 03:43:29 EDT 2013

Add file reporting to planner

--- a/hugolib/planner.go
+++ b/hugolib/planner.go
@@ -2,8 +2,20 @@
 
 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
 }
--- 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())
 }