fs: use bulitin method to get test name

15 views
Skip to first unread message

nor...@perkeep.org

unread,
Jul 2, 2022, 2:48:04 PM7/2/22
to camlistor...@googlegroups.com


https://github.com/perkeep/perkeep/commit/67f9c75ac233740f628a6bfae75694b474375b85

commit 67f9c75ac233740f628a6bfae75694b474375b85
Author: Michael Hoffmann <mho...@posteo.de>
Date: Sat Jul 2 11:44:22 2022 +0200

fs: use bulitin method to get test name

diff --git a/pkg/fs/fs_test.go b/pkg/fs/fs_test.go
index a1d1bc8..85ce794 100644
--- a/pkg/fs/fs_test.go
+++ b/pkg/fs/fs_test.go
@@ -109,25 +109,10 @@ func (e *mountEnv) Stat(s *stat) int64 {
return v
}

-func testName() string {
- skip := 0
- for {
- pc, _, _, ok := runtime.Caller(skip)
- skip++
- if !ok {
- panic("Failed to find test name")
- }
- name := strings.TrimPrefix(runtime.FuncForPC(pc).Name(), "perkeep.org/pkg/fs.")
- if strings.HasPrefix(name, "Test") {
- return name
- }
- }
-}
-
func inEmptyMutDir(t *testing.T, fn func(env *mountEnv, dir string)) {
pkmountTest(t, func(env *mountEnv) {
- dir := filepath.Join(env.mountPoint, "roots", testName())
- if err := os.Mkdir(dir, 0755); err != nil {
+ dir := filepath.Join(env.mountPoint, "roots", t.Name())
+ if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatalf("Failed to make roots/r dir: %v", err)
}
fi, err := os.Stat(dir)
@@ -538,7 +523,7 @@ func TestMoveAt(t *testing.T) {
})
pkmountTest(t, func(env *mountEnv) {
atPrefix := filepath.Join(env.mountPoint, "at")
- testname := strings.Split(testName(), ".")[0]
+ testname := t.Name()

beforeName := filepath.Join(beforeTime.Format(time.RFC3339), testname, oldName)
notYetExistName := filepath.Join(beforeTime.Format(time.RFC3339), testname, newName)
Reply all
Reply to author
Forward
0 new messages