. "$BST_LIB"
# Exercise the diffutils binaries specifically. busybox ships a `diff` applet
# and the busybox ash runs it in preference to $PATH, so a bare `diff` is
# busybox's (unified-format) diff, not this package's — invoke diffutils' own
# binary by its update-alternatives name `diff.diffutils` to prove the port.
# cmp/diff3/sdiff have no busybox applet, so `cmp` already is diffutils' cmp.
require diff.diffutils diffutils/present

tmp=${TMPDIR:-/tmp}/bst-diffutils.$$
printf 'alpha\nbeta\ngamma\n'  > "$tmp.a" 2>/dev/null
printf 'alpha\nBETA\ngamma\n'  > "$tmp.b" 2>/dev/null

# diff on two differing files reports the change. GNU diff's default (normal)
# format prints the changed line as "> BETA". diff exits 1 when files differ,
# so normalise the exit with `; true`.
check_out diffutils/diff-report   "> BETA"  sh -c "diff.diffutils '$tmp.a' '$tmp.b'; true"
# diff signals "files differ" with exit status 1 (0 = same, 2 = trouble).
check_rc  diffutils/diff-rc        1         diff.diffutils "$tmp.a" "$tmp.b"
# identical inputs: exit 0 and no output.
check     diffutils/diff-identical           diff.diffutils "$tmp.a" "$tmp.a"
check_eq  diffutils/diff-quiet     ""        "$(diff.diffutils "$tmp.a" "$tmp.a" 2>&1)"
# unified format carries the -/+ hunk lines.
check_out diffutils/diff-unified   "+BETA"   sh -c "diff.diffutils -u '$tmp.a' '$tmp.b'; true"

# cmp on equal files is silent and exits 0.
check     diffutils/cmp-equal                cmp "$tmp.a" "$tmp.a"
check_eq  diffutils/cmp-silent     ""        "$(cmp "$tmp.a" "$tmp.a" 2>&1)"
# cmp on differing files reports the first differing byte/line and exits 1.
check_out diffutils/cmp-report     "differ"  sh -c "cmp '$tmp.a' '$tmp.b'; true"
check_rc  diffutils/cmp-rc         1         cmp "$tmp.a" "$tmp.b"

rm -f "$tmp.a" "$tmp.b"
