2023-07-05 11:14:37 +00:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime/debug"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2023-08-31 15:03:52 +00:00
|
|
|
const oneParameter = `
|
|
|
|
%s
|
|
|
|
assert.%s
|
|
|
|
%v`
|
|
|
|
|
|
|
|
const twoParameters = `
|
|
|
|
%s
|
|
|
|
assert.%s
|
|
|
|
%v
|
|
|
|
%v`
|
|
|
|
|
2023-07-05 11:14:37 +00:00
|
|
|
// file returns the first line containing "_test.go" in the debug stack.
|
2023-07-10 09:36:17 +00:00
|
|
|
func file() string {
|
2023-07-05 11:14:37 +00:00
|
|
|
stack := string(debug.Stack())
|
|
|
|
lines := strings.Split(stack, "\n")
|
2023-08-31 15:03:52 +00:00
|
|
|
name := ""
|
2023-07-05 11:14:37 +00:00
|
|
|
|
|
|
|
for _, line := range lines {
|
|
|
|
if strings.Contains(line, "_test.go") {
|
2023-07-10 09:36:17 +00:00
|
|
|
space := strings.LastIndex(line, " ")
|
|
|
|
|
|
|
|
if space != -1 {
|
|
|
|
line = line[:space]
|
|
|
|
}
|
|
|
|
|
2023-08-31 15:03:52 +00:00
|
|
|
name = strings.TrimSpace(line)
|
|
|
|
break
|
2023-07-05 11:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 15:03:52 +00:00
|
|
|
return name
|
2023-07-05 11:14:37 +00:00
|
|
|
}
|