From a15264ba1e5b820db9e09892c55945b816645845 Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Wed, 17 Sep 2025 10:19:15 +0100 Subject: [PATCH 1/2] Add some lsdiff tests Assisted-by: Cursor --- Makefile.am | 3 ++ tests/lsdiff-hunks-option/run-test | 65 ++++++++++++++++++++++++++++ tests/lsdiff-lines-option/run-test | 65 ++++++++++++++++++++++++++++ tests/lsdiff-verbose-levels/run-test | 60 +++++++++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100755 tests/lsdiff-hunks-option/run-test create mode 100755 tests/lsdiff-lines-option/run-test create mode 100755 tests/lsdiff-verbose-levels/run-test diff --git a/Makefile.am b/Makefile.am index f0905b53..ace27e8e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,6 +186,9 @@ TESTS = tests/newline1/run-test \ tests/lsdiff13/run-test \ tests/lsdiff14/run-test \ tests/lsdiff15/run-test \ + tests/lsdiff-hunks-option/run-test \ + tests/lsdiff-lines-option/run-test \ + tests/lsdiff-verbose-levels/run-test \ tests/patchview1/run-test \ tests/patchview2/run-test \ tests/fuzz1/run-test \ diff --git a/tests/lsdiff-hunks-option/run-test b/tests/lsdiff-hunks-option/run-test new file mode 100755 index 00000000..d796abdb --- /dev/null +++ b/tests/lsdiff-hunks-option/run-test @@ -0,0 +1,65 @@ +#!/bin/sh + +# This is a lsdiff(1) testcase for --hunks option. +# Test: Select specific hunks from files + +. ${top_srcdir-.}/tests/common.sh + +cat << EOF > diff +--- file1 ++++ file1 +@@ -1 +1,2 @@ +-A ++a ++b +@@ -10 +11,2 @@ +-C ++c ++d +--- file2 ++++ file2 +@@ -5 +5,2 @@ +-E ++e ++f +@@ -20 +21,2 @@ +-G ++g ++h +EOF + +# Test --hunks 1 (first hunk from each file) +${LSDIFF} --hunks 1 diff 2>errors >hunks1 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - hunks1 || exit 1 +file1 +file2 +EOF + +# Test --hunks 2 (second hunk from each file) +${LSDIFF} --hunks 2 diff 2>errors >hunks2 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - hunks2 || exit 1 +file1 +file2 +EOF + +# Test --hunks 3 (third hunk - lsdiff still shows files even if hunks don't match) +${LSDIFF} --hunks 3 diff 2>errors >hunks3 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - hunks3 || exit 1 +file1 +file2 +EOF + +# Test --hunks 1-2 (range: first and second hunks) +${LSDIFF} --hunks 1-2 diff 2>errors >hunks1-2 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - hunks1-2 || exit 1 +file1 +file2 +EOF diff --git a/tests/lsdiff-lines-option/run-test b/tests/lsdiff-lines-option/run-test new file mode 100755 index 00000000..cdf6981a --- /dev/null +++ b/tests/lsdiff-lines-option/run-test @@ -0,0 +1,65 @@ +#!/bin/sh + +# This is a lsdiff(1) testcase for --lines option. +# Test: Select files containing hunks that touch specific line numbers + +. ${top_srcdir-.}/tests/common.sh + +cat << EOF > diff +--- file1 ++++ file1 +@@ -1 +1,2 @@ +-A ++a ++b +@@ -10 +11,2 @@ +-C ++c ++d +--- file2 ++++ file2 +@@ -5 +5,2 @@ +-E ++e ++f +@@ -20 +21,2 @@ +-G ++g ++h +--- file3 ++++ file3 +@@ -15 +15,2 @@ +-I ++i ++j +EOF + +# Test --lines 1 (files with hunks touching line 1) +${LSDIFF} --lines 1 diff 2>errors >lines1 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - lines1 || exit 1 +file1 +EOF + +# Test --lines 5 (files with hunks touching line 5) +${LSDIFF} --lines 5 diff 2>errors >lines5 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - lines5 || exit 1 +file2 +EOF + +# Test --lines 10-15 (range: files with hunks touching lines 10-15) +${LSDIFF} --lines 10-15 diff 2>errors >lines10-15 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - lines10-15 || exit 1 +file1 +file3 +EOF + +# Test --lines 100 (line that doesn't exist - should be empty) +${LSDIFF} --lines 100 diff 2>errors >lines100 || exit 1 +[ -s errors ] && exit 1 +[ -s lines100 ] && exit 1 # Should be empty diff --git a/tests/lsdiff-verbose-levels/run-test b/tests/lsdiff-verbose-levels/run-test new file mode 100755 index 00000000..4b7cbb7f --- /dev/null +++ b/tests/lsdiff-verbose-levels/run-test @@ -0,0 +1,60 @@ +#!/bin/sh + +# This is a lsdiff(1) testcase for multiple verbose levels. +# Test: -v, -vv, and -nvv for different levels of verbosity + +. ${top_srcdir-.}/tests/common.sh + +cat << EOF > diff +--- file1 ++++ file1 +@@ -1,3 +1,4 @@ function1 + first line +-old content ++new content ++added line + third line +@@ -10,4 +11,3 @@ function2 + context line +-removed line + another line +-old ending ++new ending +--- file2 ++++ file2 +@@ -5,2 +5,3 @@ main + some context +-original text ++modified text ++extra line +EOF + +# Test single -v (basic verbose - same as no flags for lsdiff) +${LSDIFF} -v diff 2>errors >verbose1 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - verbose1 || exit 1 +file1 +file2 +EOF + +# Test double -vv (extra verbose - same as single -v for lsdiff) +${LSDIFF} -vv diff 2>errors >verbose2 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - verbose2 || exit 1 +file1 +file2 +EOF + +# Test -nvv (numbered extra verbose) +${LSDIFF} -nvv diff 2>errors >verbose_nvv || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - verbose_nvv || exit 1 +1 File #1 file1 + 3 Hunk #1 function1 + 9 Hunk #2 function2 +15 File #2 file2 + 17 Hunk #1 main +EOF From bd60e84c1faa3131ddc6e44ec72b42b36a49528e Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Wed, 17 Sep 2025 16:43:52 +0100 Subject: [PATCH 2/2] Mark lsdiff-lines-option and lsdiff-hunks-options tests as expected-fail Those features just doesn't work at all. --- Makefile.am | 4 ++- tests/lsdiff-hunks-option/run-test | 47 +++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Makefile.am b/Makefile.am index ace27e8e..b6fce229 100644 --- a/Makefile.am +++ b/Makefile.am @@ -310,7 +310,9 @@ TESTS = tests/newline1/run-test \ XFAIL_TESTS = \ tests/delhunk5/run-test \ tests/delhunk6/run-test \ - tests/rediff-empty-hunk/run-test + tests/rediff-empty-hunk/run-test \ + tests/lsdiff-hunks-option/run-test \ + tests/lsdiff-lines-option/run-test test-perms: src/combinediff$(EXEEXT) src/flipdiff$(EXEEXT) \ src/lsdiff$(EXEEXT) src/grepdiff$(EXEEXT) src/patchview$(EXEEXT) \ diff --git a/tests/lsdiff-hunks-option/run-test b/tests/lsdiff-hunks-option/run-test index d796abdb..572500f2 100755 --- a/tests/lsdiff-hunks-option/run-test +++ b/tests/lsdiff-hunks-option/run-test @@ -12,10 +12,6 @@ cat << EOF > diff -A +a +b -@@ -10 +11,2 @@ --C -+c -+d --- file2 +++ file2 @@ -5 +5,2 @@ @@ -26,40 +22,69 @@ cat << EOF > diff -G +g +h +--- file3 ++++ file3 +@@ -10 +10,2 @@ +-I ++i ++j +@@ -15 +16,2 @@ +-K ++k ++l +@@ -25 +27,2 @@ +-M ++m ++n EOF -# Test --hunks 1 (first hunk from each file) +# Test --hunks 1 (first hunk - all files have at least 1 hunk) ${LSDIFF} --hunks 1 diff 2>errors >hunks1 || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - hunks1 || exit 1 file1 file2 +file3 EOF -# Test --hunks 2 (second hunk from each file) +# Test --hunks 2 (second hunk - only file2 and file3 have 2+ hunks) ${LSDIFF} --hunks 2 diff 2>errors >hunks2 || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - hunks2 || exit 1 -file1 file2 +file3 EOF -# Test --hunks 3 (third hunk - lsdiff still shows files even if hunks don't match) +# Test --hunks 3 (third hunk - only file3 has 3 hunks) ${LSDIFF} --hunks 3 diff 2>errors >hunks3 || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - hunks3 || exit 1 -file1 -file2 +file3 EOF -# Test --hunks 1-2 (range: first and second hunks) +# Test --hunks 1-2 (range: first and second hunks - all files have hunk 1, file2 and file3 have hunk 2) ${LSDIFF} --hunks 1-2 diff 2>errors >hunks1-2 || exit 1 [ -s errors ] && exit 1 cat << EOF | cmp - hunks1-2 || exit 1 file1 file2 +file3 +EOF + +# Test --hunks 2-3 (range: second and third hunks - file2 has hunk 2, file3 has hunks 2 and 3) +${LSDIFF} --hunks 2-3 diff 2>errors >hunks2-3 || exit 1 +[ -s errors ] && exit 1 + +cat << EOF | cmp - hunks2-3 || exit 1 +file2 +file3 EOF + +# Test --hunks 4 (fourth hunk - no files have 4 hunks, should be empty) +${LSDIFF} --hunks 4 diff 2>errors >hunks4 || exit 1 +[ -s errors ] && exit 1 +[ -s hunks4 ] && exit 1 # Should be empty