//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) }) }) }