caption/caption_sample_test.go
Yonah 8e6affff41
caption: overridable default
This increases performance in the typical use case.
2025-07-13 01:38:09 +09:00

35 lines
856 B
Go

//go:build export_samples
package caption_test
import (
"image"
"image/png"
"os"
"path"
"strings"
"testing"
)
func init() {
beforeCheck = append(beforeCheck, func(t *testing.T, name string, redraw bool, got image.Image) {
suffix := ""
if redraw {
suffix = " redraw"
}
t.Run("export"+suffix, func(t *testing.T) {
outPath := strings.TrimSpace(os.Getenv("TEST_RENDER_OUT_PATH"))
if len(outPath) == 0 {
outPath = os.TempDir()
}
outPath = path.Join(outPath, "overlay-"+strings.Join(strings.Fields(name+suffix), "-")+".png")
if re, err := os.Create(outPath); err != nil {
t.Fatalf("cannot create: %v", err)
} else if err = (&png.Encoder{CompressionLevel: png.NoCompression}).Encode(re, got); err != nil {
t.Fatalf("cannot encode to file: %v", err)
}
t.Logf("test case exported to %s", outPath)
})
})
}