You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
% mkdir tmp
% go mod init testtemp
% cat test_test.go
package main
import (
"fmt"
"os"
"testing"
)
func TestTest(t *testing.T) {
fmt.Println(t.TempDir())
fmt.Println(t.TempDir())
os.Chdir("./tmp")
fmt.Println(t.TempDir())
}
This runs fine:
% go test
/tmp/TestTest731866446/001
/tmp/TestTest731866446/002
/tmp/TestTest731866446/003
But when setting TMPDIR to ./tmp it stops working after the os.Chdir() call:
% TMPDIR=./tmp go test
./tmp/TestTest4094023708/001
./tmp/TestTest4094023708/002
--- FAIL: TestTest (0.00s)
test_test.go:13: TempDir: stat ./tmp: no such file or directory
FAIL
exit status 1
FAIL test 0.002s
It needs to be the full path:
% TMPDIR=/home/martin/testtmp/tmp go test
/home/martin/testtmp/tmp/TestTest2010017600/001
/home/martin/testtmp/tmp/TestTest2010017600/002
/home/martin/testtmp/tmp/TestTest2010017600/003
PASS
ok test 0.002s
Context: I have some filesystem-specific code that's sensitive to the current directory, so I need to change it. I have ./tmp mounted as a XFS image to test that it works on that, in addition to ext4.
I can just use the full path of course, but it's fairly long and annoying, and "it works fine, except in this one specific case" is rather confusing. And should be easy enough to fix with filepath.Abs() call.
The text was updated successfully, but these errors were encountered:
Go version
1.22.4
Output of
go env
in your module/workspace:Setup:
This runs fine:
But when setting TMPDIR to ./tmp it stops working after the os.Chdir() call:
It needs to be the full path:
Context: I have some filesystem-specific code that's sensitive to the current directory, so I need to change it. I have ./tmp mounted as a XFS image to test that it works on that, in addition to ext4.
I can just use the full path of course, but it's fairly long and annoying, and "it works fine, except in this one specific case" is rather confusing. And should be easy enough to fix with filepath.Abs() call.
The text was updated successfully, but these errors were encountered: