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
33 changes: 31 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ DISTCLEANFILES = src/stamp-h[0-9]* src/config.h

bin_PROGRAMS = src/interdiff src/filterdiff src/rediff

# lsdiff is provided by symlink to filterdiff (unless scanner-patchfilter is enabled)

# Scanner-based unified patchfilter tool (experimental)
if USE_SCANNER_PATCHFILTER
bin_PROGRAMS += src/patchfilter
Expand Down Expand Up @@ -152,6 +150,11 @@ $(filterdiff_links): src/filterdiff$(EXEEXT)
$(patchview_links): patchview/patchview-wrapper$(EXEEXT)
ln -sf $(notdir $<) $@

# Ensure all symlinks are created during build
all-local: $(interdiff_links) $(filterdiff_links) src/lsdiff$(EXEEXT) src/grepdiff$(EXEEXT)
@test -d patchview || mkdir -p patchview
@$(MAKE) $(AM_MAKEFLAGS) $(patchview_links)

install-exec-hook:
@for f in $(interdiff_links); do \
ln -sf "`echo interdiff$(EXEEXT) | sed '$(transform)'`" \
Expand Down Expand Up @@ -290,6 +293,11 @@ TESTS = tests/newline1/run-test \
tests/lsdiff13/run-test \
tests/lsdiff14/run-test \
tests/lsdiff15/run-test \
tests/lsdiff-number-files/run-test \
tests/lsdiff-files-range/run-test \
tests/lsdiff-empty-files-removed/run-test \
tests/lsdiff-addprefix/run-test \
tests/lsdiff-strip-match/run-test \
tests/lsdiff-hunks-option/run-test \
tests/lsdiff-lines-option/run-test \
tests/lsdiff-exclusion-combined/run-test \
Expand Down Expand Up @@ -320,6 +328,12 @@ TESTS = tests/newline1/run-test \
tests/grepdiff8/run-test \
tests/grepdiff9/run-test \
tests/grepdiff-original-line-numbers/run-test \
tests/grepdiff-number-files/run-test \
tests/grepdiff-status/run-test \
tests/grepdiff-include-exclude/run-test \
tests/grepdiff-file-regex/run-test \
tests/grepdiff-annotate/run-test \
tests/grepdiff-with-filename/run-test \
tests/number1/run-test \
tests/number2/run-test \
tests/number3/run-test \
Expand Down Expand Up @@ -445,6 +459,21 @@ XFAIL_TESTS += \
tests/lsdiff-exclusion-mode/run-test
endif

# grepdiff tests: expected to fail when scanner-patchfilter is enabled
# (features not yet implemented in scanner-based grepdiff)
if USE_SCANNER_PATCHFILTER
XFAIL_TESTS += \
tests/grepdiff-status/run-test \
tests/grepdiff-annotate/run-test
endif

# lsdiff tests: expected to fail when scanner-patchfilter is enabled
# (features not yet implemented in scanner-based lsdiff)
if USE_SCANNER_PATCHFILTER
XFAIL_TESTS += \
tests/lsdiff-strip-match/run-test
endif

test-perms: src/combinediff$(EXEEXT) src/flipdiff$(EXEEXT) \
src/lsdiff$(EXEEXT) src/grepdiff$(EXEEXT) src/patchview$(EXEEXT) \
scripts/splitdiff
Expand Down
34 changes: 34 additions & 0 deletions tests/grepdiff-annotate/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

# Test grepdiff --annotate option

. ${top_srcdir-.}/tests/common.sh

cat << EOF > diff
--- file1
+++ file1
@@ -1,2 +1,2 @@
context
-old
+new
@@ -10 +10 @@
-another
+change
--- file2
+++ file2
@@ -1 +1 @@
-foo
+bar
EOF

${GREPDIFF} --annotate --output-matching=hunk 'new' diff 2>errors >output || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output || exit 1
--- file1
+++ file1
@@ -1,2 +1,2 @@ Hunk #1, file1
context
-old
+new
EOF
36 changes: 36 additions & 0 deletions tests/grepdiff-file-regex/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

# Test grepdiff -f/--file option (read regexes from file)

. ${top_srcdir-.}/tests/common.sh

cat << EOF > diff
--- file1
+++ file1
@@ -1 +1 @@
-apple
+banana
--- file2
+++ file2
@@ -1 +1 @@
-cherry
+date
--- file3
+++ file3
@@ -1 +1 @@
-elderberry
+fig
EOF

cat << EOF > patterns
banana
date
EOF

${GREPDIFF} -f patterns diff 2>errors >output || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output || exit 1
file1
file2
EOF
49 changes: 49 additions & 0 deletions tests/grepdiff-include-exclude/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

# Test grepdiff -i/--include and -x/--exclude options

. ${top_srcdir-.}/tests/common.sh

