Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(496)

Unified Diff: src/pkg/log/log_test.go

Issue 157094: code review 157094: Package log now contains a useful interface and functi...
Patch Set: code review 157094: Package log now contains a useful interface and functi... Created 15 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/log/log.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/log/log_test.go
===================================================================
--- a/src/pkg/log/log_test.go
+++ b/src/pkg/log/log_test.go
@@ -11,6 +11,7 @@
"os";
"regexp";
"testing";
+ "fmt";
)
const (
@@ -28,6 +29,8 @@
pattern string; // regexp that log output must match; we add ^ and expected_text$ always
}
+func (t *tester) Log() string { return fmt.Sprintf("flag: %d", t.flag) }
+
var tests = []tester{
// individual pieces:
tester{0, "", ""},
@@ -74,9 +77,36 @@
}
}
+func testLogObj(t *testing.T) {
+ test := &tester{9, "X", "X"};
+ r, w, err1 := os.Pipe();
+ l := New(w, nil, "", Lok|Ldate|Ltime);
+ if err1 != nil {
+ t.Fatal("pipe", err1)
+ }
+ defer r.Close();
+ defer w.Close();
+ buf := bufio.NewReader(r);
+ l.LogObj(test);
+ line, readerr := buf.ReadString('\n');
+ fmt.Printf("here");
+ if readerr != nil {
+ t.Fatal("logable test error", readerr)
+ }
+ matched, compErr := regexp.MatchString(Rdate+" "+Rtime+" "+`flag: [0-9]`, line);
+ if compErr != nil {
+ t.Fatal("pattern did not compile: ", compErr)
+ }
+ if !matched {
+ t.Fatal("logable test")
+ }
+}
+
func TestAllLog(t *testing.T) {
for _, testcase := range tests {
testLog(t, testcase.flag, testcase.prefix, testcase.pattern, false);
testLog(t, testcase.flag, testcase.prefix, testcase.pattern, true);
}
+
+ testLogObj(t);
}
« no previous file with comments | « src/pkg/log/log.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b