t/t0211-trace2-perf.sh: fix typo patern -> pattern
[alt-git.git] / t / t4125-apply-ws-fuzz.sh
blob090987c89b24b4795bcb80c0461e5c90f3fe5b3b
1 #!/bin/sh
3 test_description='applying patch that has broken whitespaces in context'
5 . ./test-lib.sh
7 test_expect_success setup '
9 >file &&
10 git add file &&
12 # file-0 is full of whitespace breakages
13 printf "%s \n" a bb c d eeee f ggg h >file-0 &&
15 # patch-0 creates a whitespace broken file
16 cat file-0 >file &&
17 git diff >patch-0 &&
18 git add file &&
20 # file-1 is still full of whitespace breakages,
21 # but has one line updated, without fixing any
22 # whitespaces.
23 # patch-1 records that change.
24 sed -e "s/d/D/" file-0 >file-1 &&
25 cat file-1 >file &&
26 git diff >patch-1 &&
28 # patch-all is the effect of both patch-0 and patch-1
29 >file &&
30 git add file &&
31 cat file-1 >file &&
32 git diff >patch-all &&
34 # patch-2 is the same as patch-1 but is based
35 # on a version that already has whitespace fixed,
36 # and does not introduce whitespace breakages.
37 sed -e "s/ \$//" patch-1 >patch-2 &&
39 # If all whitespace breakages are fixed the contents
40 # should look like file-fixed
41 sed -e "s/ \$//" file-1 >file-fixed
45 test_expect_success nofix '
47 >file &&
48 git add file &&
50 # Baseline. Applying without fixing any whitespace
51 # breakages.
52 git apply --whitespace=nowarn patch-0 &&
53 git apply --whitespace=nowarn patch-1 &&
55 # The result should obviously match.
56 test_cmp file-1 file
59 test_expect_success 'withfix (forward)' '
61 >file &&
62 git add file &&
64 # The first application will munge the context lines
65 # the second patch depends on. We should be able to
66 # adjust and still apply.
67 git apply --whitespace=fix patch-0 &&
68 git apply --whitespace=fix patch-1 &&
70 test_cmp file-fixed file
73 test_expect_success 'withfix (backward)' '
75 >file &&
76 git add file &&
78 # Now we have a whitespace breakages on our side.
79 git apply --whitespace=nowarn patch-0 &&
81 # And somebody sends in a patch based on image
82 # with whitespace already fixed.
83 git apply --whitespace=fix patch-2 &&
85 # The result should accept the whitespace fixed
86 # postimage. But the line with "h" is beyond context
87 # horizon and left unfixed.
89 sed -e /h/d file-fixed >fixed-head &&
90 sed -e /h/d file >file-head &&
91 test_cmp fixed-head file-head &&
93 sed -n -e /h/p file-fixed >fixed-tail &&
94 sed -n -e /h/p file >file-tail &&
96 ! test_cmp fixed-tail file-tail
100 test_done