Exemplo n.º 1
0
func (*router) reportExistError(typ, pattern string) error {
	return existError{
		pos:     runtime2.Caller(2),
		typ:     typ,
		pattern: pattern,
	}
}
Exemplo n.º 2
0
func TraceDepth(err error, depth int) error {
	if err == nil {
		return nil
	}
	if !TraceEnabled {
		fmt.Println(err)
		return err
	}

	if _, is := err.(traceError); is {
		return err
	}
	return traceError{
		pos: runtime2.Caller(depth + 1),
		err: err,
	}
}
Exemplo n.º 3
0
func indexErrorInfo(t testing.TB, skip int, index string, expect, got interface{}, withType bool) {
	var (
		pos        = runtime2.Caller(skip + 1)
		exps, gots string
	)

	const formatT = "%+v(%T)"
	const format = "%+v"

	if !output.IsTTY {
		if withType {
			exps = fmt.Sprintf(formatT, expect, expect)
			gots = fmt.Sprintf(formatT, got, got)
		} else {
			exps = fmt.Sprintf(format, expect)
			gots = fmt.Sprintf(format, got)
		}
	} else {
		var red = ansi.Begin(ansi.Highlight, ansi.FgRed)
		var green = ansi.Begin(ansi.Highlight, ansi.FgGreen)
		var end = ansi.End()

		pos = ansi.Render(pos, ansi.Highlight, ansi.FgBlue)
		if withType {
			exps = fmt.Sprintf(green+formatT+end, expect, expect)
			gots = fmt.Sprintf(red+formatT+end, got, got)
		} else {
			exps = fmt.Sprintf(green+format+end, expect)
			gots = fmt.Sprintf(red+format+end, got)
		}
	}
	if index != "" {
		if output.IsTTY {
			index = ansi.Render(index, ansi.Highlight, ansi.FgYellow)
		}

		pos += ": " + index
	}

	t.Errorf("%s: expect: %s, got: %s", pos, exps, gots)
}
Exemplo n.º 4
0
func indexErrorInfo(t testing.TB, skip int, index string, expect, got interface{}, withType bool) {
	var (
		pos        = runtime2.Caller(skip + 1)
		exps, gots string
	)

	const formatT = "%+v(%T)"
	const format = "%+v"

	if !color.IsTTY {
		if withType {
			exps = fmt.Sprintf(formatT, expect, expect)
			gots = fmt.Sprintf(formatT, got, got)
		} else {
			exps = fmt.Sprintf(format, expect)
			gots = fmt.Sprintf(format, got)
		}
	} else {
		pos = blue.RenderString(pos)
		if withType {
			exps = green.Sprintf(formatT, expect, expect)
			gots = red.Sprintf(formatT, got, got)
		} else {
			exps = green.Sprintf(format, expect)
			gots = red.Sprintf(format, got)
		}
	}
	if index != "" {
		if color.IsTTY {
			index = yellow.RenderString(index)
		}

		pos += ": " + index
	}

	t.Errorf("%s: expect: %s, got: %s", pos, exps, gots)
}
Exemplo n.º 5
0
func _tmpCheck() {
	if _tmp == nil {
		log.Panicln("Temporary data store has been destroyed: " + runtime2.Caller(2))
	}
}