blob: b495c9c2dbbe38b97db9572736f924f1377883c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/bin/bash
# Check install.sh's ini_merge: fresh file, partial file, idempotence.
# 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)"
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"
|