@@ -384,8 +384,8 @@ func TestGetRootDir_XDGOnLinux(t *testing.T) {
384384 }
385385}
386386
387- func TestGetRootDir_NonLinux (t * testing.T ) {
388- // On non-Linux platforms, verify that ~/.dtvem is used regardless of XDG
387+ func TestGetRootDir_NonLinux_WithXDG (t * testing.T ) {
388+ // On non-Linux platforms, verify that XDG_DATA_HOME is respected when set
389389 if runtime .GOOS == constants .OSLinux {
390390 t .Skip ("This test only runs on non-Linux platforms" )
391391 }
@@ -409,15 +409,53 @@ func TestGetRootDir_NonLinux(t *testing.T) {
409409
410410 // Clear DTVEM_ROOT and set XDG_DATA_HOME
411411 _ = os .Unsetenv ("DTVEM_ROOT" )
412- _ = os .Setenv ("XDG_DATA_HOME" , "/should/be/ignored" )
412+ customXDG := "/custom/xdg/data"
413+ _ = os .Setenv ("XDG_DATA_HOME" , customXDG )
414+ resetPathsForTesting ()
415+
416+ result := getRootDir ()
417+ expected := filepath .Join (customXDG , "dtvem" )
418+
419+ if result != expected {
420+ t .Errorf ("getRootDir() on %s should use XDG_DATA_HOME when set, got %q, want %q" ,
421+ runtime .GOOS , result , expected )
422+ }
423+ }
424+
425+ func TestGetRootDir_NonLinux_WithoutXDG (t * testing.T ) {
426+ // On non-Linux platforms, verify that ~/.dtvem is used when XDG_DATA_HOME is not set
427+ if runtime .GOOS == constants .OSLinux {
428+ t .Skip ("This test only runs on non-Linux platforms" )
429+ }
430+
431+ // Save original environment
432+ originalRoot := os .Getenv ("DTVEM_ROOT" )
433+ originalXDG := os .Getenv ("XDG_DATA_HOME" )
434+ defer func () {
435+ if originalRoot != "" {
436+ _ = os .Setenv ("DTVEM_ROOT" , originalRoot )
437+ } else {
438+ _ = os .Unsetenv ("DTVEM_ROOT" )
439+ }
440+ if originalXDG != "" {
441+ _ = os .Setenv ("XDG_DATA_HOME" , originalXDG )
442+ } else {
443+ _ = os .Unsetenv ("XDG_DATA_HOME" )
444+ }
445+ resetPathsForTesting ()
446+ }()
447+
448+ // Clear both DTVEM_ROOT and XDG_DATA_HOME
449+ _ = os .Unsetenv ("DTVEM_ROOT" )
450+ _ = os .Unsetenv ("XDG_DATA_HOME" )
413451 resetPathsForTesting ()
414452
415453 result := getRootDir ()
416454 home , _ := os .UserHomeDir ()
417455 expected := filepath .Join (home , ".dtvem" )
418456
419457 if result != expected {
420- t .Errorf ("getRootDir() on %s should ignore XDG_DATA_HOME , got %q, want %q" ,
458+ t .Errorf ("getRootDir() on %s without XDG_DATA_HOME should use ~/.dtvem , got %q, want %q" ,
421459 runtime .GOOS , result , expected )
422460 }
423461}
0 commit comments