func UseFrontLoadedReporter(reporter reporters.Reporter) io.Closer {
	closer := &frontLoadedReporterCloser{
		reporter: defaultFrontLoadedReporter,
	}
	defaultFrontLoadedReporter = reporter
	return closer
}
UseFrontLoadedReporter configures reporters ahead of all other reporters to
handle situations like CI. These reporters usually prevent reporting in
scenarios that are headless.
package approvals
import (
	"bytes"
	"encoding/json"
	"encoding/xml"
	"fmt"
	"io"
	"os"
	"reflect"
	"strings"
	"github.com/approvals/go-approval-tests/reporters"
	"github.com/approvals/go-approval-tests/utils"
)
var (
	defaultReporter            = reporters.NewDiffReporter()
	defaultFrontLoadedReporter = reporters.NewFrontLoadedReporter()
	defaultFolder              = ""
)
type Failable interface {
	Fail()
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Name() string
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	Helper()
}
func VerifyWithExtension(t Failable, reader io.Reader, extWithDot string) {
	t.Helper()
	namer := getApprovalName(t)
	reporter := getReporter()
	var err = namer.compare(namer.getApprovalFile(extWithDot), namer.getReceivedFile(extWithDot), reader)
	if err != nil {
		reporter.Report(namer.getApprovalFile(extWithDot), namer.getReceivedFile(extWithDot))
		t.Log("Failed Approval: received does not match approved.")
		t.Fail()
	} else {
		_ = os.Remove(namer.getReceivedFile(extWithDot))
	}
}
func Verify(t Failable, reader io.Reader) {
	t.Helper()
	VerifyWithExtension(t, reader, ".txt")
}
func VerifyString(t Failable, s string) {
	t.Helper()
	reader := strings.NewReader(s)
	Verify(t, reader)
}
func VerifyXMLStruct(t Failable, obj interface{}) {
	t.Helper()
	xmlContent, err := xml.MarshalIndent(obj, "", "  ")
	if err != nil {
		tip := ""
		if reflect.TypeOf(obj).Name() == "" {
			tip = "when using anonymous types be sure to include\n  XMLName xml.Name `xml:\"Your_Name_Here\"`\n"
		}
		message := fmt.Sprintf("error while pretty printing XML\n%verror:\n  %v\nXML:\n  %v\n", tip, err, obj)
		VerifyWithExtension(t, strings.NewReader(message), ".xml")
	} else {
		VerifyWithExtension(t, bytes.NewReader(xmlContent), ".xml")
	}
}
func VerifyXMLBytes(t Failable, bs []byte) {
	t.Helper()
	type node struct {
		Attr     []xml.Attr
		XMLName  xml.Name
		Children []node `xml:",any"`
		Text     string `xml:",chardata"`
	}
	x := node{}
	err := xml.Unmarshal(bs, &x)
	if err != nil {
		message := fmt.Sprintf("error while parsing XML\nerror:\n  %s\nXML:\n  %s\n", err, string(bs))
		VerifyWithExtension(t, strings.NewReader(message), ".xml")
	} else {
		VerifyXMLStruct(t, x)
	}
}
func VerifyJSONStruct(t Failable, obj interface{}) {
	t.Helper()
	jsonb, err := json.MarshalIndent(obj, "", "  ")
	if err != nil {
		message := fmt.Sprintf("error while pretty printing JSON\nerror:\n  %s\nJSON:\n  %s\n", err, obj)
		VerifyWithExtension(t, strings.NewReader(message), ".json")
	} else {
		VerifyWithExtension(t, bytes.NewReader(jsonb), ".json")
	}
}
func VerifyJSONBytes(t Failable, bs []byte) {
	t.Helper()
	var obj map[string]interface{}
	err := json.Unmarshal(bs, &obj)
	if err != nil {
		message := fmt.Sprintf("error while parsing JSON\nerror:\n  %s\nJSON:\n  %s\n", err, string(bs))
		VerifyWithExtension(t, strings.NewReader(message), ".json")
	} else {
		VerifyJSONStruct(t, obj)
	}
}
func VerifyMap(t Failable, m interface{}) {
	t.Helper()
	outputText := utils.PrintMap(m)
	VerifyString(t, outputText)
}
func VerifyArray(t Failable, array interface{}) {
	t.Helper()
	outputText := utils.PrintArray(array)
	VerifyString(t, outputText)
}
func VerifyAll(t Failable, header string, collection interface{}, transform func(interface{}) string) {
	t.Helper()
	if len(header) != 0 {
		header = fmt.Sprintf("%s\n\n\n", header)
	}
	outputText := header + strings.Join(utils.MapToString(collection, transform), "\n")
	VerifyString(t, outputText)
}
type reporterCloser struct {
	reporter reporters.Reporter
}
func (s *reporterCloser) Close() error {
	defaultReporter = s.reporter
	return nil
}
type frontLoadedReporterCloser struct {
	reporter reporters.Reporter
}
func (s *frontLoadedReporterCloser) Close() error {
	defaultFrontLoadedReporter = s.reporter
	return nil
}
func UseReporter(reporter reporters.Reporter) io.Closer {
	closer := &reporterCloser{
		reporter: defaultReporter,
	}
	defaultReporter = reporter
	return closer
}