Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -307,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) \
Expand Down
90 changes: 90 additions & 0 deletions tests/lsdiff-hunks-option/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/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
--- file2
+++ file2
@@ -5 +5,2 @@
-E
+e
+f
@@ -20 +21,2 @@
-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 - 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 - 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
file2
file3
EOF

# 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
file3
EOF

# 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
65 changes: 65 additions & 0 deletions tests/lsdiff-lines-option/run-test
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions tests/lsdiff-verbose-levels/run-test
Original file line number Diff line number Diff line change
@@ -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