cat << EOF > diff
--- src/file1.c
+++ src/file1.c
@@ -1 +1 @@
-old
+new
--- docs/readme.txt
+++ docs/readme.txt
@@ -1 +1 @@
-old
+new
--- src/file2.c
+++ src/file2.c
@@ -1 +1 @@
-old
+new
EOF

# Test include pattern
${GREPDIFF} -i '*.c' 'new' diff 2>errors >output || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output || exit 1
src/file1.c
src/file2.c
EOF

# Test exclude pattern
${GREPDIFF} -x '*.txt' 'new' diff 2>errors >output2 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output2 || exit 1
src/file1.c
src/file2.c
EOF

# Test combination of include and exclude
${GREPDIFF} -i 'src/*' -x '*file2*' 'new' diff 2>errors >output3 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output3 || exit 1
src/file1.c
EOF
40 changes: 40 additions & 0 deletions tests/grepdiff-number-files/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

# Test grepdiff -N/--number-files option

. ${top_srcdir-.}/tests/common.sh

cat << EOF > diff
--- file1
+++ file1
@@ -1 +1 @@
-old
+new
--- file2
+++ file2
@@ -1 +1 @@
-foo
+bar
--- file3
+++ file3
@@ -1 +1 @@
-test
+result
EOF

${GREPDIFF} -N 'new' diff 2>errors >output || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output || exit 1
File #1 file1
EOF

# Test with multiple matches (pattern matches content in files 1 and 3)
${GREPDIFF} -N '[ot]' diff 2>errors >output2 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output2 || exit 1
File #1 file1
File #2 file2
File #3 file3
EOF
38 changes: 38 additions & 0 deletions tests/grepdiff-status/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

# Test grepdiff -s/--status option
# Shows file status: + (addition), - (removal), ! (modification)

. ${top_srcdir-.}/tests/common.sh

cat << EOF > diff
--- /dev/null
+++ newfile
@@ -0,0 +1 @@
+content
--- oldfile
+++ /dev/null
@@ -1 +0,0 @@
-content
--- modified
+++ modified
@@ -1 +1 @@
-old
+new
EOF

${GREPDIFF} -s 'content' diff 2>errors >output || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output || exit 1
! newfile
! oldfile
EOF

# Test with modification
${GREPDIFF} -s 'new' diff 2>errors >output2 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output2 || exit 1
! modified
EOF
45 changes: 45 additions & 0 deletions tests/grepdiff-with-filename/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

# Test grepdiff -H/--with-filename and -h/--no-filename options

. ${top_srcdir-.}/tests/common.sh

cat << EOF > patch1
--- file1
+++ file1
@@ -1 +1 @@
-old
+new
EOF

cat << EOF > patch2
--- file2
+++ file2
@@ -1 +1 @@
-foo
+bar
EOF

# Test with multiple patch files (should show filenames by default)
${GREPDIFF} 'new' patch1 patch2 2>errors >output || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output || exit 1
patch1:file1
EOF

# Test -H explicitly
${GREPDIFF} -H 'new' patch1 patch2 2>errors >output2 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output2 || exit 1
patch1:file1
EOF

# Test -h to suppress filename
${GREPDIFF} -h 'new' patch1 patch2 2>errors >output3 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output3 || exit 1
file1
EOF
26 changes: 26 additions & 0 deletions tests/lsdiff-addprefix/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# Test lsdiff --addprefix option

. ${top_srcdir-.}/tests/common.sh

cat << EOF > diff
--- file1
+++ file1
@@ -1 +1 @@
-old
+new
--- file2
+++ file2
@@ -1 +1 @@
-foo
+bar
EOF

${LSDIFF} --addprefix=prefix/ diff 2>errors >output || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output || exit 1
prefix/file1
prefix/file2
EOF
44 changes: 44 additions & 0 deletions tests/lsdiff-empty-files-removed/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

# Test lsdiff -E/--empty-files-as-removed option

. ${top_srcdir-.}/tests/common.sh

# Create diffs where files become empty or start empty
mkdir dir dir.orig

# File that becomes empty (modified -> empty)
echo content > dir.orig/becomes-empty
touch dir/becomes-empty

# File that starts empty (empty -> modified)
touch dir.orig/was-empty
echo content > dir/was-empty

# Normal modification
echo old > dir.orig/modified
echo new > dir/modified

${DIFF} -uN dir.orig dir > diff

# Without -E, files that are/become empty show as modifications
${LSDIFF} -s --strip=1 diff 2>errors >output1 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output1 || exit 1
! becomes-empty
! modified
! was-empty
EOF

# With -E, treat empty files as absent
# becomes-empty: content->empty = treated as removal
# was-empty: empty->content = treated as addition
${LSDIFF} -sE --strip=1 diff 2>errors >output2 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - output2 || exit 1
- becomes-empty
! modified
+ was-empty
EOF
Loading