Debian Codegraph @

tests/patch-ignore-whitespace/run-test

raw
1 #!/bin/sh
2
3 # This is an interdiff(1) testcase.
4 # Test: Verify that -w option enables patch -l behavior for whitespace tolerance
5
6 . ${top_srcdir-.}/tests/common.sh
7
8 # Create a scenario where patch application would fail without -l but succeed with -l
9 # This simulates the core functionality our change provides
10
11 # Create original file
12 cat << EOF > original.txt
13 function test() {
14 var x = 1;
15 var y = 2;
16 return x + y;
17 }
18 EOF
19
20 # Create version 1 with a change
21 cat << EOF > version1.txt
22 function test() {
23 var x = 1;
24 var y = 3;
25 return x + y;
26 }
27 EOF
28
29 # Create version 2 with whitespace differences that would cause patch to fail
30 cat << EOF > version2.txt
31 function test() {
32 var x = 1;
33 var y = 4;
34 return x + y;
35 }
36 EOF
37
38 # Create patches
39 ${DIFF} -u original.txt version1.txt > patch1 || true
40 ${DIFF} -u version1.txt version2.txt > patch2 || true
41
42 # Add some whitespace variations to make patch application challenging
43 # Modify patch2 to have different whitespace that would cause normal patch to fail
44 sed 's/var y = 4;/var y = 4; /' patch2 > patch2-ws
45
46 # Test without -w: This might fail due to whitespace issues
47 ${INTERDIFF} patch1 patch2-ws > result-strict 2>errors-strict || STRICT_FAILED=$?
48
49 # Test with -w: This should succeed because -w enables patch -l
50 ${INTERDIFF} -w patch1 patch2-ws > result-tolerant 2>errors-tolerant || exit 1
51
52 # Verify that -w version succeeded
53 [ $? -eq 0 ] || exit 1
54
55 # The result should show the change from y=3 to y=4
56 grep -E "(var y = 4|y = 4)" result-tolerant > /dev/null || exit 1
57
58 # Test a more direct scenario: patches that only differ in whitespace
59 cat << EOF > file-tabs.txt
60 line1
61 line2
62 line3
63 EOF
64
65 cat << EOF > file-spaces.txt
66 line1
67 line2
68 line3
69 EOF
70
71 ${DIFF} -u original.txt file-tabs.txt > patch-tabs || true
72 ${DIFF} -u original.txt file-spaces.txt > patch-spaces || true
73
74 # Without -w, this might show whitespace differences
75 ${INTERDIFF} patch-tabs patch-spaces > result-ws-strict 2>errors-ws-strict || WS_STRICT_FAILED=$?
76
77 # With -w, this should handle the whitespace differences gracefully
78 ${INTERDIFF} -w patch-tabs patch-spaces > result-ws-tolerant 2>errors-ws-tolerant || exit 1
79
80 # Success if we reach here
81 exit 0