File: package_test.go

package info (click to toggle)
golang-github-juju-errors 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 196 kB
  • sloc: makefile: 21
file content (31 lines) | stat: -rw-r--r-- 827 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2013, 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.

package errors_test

import (
	"fmt"
	"runtime"
	"testing"

	gc "gopkg.in/check.v1"
)

func Test(t *testing.T) {
	gc.TestingT(t)
}

// errorLocationValue provides the function name and line number for where this
// function was called from - 1 line. What this means is that the returned value
// will be homed to the file line directly above where this function was called.
// This is a utility for testing error details and that associated error calls
// set the error location correctly.
func errorLocationValue(c *gc.C) string {
	rpc := make([]uintptr, 1)
	n := runtime.Callers(2, rpc[:])
	if n < 1 {
		return ""
	}
	frame, _ := runtime.CallersFrames(rpc).Next()
	return fmt.Sprintf("%s:%d", frame.Function, frame.Line-1)
}