Files
vx/tests/test_diff3.sh

82 lines
3.1 KiB
Bash
Executable File

#!/bin/sh
# tests/test_diff3.sh - Tests for diff3 applet
_test_name="diff3"
. "$(dirname "$0")/harness.sh"
_srcdir="$(cd "$(dirname "$0")/../src/diff3/tests" && pwd)"
setup_tmpdir
DIFF3="$VX diff3"
echo "Running diff3 tests..."
# --- basic 3-way diff ---
_got="$($DIFF3 "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/1.out")"
check_eq "$_got" "$_exp" "basic: default output"
# --- strip trailing CR ---
_got="$($DIFF3 --strip-trailing-cr "$_srcdir/1cr.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/1.out")"
check_eq "$_got" "$_exp" "stripcr: matches default output"
# --- -T flag ---
_got="$($DIFF3 -T "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/1t.out")"
check_eq "$_got" "$_exp" "Tflag: initial tab output"
# --- -e (ed script) ---
_got="$($DIFF3 -e "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/2.out")"
check_eq "$_got" "$_exp" "ed: -e output"
# --- -E (overlap ed script with labels) ---
_got="$($DIFF3 -E -L 1 -L 2 -L 3 "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/3.out")"
check_eq "$_got" "$_exp" "overlap: -E output"
# --- -X (only overlapping changes) ---
_got="$($DIFF3 -X -L 1 -L 2 -L 3 "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/4.out")"
check_eq "$_got" "$_exp" "Xflag: -X output"
# --- -x (only overlapping, no labels) ---
_got="$($DIFF3 -x "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/5.out")"
check_eq "$_got" "$_exp" "xflag: -x output"
# --- -3 (ed script for file 3 changes only) ---
_got="$($DIFF3 -3 "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/6.out")"
check_eq "$_got" "$_exp" "3flag: -3 output"
# --- -i (append w/q commands) ---
_got="$($DIFF3 -i "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/7.out")"
check_eq "$_got" "$_exp" "iflag: -i output"
# --- -A (show all changes) ---
$DIFF3 -A -L 1 -L 2 -L 3 "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" > Aout 2>/dev/null
_rc=$?
check_eq "$_rc" "1" "Aflag: exits 1 on conflicts"
check_file Aout "$_srcdir/8.out" "Aflag: output matches"
# --- long ed script ---
_got="$($DIFF3 -e "$_srcdir/long-m.txt" "$_srcdir/long-o.txt" "$_srcdir/long-y.txt" 2>/dev/null)"
_exp="$(cat "$_srcdir/long-ed.out")"
check_eq "$_got" "$_exp" "long-ed: output matches"
# --- long A ---
$DIFF3 -A -L long-m.txt -L long-o.txt -L long-y.txt \
"$_srcdir/long-m.txt" "$_srcdir/long-o.txt" "$_srcdir/long-y.txt" > longAout 2>/dev/null
check_file longAout "$_srcdir/long-A.out" "long-A: output matches"
# --- merge ---
$DIFF3 -m -L 1 -L 2 -L 3 "$_srcdir/1.txt" "$_srcdir/2.txt" "$_srcdir/3.txt" > mergeout 2>/dev/null
check_file mergeout "$_srcdir/9.out" "merge: output matches"
$DIFF3 -m -L long-m.txt -L long-o.txt -L long-y.txt \
"$_srcdir/long-m.txt" "$_srcdir/long-o.txt" "$_srcdir/long-y.txt" > longmergeout 2>/dev/null
check_file longmergeout "$_srcdir/long-merge.out" "long-merge: output matches"
summary