// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package session import ( "strings" "testing" ) func TestDesktopEnvironment(t *testing.T) { for _, test := range []struct { name, kind, display, backend, wantBackend string wayland bool }{ {"Xorg", "x11", "", "wayland", "x11", false}, {"Xorg with inherited Wayland display", "x11", "wayland-0", "", "x11", false}, {"Wayland", "wayland", "wayland-0", "", "", true}, {"Wayland user backend", "wayland", "wayland-0", "x11", "x11", true}, {"normalized session", " Wayland ", "", "wayland,x11", "wayland,x11", true}, {"Wayland display fallback", "", "wayland-0", "", "", true}, {"unspecified session", "", "", "wayland,x11", "wayland,x11", false}, {"explicit other session", "tty", "wayland-0", "", "", false}, } { t.Run(test.name, func(t *testing.T) { t.Setenv("XDG_SESSION_TYPE", test.kind) t.Setenv("WAYLAND_DISPLAY", test.display) t.Setenv("GDK_BACKEND", test.backend) t.Setenv("CTHULHU_TEST_INHERITED", "preserved") if got := Wayland(); got != test.wayland { t.Fatalf("Wayland = %v, want %v", got, test.wayland) } values := make(map[string]string) for _, entry := range GTKEnvironment() { key, value, _ := strings.Cut(entry, "=") values[key] = value } if values["GDK_BACKEND"] != test.wantBackend || values["CTHULHU_TEST_INHERITED"] != "preserved" { t.Fatalf("GTK backend = %q, inherited value = %q", values["GDK_BACKEND"], values["CTHULHU_TEST_INHERITED"]) } }) } }