#!/bin/sh # tests/test_sdiff.sh - Tests for sdiff applet _test_name="sdiff" . "$(dirname "$0")/harness.sh" _srcdir="$(cd "$(dirname "$0")/../src/sdiff/tests" && pwd)" setup_tmpdir SDIFF="$VX sdiff" echo "Running sdiff tests..." # --- flags: -l, -s, -w --- _got="$($SDIFF -l "$_srcdir/d_input1" "$_srcdir/d_input2" 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_flags_l.out")" check_eq "$_got" "$_exp" "flags: -l output matches" _got="$($SDIFF -s "$_srcdir/d_input1" "$_srcdir/d_input2" 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_flags_s.out")" check_eq "$_got" "$_exp" "flags: -s output matches" _got="$($SDIFF -w 125 "$_srcdir/d_input1" "$_srcdir/d_input2" 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_flags_w.out")" check_eq "$_got" "$_exp" "flags: -w output matches" # --- same file --- _got="$($SDIFF "$_srcdir/d_input1" "$_srcdir/d_input1" 2>/dev/null)" _exp="$(cat "$_srcdir/d_same.out")" check_eq "$_got" "$_exp" "same: identical file output matches" # --- tabs --- _got="$($SDIFF "$_srcdir/d_tabs1.in" "$_srcdir/d_tabs2.in" 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_tabs.out")" check_eq "$_got" "$_exp" "tabs: tab output matches" # --- tabends --- _got="$($SDIFF -w30 "$_srcdir/d_tabends.in" /dev/null 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_tabends_a.out")" check_eq "$_got" "$_exp" "tabends: file vs null (a)" _got="$($SDIFF -w30 /dev/null "$_srcdir/d_tabends.in" 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_tabends_b.out")" check_eq "$_got" "$_exp" "tabends: null vs file (b)" _got="$($SDIFF -w19 "$_srcdir/d_tabends.in" /dev/null 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_tabends_c.out")" check_eq "$_got" "$_exp" "tabends: narrow width (c)" # --- oneline --- _got="$($SDIFF /dev/null "$_srcdir/d_oneline.in" 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_oneline_a.out")" check_eq "$_got" "$_exp" "oneline: null vs file" _got="$($SDIFF "$_srcdir/d_oneline.in" /dev/null 2>/dev/null)" || true _exp="$(cat "$_srcdir/d_oneline_b.out")" check_eq "$_got" "$_exp" "oneline: file vs null" # --- basic side-by-side --- printf "A\nB\nC\n" > sby_a printf "D\nB\nE\n" > sby_b $SDIFF sby_a sby_b > sby_out 2>&1 || true check_grep "|" sby_out "side-by-side: contains change marker" check_grep "B" sby_out "side-by-side: contains common line" # --- exit codes --- printf "a\n" > ex_a printf "b\n" > ex_b cp ex_a ex_a2 check_exit "exit: identical files exit 0" 0 $SDIFF ex_a ex_a2 check_exit "exit: different files exit 1" 1 $SDIFF ex_a ex_b summary