aboutsummaryrefslogtreecommitdiffstats
path: root/tests/machine-name.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/machine-name.sh')
-rwxr-xr-xtests/machine-name.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/machine-name.sh b/tests/machine-name.sh
new file mode 100755
index 0000000..f8d9f6d
--- /dev/null
+++ b/tests/machine-name.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# Check bin/udt-machine-name: quoting round-trips through shlex, other keys
+# survive, a second set replaces rather than appends.
+# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+# Licensed under the GNU General Public License v2 only.
+set -euo pipefail
+
+repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+tmp="$(mktemp -d)"
+trap 'rm -rf "$tmp"' EXIT
+export UDT_MACHINE_INFO="$tmp/machine-info"
+
+printf 'ICON_NAME=computer\nPRETTY_HOSTNAME="old"\n' > "$UDT_MACHINE_INFO"
+"$repo/bin/udt-machine-name" 'first' >/dev/null
+"$repo/bin/udt-machine-name" 'Anne'"'"'s "Box" \ $HOME' >/dev/null
+
+[ "$(grep -c '^PRETTY_HOSTNAME=' "$UDT_MACHINE_INFO")" = 1 ]
+grep -qx 'ICON_NAME=computer' "$UDT_MACHINE_INFO"
+python3 - "$UDT_MACHINE_INFO" <<'PY'
+import shlex, sys
+line = next(l for l in open(sys.argv[1]) if l.startswith("PRETTY_HOSTNAME="))
+got = " ".join(shlex.split(line[len("PRETTY_HOSTNAME="):]))
+assert got == 'Anne\'s "Box" \\ $HOME', got
+PY
+! "$repo/bin/udt-machine-name" $'a\nb' 2>/dev/null
+! "$repo/bin/udt-machine-name" '' 2>/dev/null
+
+echo "machine-name OK"