github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/report_entry.go (about)

     1  package internal
     2  
     3  import (
     4  	"reflect"
     5  	"time"
     6  
     7  	"github.com/onsi/ginkgo/types"
     8  )
     9  
    10  type ReportEntry = types.ReportEntry
    11  
    12  func NewReportEntry(name string, cl types.CodeLocation, args ...interface{}) (ReportEntry, error) {
    13  	out := ReportEntry{
    14  		Visibility: types.ReportEntryVisibilityAlways,
    15  		Name:       name,
    16  		Time:       time.Now(),
    17  		Location:   cl,
    18  	}
    19  	var didSetValue = false
    20  	for _, arg := range args {
    21  		switch reflect.TypeOf(arg) {
    22  		case reflect.TypeOf(types.ReportEntryVisibilityAlways):
    23  			out.Visibility = arg.(types.ReportEntryVisibility)
    24  		case reflect.TypeOf(types.CodeLocation{}):
    25  			out.Location = arg.(types.CodeLocation)
    26  		case reflect.TypeOf(Offset(0)):
    27  			out.Location = types.NewCodeLocation(2 + int(arg.(Offset)))
    28  		case reflect.TypeOf(out.Time):
    29  			out.Time = arg.(time.Time)
    30  		default:
    31  			if didSetValue {
    32  				return ReportEntry{}, types.GinkgoErrors.TooManyReportEntryValues(out.Location, arg)
    33  			}
    34  			out.Value = types.WrapEntryValue(arg)
    35  			didSetValue = true
    36  		}
    37  	}
    38  
    39  	return out, nil
    40  }