dslFuncLocation returns the file and line where the given DSL function is declared. The returned file is relative to the current working directory when possible.
(fn func())
| 148 | // |
| 149 | // The returned file is relative to the current working directory when possible. |
| 150 | func dslFuncLocation(fn func()) (file string, line int, ok bool) { |
| 151 | pc := reflect.ValueOf(fn).Pointer() |
| 152 | f := runtime.FuncForPC(pc) |
| 153 | if f == nil { |
| 154 | return "", 0, false |
| 155 | } |
| 156 | file, line = f.FileLine(pc) |
| 157 | if file == "" || line == 0 { |
| 158 | return "", 0, false |
| 159 | } |
| 160 | return relativeToWorkdir(file), line, true |
| 161 | } |
| 162 | |
| 163 | // relativeToWorkdir returns file relative to the current working directory when |
| 164 | // possible, otherwise it returns file unchanged. |
no test coverage detected