diff --git a/constructors.go b/constructors.go index 6e78b56..953aee3 100644 --- a/constructors.go +++ b/constructors.go @@ -45,7 +45,7 @@ func NullPath() *Path { // TempDir returns the default path to use for temporary files func TempDir() *Path { - return New(os.TempDir()) + return New(os.TempDir()).Canonical() } // MkTempDir creates a new temporary directory in the directory @@ -57,7 +57,7 @@ func MkTempDir(dir, prefix string) (*Path, error) { if err != nil { return nil, err } - return New(path), nil + return New(path).Canonical(), nil } // MkTempFile creates a new temporary file in the directory dir with a name beginning with prefix, diff --git a/paths_test.go b/paths_test.go index b563aac..09ba8f2 100644 --- a/paths_test.go +++ b/paths_test.go @@ -208,6 +208,10 @@ func TestReadFileAsLines(t *testing.T) { require.Equal(t, "line 3", lines[3]) } +func TestCanonicaTempDir(t *testing.T) { + require.Equal(t, TempDir().String(), TempDir().Canonical().String()) +} + func TestCopyDir(t *testing.T) { tmp, err := MkTempDir("", "") require.NoError(t, err) @@ -341,6 +345,10 @@ func TestCanonicalize(t *testing.T) { r := New("c:\\").Canonical() require.Equal(t, "C:\\", r.String()) + + tmp, err := MkTempDir("", "pref") + require.NoError(t, err) + require.Equal(t, tmp.String(), tmp.Canonical().String()) } }