#!/bin/bash # Check install.sh's ini_merge: fresh file, partial file, idempotence. # Copyright (C) 2026 Danilo M. # Licensed under the GNU General Public License v2 only. set -euo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" eval "$(sed -n '/^ini_merge() {/,/^}/p' "$repo/install.sh")" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT printf '[A]\nx=1\ny=2\n[B]\nz=3\n' > "$tmp/tmpl" ini_merge "$tmp/tmpl" "$tmp/fresh" diff <(printf '[A]\nx=1\ny=2\n[B]\nz=3\n') "$tmp/fresh" # Existing key replaced, foreign key kept, missing key lands before the blank # line that separates sections, missing section appended. printf '[A]\nx=0\nkeep=me\n\n[C]\nw=4\n' > "$tmp/part" ini_merge "$tmp/tmpl" "$tmp/part" diff <(printf '[A]\nx=1\nkeep=me\ny=2\n\n[C]\nw=4\n[B]\nz=3\n') "$tmp/part" cp "$tmp/part" "$tmp/again" ini_merge "$tmp/tmpl" "$tmp/again" diff "$tmp/part" "$tmp/again" echo "ini-merge OK"