"cmd/internal/src"
"crypto/sha1"
"fmt"
+ "io"
"math"
"os"
"strings"
)
+type writeSyncer interface {
+ io.Writer
+ Sync() error
+}
+
// A Func represents a Go func declaration (or function literal) and its body.
// This package compiles each Func independently.
// Funcs are single-use; a new Func must be created for every compiled function.
// Given an environment variable used for debug hash match,
// what file (if any) receives the yes/no logging?
- logfiles map[string]*os.File
+ logfiles map[string]writeSyncer
HTMLWriter *HTMLWriter // html writer, for debugging
DebugTest bool // default true unless $GOSSAHASH != ""; as a debugging aid, make new code conditional on this and use GOSSAHASH to binary search for failing cases
func (f *Func) logDebugHashMatch(evname, name string) {
if f.logfiles == nil {
- f.logfiles = make(map[string]*os.File)
+ f.logfiles = make(map[string]writeSyncer)
}
file := f.logfiles[evname]
if file == nil {
}
f.logfiles[evname] = file
}
- s := fmt.Sprintf("%s triggered %s\n", evname, name)
- file.WriteString(s)
+ fmt.Fprintf(file, "%s triggered %s\n", evname, name)
file.Sync()
}
type HTMLWriter struct {
Logger
- *os.File
+ w io.WriteCloser
}
func NewHTMLWriter(path string, logger Logger, funcname string) *HTMLWriter {
if err != nil {
logger.Fatalf(src.NoXPos, "%v", err)
}
- html := HTMLWriter{File: out, Logger: logger}
+ html := HTMLWriter{w: out, Logger: logger}
html.start(funcname)
return &html
}
if w == nil {
return
}
- w.WriteString("</tr>")
- w.WriteString("</table>")
- w.WriteString("</body>")
- w.WriteString("</html>")
- w.File.Close()
+ io.WriteString(w.w, "</tr>")
+ io.WriteString(w.w, "</table>")
+ io.WriteString(w.w, "</body>")
+ io.WriteString(w.w, "</html>")
+ w.w.Close()
}
// WriteFunc writes f in a column headed by title.
}
func (w *HTMLWriter) Printf(msg string, v ...interface{}) {
- if _, err := fmt.Fprintf(w.File, msg, v...); err != nil {
+ if _, err := fmt.Fprintf(w.w, msg, v...); err != nil {
w.Fatalf(src.NoXPos, "%v", err)
}
}
func (w *HTMLWriter) WriteString(s string) {
- if _, err := w.File.WriteString(s); err != nil {
+ if _, err := io.WriteString(w.w, s); err != nil {
w.Fatalf(src.NoXPos, "%v", err)
}
}