Debian Codegraph @

tests/grepdiff-original-line-numbers/run-test

raw
1 #!/bin/sh
2
3 # Test for grepdiff --as-numbered-lines=original-* options
4 # Tests the new original-before and original-after options that preserve
5 # original line numbers from the diff (useful for CI/CD error reporting)
6 # Addresses GitHub issue #55
7
8 . ${top_srcdir-.}/tests/common.sh
9
10 # Create a test diff that reproduces the issue from the GitHub issue
11 cat << EOF > diff
12 diff --git a/foobar.txt b/foobar.txt
13 index 8a19eed..ae745cf 100644
14 --- a/foobar.txt
15 +++ b/foobar.txt
16 @@ -0,0 +1,4 @@
17 +# pre-comment
18 +# spread over
19 +# three lines
20 +
21 @@ -8 +12 @@
22 -foo()
23 +foo(bar)
24 EOF
25
26 # Test --output-matching=hunk (shows adjusted line numbers in hunk headers)
27 ${GREPDIFF} --git-prefixes=strip foo --output-matching=hunk diff 2>errors >hunk_output || exit 1
28 [ -s errors ] && exit 1
29
30 # The hunk output shows adjusted line numbers (this is the existing behavior)
31 cat << EOF | cmp - hunk_output || exit 1
32 diff --git a/foobar.txt b/foobar.txt
33 index 8a19eed..ae745cf 100644
34 --- a/foobar.txt
35 +++ b/foobar.txt
36 @@ -8 +8 @@
37 -foo()
38 +foo(bar)
39 EOF
40
41 # Test --as-numbered-lines=original-after (the new option for this use case)
42 ${GREPDIFF} --git-prefixes=strip foo --output-matching=hunk --only-match=additions --as-numbered-lines=original-after diff 2>errors2 >numbered_output || exit 1
43 [ -s errors2 ] && exit 1
44
45 # The expected output should show line 12 (original line number from diff)
46 cat << EOF | cmp - numbered_output || exit 1
47 diff --git a/foobar.txt b/foobar.txt
48 index 8a19eed..ae745cf 100644
49 +++ b/foobar.txt
50 12 :foo(bar)
51 EOF
52
53 # Test --as-numbered-lines=original-before
54 ${GREPDIFF} --git-prefixes=strip foo --output-matching=hunk --only-match=additions --as-numbered-lines=original-before diff 2>errors3 >numbered_before_output || exit 1
55 [ -s errors3 ] && exit 1
56
57 # This should show line 8 for the "before" version (original line number from diff)
58 cat << EOF | cmp - numbered_before_output || exit 1
59 diff --git a/foobar.txt b/foobar.txt
60 index 8a19eed..ae745cf 100644
61 --- a/foobar.txt
62 8 :foo()
63 EOF
64
65 # Test that regular --as-numbered-lines=after still works with adjusted line numbers
66 ${GREPDIFF} --git-prefixes=strip foo --output-matching=hunk --only-match=additions --as-numbered-lines=after diff 2>errors4 >numbered_adjusted_output || exit 1
67 [ -s errors4 ] && exit 1
68
69 # This should show line 8 (adjusted line number, old behavior)
70 cat << EOF | cmp - numbered_adjusted_output || exit 1
71 diff --git a/foobar.txt b/foobar.txt
72 index 8a19eed..ae745cf 100644
73 +++ b/foobar.txt
74 8 :foo(bar)
75 EOF