Files
omarchy/test/shell.d/region-test.sh
T
ZacharyZhang-NY 199a7f23fc Split language from region: omarchy-language and Setup > Language own LANG
omarchy-region and install/config/region.sh no longer touch the locale;
both logout prompts are worded through omarchy-text.
2026-10-08 23:44:04 -04:00

98 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
region_bin="$test_tmp/omarchy-region"
region_file="$test_tmp/region"
sed "s|/etc/omarchy/region|$region_file|" "$ROOT/bin/omarchy-region" >"$region_bin"
chmod +x "$region_bin"
[[ $("$region_bin") == "Global" ]] || fail "no region file reads as Global"
pass "no region file reads as Global"
echo cn >"$region_file"
[[ $("$region_bin") == "China" ]] || fail "cn region file reads as China"
pass "cn region file reads as China"
echo mars >"$region_file"
if output=$("$region_bin" 2>&1); then
fail "an unknown region fails" "$output"
fi
[[ $output == "Unknown region in $region_file: mars" ]] || fail "an unknown region names the file and value" "$output"
pass "an unknown region fails and names the file and value"
stub_bin="$test_tmp/bin"
calls="$test_tmp/calls"
mkdir -p "$stub_bin"
printf '#!/bin/bash\necho "locale-gen $*" >>"%s"\n' "$calls" >"$stub_bin/locale-gen"
chmod +x "$stub_bin"/*
PATH="$stub_bin:$PATH"
region_setup="$test_tmp/region.sh"
root="$test_tmp/root"
sed -e "s|/etc/|$root/etc/|g" -e "s| /\.cargo/| $root/.cargo/|g" "$ROOT/install/config/region.sh" >"$region_setup"
export OMARCHY_PATH="$ROOT"
mkdir -p "$root/etc"
printf '#zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\n' >"$root/etc/locale.gen"
printf 'LANG=en_US.UTF-8\nLC_TIME=en_DK.UTF-8\n' >"$root/etc/locale.conf"
: >"$calls"
OMARCHY_REGION=cn bash -e "$region_setup"
[[ $(<"$root/etc/omarchy/region") == "cn" ]] || fail "install records the China region as cn"
[[ ! -s $calls && $(<"$root/etc/locale.gen") == $'#zh_CN.UTF-8 UTF-8\nen_US.UTF-8 UTF-8' && $(<"$root/etc/locale.conf") == $'LANG=en_US.UTF-8\nLC_TIME=en_DK.UTF-8' ]] ||
fail "China leaves the language alone" "$(<"$root/etc/locale.conf")"
pass "install records the China region and leaves the language alone"
for link in "environment.conf etc/environment.d/90-omarchy-china.conf" "cargo.toml .cargo/config.toml" "gemrc etc/gemrc"; do
read -r source target <<<"$link"
[[ $(readlink "$root/$target") == "$ROOT/default/regions/cn/$source" ]] || fail "China links /$target to the shipped $source"
done
pass "China links the developer mirror drop-ins"
: >"$calls"
OMARCHY_REGION=global bash -e "$region_setup"
[[ ! -e $root/etc/omarchy/region ]] || fail "install records Global by leaving no region file"
printf 'LANG=zh_CN.UTF-8\n' >"$root/etc/locale.conf"
OMARCHY_REGION=global bash -e "$region_setup"
[[ ! -s $calls && $(<"$root/etc/locale.conf") == "LANG=zh_CN.UTF-8" ]] || fail "Global keeps a Chinese language"
pass "Global leaves the language alone"
[[ ! -e $root/etc/environment.d/90-omarchy-china.conf && ! -e $root/.cargo/config.toml && ! -e $root/etc/gemrc ]] ||
fail "Global removes the developer mirror drop-ins"
pass "Global removes the developer mirror drop-ins"
ln -s /usr/share/somewhere/gemrc "$root/etc/gemrc"
OMARCHY_REGION=global bash -e "$region_setup"
[[ -L $root/etc/gemrc ]] || fail "Global keeps a gemrc link Omarchy did not create"
rm "$root/etc/gemrc"
echo ":sources: []" >"$root/etc/gemrc"
if output=$(OMARCHY_REGION=cn bash -e "$region_setup" 2>&1); then
fail "China refuses to replace an admin's /etc/gemrc" "$output"
fi
[[ $output == "Refusing to replace $root/etc/gemrc, which Omarchy did not create" && $(<"$root/etc/gemrc") == ":sources: []" ]] ||
fail "China names the file it refuses to replace and leaves it" "$output"
[[ ! -e $root/etc/omarchy/region ]] || fail "a refused China switch records no region"
rm "$root/etc/gemrc"
pass "region setup never touches mirror config Omarchy did not create"
echo cn >"$root/etc/omarchy/region"
: >"$calls"
env -u OMARCHY_REGION bash -e "$region_setup"
[[ $(<"$root/etc/omarchy/region") == "cn" && $(readlink "$root/etc/gemrc") == "$ROOT/default/regions/cn/gemrc" ]] ||
fail "install keeps the cn marker the installer wrote and links its drop-ins"
pass "install follows the region marker the installer wrote"
OMARCHY_REGION=global bash -e "$region_setup"
env -u OMARCHY_REGION bash -e "$region_setup"
[[ ! -e $root/etc/omarchy/region && ! -e $root/etc/gemrc ]] || fail "no marker installs Global"
pass "no marker installs Global"
if output=$(OMARCHY_REGION=mars bash -e "$region_setup" 2>&1); then
fail "install rejects an unknown region" "$output"
fi
[[ $output == "Unknown region: mars" ]] || fail "install names the unknown region" "$output"
pass "install rejects an unknown region"