File: run-test

package info (click to toggle)
patchutils 0.4.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,976 kB
  • sloc: ansic: 20,804; sh: 11,956; xml: 2,831; perl: 419; makefile: 300; python: 23
file content (75 lines) | stat: -rwxr-xr-x 2,379 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh

# Test for grepdiff --as-numbered-lines=original-* options
# Tests the new original-before and original-after options that preserve
# original line numbers from the diff (useful for CI/CD error reporting)
# Addresses GitHub issue #55

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

# Create a test diff that reproduces the issue from the GitHub issue
cat << EOF > diff
diff --git a/foobar.txt b/foobar.txt
index 8a19eed..ae745cf 100644
--- a/foobar.txt
+++ b/foobar.txt
@@ -0,0 +1,4 @@
+# pre-comment
+# spread over
+# three lines
+
@@ -8 +12 @@
-foo()
+foo(bar)
EOF

# Test --output-matching=hunk (shows adjusted line numbers in hunk headers)
${GREPDIFF} foo --output-matching=hunk diff 2>errors >hunk_output || exit 1
[ -s errors ] && exit 1

# The hunk output shows adjusted line numbers (this is the existing behavior)
cat << EOF | cmp - hunk_output || exit 1
diff --git a/foobar.txt b/foobar.txt
index 8a19eed..ae745cf 100644
--- a/foobar.txt
+++ b/foobar.txt
@@ -8 +8 @@
-foo()
+foo(bar)
EOF

# Test --as-numbered-lines=original-after (the new option for this use case)
${GREPDIFF} foo --output-matching=hunk --only-match=additions --as-numbered-lines=original-after diff 2>errors2 >numbered_output || exit 1
[ -s errors2 ] && exit 1

# The expected output should show line 12 (original line number from diff)
cat << EOF | cmp - numbered_output || exit 1
diff --git a/foobar.txt b/foobar.txt
index 8a19eed..ae745cf 100644
+++ b/foobar.txt
12	:foo(bar)
EOF

# Test --as-numbered-lines=original-before
${GREPDIFF} foo --output-matching=hunk --only-match=additions --as-numbered-lines=original-before diff 2>errors3 >numbered_before_output || exit 1
[ -s errors3 ] && exit 1

# This should show line 8 for the "before" version (original line number from diff)
cat << EOF | cmp - numbered_before_output || exit 1
diff --git a/foobar.txt b/foobar.txt
index 8a19eed..ae745cf 100644
--- a/foobar.txt
8	:foo()
EOF

# Test that regular --as-numbered-lines=after still works with adjusted line numbers
${GREPDIFF} foo --output-matching=hunk --only-match=additions --as-numbered-lines=after diff 2>errors4 >numbered_adjusted_output || exit 1
[ -s errors4 ] && exit 1

# This should show line 8 (adjusted line number, old behavior)
cat << EOF | cmp - numbered_adjusted_output || exit 1
diff --git a/foobar.txt b/foobar.txt
index 8a19eed..ae745cf 100644
+++ b/foobar.txt
8	:foo(bar)
EOF