Import VX multicall utility and applets
This commit is contained in:
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
# tests/test_patch.sh - Tests for patch applet
|
||||
_test_name="patch"
|
||||
. "$(dirname "$0")/harness.sh"
|
||||
_srcdir="$(cd "$(dirname "$0")/../src/patch/tests" && pwd)"
|
||||
|
||||
setup_tmpdir
|
||||
PATCH="$VX patch"
|
||||
|
||||
echo "Running patch tests..."
|
||||
|
||||
# --- basic: apply unified diffs from various starting points ---
|
||||
printf "a\nb\nc\nd\ne\nf\ng\nh\ni\n" > foo_full
|
||||
printf "a\nb\nc\n" > foo_start
|
||||
printf "g\nh\ni\n" > foo_end
|
||||
printf "d\ne\nf\n" > foo_middle
|
||||
|
||||
$VX diff -u foo_start foo_full > foo_start2full.diff || true
|
||||
$VX diff -u foo_end foo_full > foo_end2full.diff || true
|
||||
$VX diff -u foo_middle foo_full > foo_mid2full.diff || true
|
||||
|
||||
# Each diff should be 12 lines (9 content lines + 3 header)
|
||||
_lines=$(wc -l < foo_start2full.diff | tr -d ' ')
|
||||
check_eq "$_lines" "12" "basic: start diff is 12 lines"
|
||||
|
||||
_lines=$(wc -l < foo_end2full.diff | tr -d ' ')
|
||||
check_eq "$_lines" "12" "basic: end diff is 12 lines"
|
||||
|
||||
_lines=$(wc -l < foo_mid2full.diff | tr -d ' ')
|
||||
check_eq "$_lines" "12" "basic: mid diff is 12 lines"
|
||||
|
||||
# Apply patches
|
||||
$PATCH foo_start foo_start2full.diff -o foo_start2full >/dev/null 2>&1
|
||||
check_exit "basic: apply start->full" 0 diff -q foo_start2full foo_full
|
||||
|
||||
$PATCH foo_end foo_end2full.diff -o foo_end2full >/dev/null 2>&1
|
||||
check_exit "basic: apply end->full" 0 diff -q foo_end2full foo_full
|
||||
|
||||
$PATCH foo_middle foo_mid2full.diff -o foo_mid2full >/dev/null 2>&1
|
||||
check_exit "basic: apply mid->full" 0 diff -q foo_mid2full foo_full
|
||||
|
||||
# --- limited context: PR74127 regression ---
|
||||
check_exit "limited_ctx: bad diff rejected" 1 \
|
||||
$PATCH -o _.out "$_srcdir/PR74127.in" "$_srcdir/PR74127-repro.diff"
|
||||
|
||||
check_exit "limited_ctx: good diff accepted" 0 \
|
||||
$PATCH -o _.out "$_srcdir/PR74127.in" "$_srcdir/PR74127-good.diff"
|
||||
|
||||
# --- file creation ---
|
||||
echo "x" > fc_foo
|
||||
$VX diff -u /dev/null fc_foo > fc_foo.diff || true
|
||||
rm fc_foo
|
||||
$PATCH -s < fc_foo.diff >/dev/null 2>&1
|
||||
check_exit "file_creation: creates file" 0 test -f fc_foo
|
||||
|
||||
# --- reverse removal ---
|
||||
echo "x" > rev_foo
|
||||
$VX diff -u /dev/null rev_foo > rev_foo.diff || true
|
||||
$PATCH -Rs < rev_foo.diff >/dev/null 2>&1
|
||||
check_exit "file_removal: file removed" 1 test -f rev_foo
|
||||
|
||||
summary
|
||||
Reference in New Issue
Block a user