Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go123
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go123
Commits
6cabc980
Commit
6cabc980
authored
Apr 19, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
my: Add File, Line and Frame
To determine current function's file name, line number and runtime.Frame
parent
cf55754e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
my/my.go
my/my.go
+17
-0
my/my_test.go
my/my_test.go
+20
-0
No files found.
my/my.go
View file @
6cabc980
...
...
@@ -60,3 +60,20 @@ func PkgName() string {
}
return
myfunc
[
:
iafterslash
+
idot
]
}
// File returns path of currently running function's file
func
File
()
string
{
f
:=
_myframe
(
3
)
return
f
.
File
}
// Line returns currently running function's line
func
Line
()
int
{
f
:=
_myframe
(
3
)
return
f
.
Line
}
// Frame returns currently running functions's frame
func
Frame
()
runtime
.
Frame
{
return
_myframe
(
3
)
}
my/my_test.go
View file @
6cabc980
...
...
@@ -22,6 +22,16 @@ import (
"testing"
)
// goes first not to be broken by other edits
func
TestMyLine
(
t
*
testing
.
T
)
{
myline
:=
Line
()
want
:=
27
if
myline
!=
want
{
t
.
Errorf
(
"my.Line() -> %v ; want %v"
,
myline
,
want
)
}
}
func
TestMyFuncName
(
t
*
testing
.
T
)
{
myfunc
:=
FuncName
()
// go test changes full package name (putting filesystem of the tree into it)
...
...
@@ -31,3 +41,13 @@ func TestMyFuncName(t *testing.T) {
t
.
Errorf
(
"my.FuncName() -> %v ; want *%v"
,
myfunc
,
wantsuffix
)
}
}
// XXX how to test PkgName? (go test changes full package name - see ^^^)
func
TestMyFile
(
t
*
testing
.
T
)
{
myfile
:=
File
()
wantsuffix
:=
"my_test.go"
if
!
strings
.
HasSuffix
(
myfile
,
wantsuffix
)
{
t
.
Errorf
(
"my.File() -> %v ; want *%v"
,
myfile
,
wantsuffix
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment