103 lines
4.2 KiB
Go
103 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// picom's shape (novox/hq ADR 0208): it claims node-compositor and serves no verb of it, requires the
|
|
// X display on its own machine, owns its configuration file, and is started once, by its package's
|
|
// XDG autostart entry, never by the window manager or the session's start as well.
|
|
|
|
func TestItClaimsTheCompositorSeatAndRequiresTheXDisplay(t *testing.T) {
|
|
m := readManifest(t)
|
|
if m.Module != "picom" || m.Seats != nil {
|
|
t.Fatalf("module %q declares seats %v", m.Module, m.Seats)
|
|
}
|
|
if !reflect.DeepEqual(m.Claims, []claim{{Name: "node-compositor", Scope: "node"}}) {
|
|
t.Fatalf("claims: %+v", m.Claims)
|
|
}
|
|
if !reflect.DeepEqual(m.Requires, []string{"x11-display"}) {
|
|
t.Fatalf("requires: %v", m.Requires)
|
|
}
|
|
if present, absent := m.packages(); !reflect.DeepEqual(present, []string{"picom", "xorg-xprop"}) || absent != nil {
|
|
t.Fatalf("packages: %v, absent %v", present, absent)
|
|
}
|
|
}
|
|
|
|
func TestItOwnsItsConfigurationAsWrittenInTheModule(t *testing.T) {
|
|
m := readManifest(t)
|
|
m.fromTemplate(t, "configuration", "files/picom.conf")
|
|
if p := m.resource(t, "configuration")["path"]; p != "${machine:account-home}/.config/picom/picom.conf" {
|
|
t.Fatalf("path: %v", p)
|
|
}
|
|
if d := m.resource(t, "configuration-dir"); d["type"] != "directory" || d["path"] != "${machine:account-home}/.config/picom" {
|
|
t.Fatalf("the directory: %v", d)
|
|
}
|
|
}
|
|
|
|
func TestThePackagesAutostartEntryIsItsOnlyStart(t *testing.T) {
|
|
m := readManifest(t)
|
|
// picom's package ships /etc/xdg/autostart/picom.desktop, which the session's dex runs. A second
|
|
// start from here would be a second compositor, refused by the first.
|
|
if m.Shell != nil {
|
|
t.Fatalf("a session-start line as well as the package's autostart entry: %+v", m.Shell)
|
|
}
|
|
for _, r := range m.Resources {
|
|
if p, _ := r["path"].(string); strings.Contains(p, "i3/config.d") || strings.Contains(p, "autostart") {
|
|
t.Fatalf("a second start: %v", r)
|
|
}
|
|
if r["type"] == "service" || r["type"] == "process" {
|
|
t.Fatalf("a unit: %v", r)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTheToolsAgreeWithTheManifest(t *testing.T) {
|
|
m := readManifest(t)
|
|
checkTheToolsAgree(t, m)
|
|
checkNoSecretsOrInstallationNames(t)
|
|
}
|
|
|
|
// The backend and damage tracking are each machine's (novox/hq research 037: the backend depends on the
|
|
// machine's graphics driver; issue 345: a window left unpainted under glx is the first suspect). Both
|
|
// are config values whose defaults are what every machine ran before, so the file filled with them is today's
|
|
// (novox/hq ADR 0348 §4): the backend a string of picom's backends, damage tracking a boolean, both trusted
|
|
// as the file is.
|
|
func TestTheBackendAndDamageTrackingAreConfigValuesWithTodaysDefaults(t *testing.T) {
|
|
m := readManifest(t)
|
|
b, d := m.Config["backend"], m.Config["use-damage"]
|
|
if b.Type != "string" || b.Default != "glx" || b.Description == "" || !b.Trusted || len(b.Enum) == 0 ||
|
|
d.Type != "boolean" || d.Default != true || d.Description == "" || !d.Trusted {
|
|
t.Fatalf("config: %+v", m.Config)
|
|
}
|
|
r := m.resource(t, "configuration")
|
|
c := m.text(t, "configuration")
|
|
for _, want := range []string{`backend = "${config:backend}";`, "use-damage = ${config:use-damage};"} {
|
|
if !strings.Contains(c, want) {
|
|
t.Errorf("the file asks for %q", want)
|
|
}
|
|
}
|
|
// Trusted (unmarked): a value is pasted into the file as it is, so `xrender"; write-pid-path = "…`
|
|
// would add an option of the caller's. Until settings are typed and quoted (hq issue 346), only the
|
|
// controller's terminal sets them.
|
|
if _, marked := r["trusted"]; marked {
|
|
t.Fatal("the file stays trusted: its settings are set at the terminal alone (hq issue 346)")
|
|
}
|
|
got := parseRules("picom.conf", withDefaults(c), nil)
|
|
if got.Global["backend"] != "glx" || got.Global["use-damage"] != "true" || got.Global["vsync"] != "true" {
|
|
t.Fatalf("filled with the defaults: %v", got.Global)
|
|
}
|
|
}
|
|
|
|
// withDefaults fills the file's config values with their defaults, as a machine without its own values gets it.
|
|
func withDefaults(c string) string {
|
|
return strings.NewReplacer("${config:backend}", "glx", "${config:use-damage}", "true").Replace(c)
|
|
}
|
|
|
|
// No file resource carries its text inline (novox/hq ADR 0349 §2).
|
|
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
|
|
readManifest(t).everyFileIsATemplate(t)
|
|
}
|