Git fork
at reftables-rust 227 lines 4.4 kB view raw
1# Helpers shared by the test scripts for diff algorithms (patience, 2# histogram, etc). 3 4test_diff_frobnitz() { 5 cat >file1 <<\EOF 6#include <stdio.h> 7 8// Frobs foo heartily 9int frobnitz(int foo) 10{ 11 int i; 12 for(i = 0; i < 10; i++) 13 { 14 printf("Your answer is: "); 15 printf("%d\n", foo); 16 } 17} 18 19int fact(int n) 20{ 21 if(n > 1) 22 { 23 return fact(n-1) * n; 24 } 25 return 1; 26} 27 28int main(int argc, char **argv) 29{ 30 frobnitz(fact(10)); 31} 32EOF 33 34 cat >file2 <<\EOF 35#include <stdio.h> 36 37int fib(int n) 38{ 39 if(n > 2) 40 { 41 return fib(n-1) + fib(n-2); 42 } 43 return 1; 44} 45 46// Frobs foo heartily 47int frobnitz(int foo) 48{ 49 int i; 50 for(i = 0; i < 10; i++) 51 { 52 printf("%d\n", foo); 53 } 54} 55 56int main(int argc, char **argv) 57{ 58 frobnitz(fib(10)); 59} 60EOF 61 62 file1=$(git rev-parse --short $(git hash-object file1)) 63 file2=$(git rev-parse --short $(git hash-object file2)) 64 cat >expect <<EOF 65diff --git a/file1 b/file2 66index $file1..$file2 100644 67--- a/file1 68+++ b/file2 69@@ -1,26 +1,25 @@ 70 #include <stdio.h> 71 72+int fib(int n) 73+{ 74+ if(n > 2) 75+ { 76+ return fib(n-1) + fib(n-2); 77+ } 78+ return 1; 79+} 80+ 81 // Frobs foo heartily 82 int frobnitz(int foo) 83 { 84 int i; 85 for(i = 0; i < 10; i++) 86 { 87- printf("Your answer is: "); 88 printf("%d\n", foo); 89 } 90 } 91 92-int fact(int n) 93-{ 94- if(n > 1) 95- { 96- return fact(n-1) * n; 97- } 98- return 1; 99-} 100- 101 int main(int argc, char **argv) 102 { 103- frobnitz(fact(10)); 104+ frobnitz(fib(10)); 105 } 106EOF 107 108 cat >expect_diffstat <<EOF 109 file1 => file2 | 21 ++++++++++----------- 110 1 file changed, 10 insertions(+), 11 deletions(-) 111EOF 112 113 STRATEGY=$1 114 115 test_expect_success "setup attributes files for tests with $STRATEGY" ' 116 git checkout -b master && 117 echo "file* diff=driver" >.gitattributes && 118 git add file1 file2 .gitattributes && 119 git commit -m "adding files" && 120 git checkout -b branchA && 121 echo "file* diff=driverA" >.gitattributes && 122 git add .gitattributes && 123 git commit -m "adding driverA as diff driver" && 124 git checkout master && 125 git clone --bare --no-local . bare.git 126 ' 127 128 test_expect_success "$STRATEGY diff from attributes" ' 129 test_must_fail git -c diff.driver.algorithm=$STRATEGY diff --no-index file1 file2 > output && 130 test_cmp expect output 131 ' 132 133 test_expect_success "diff from attributes with bare repo with source" ' 134 git -C bare.git --attr-source=branchA -c diff.driver.algorithm=myers \ 135 -c diff.driverA.algorithm=$STRATEGY \ 136 diff HEAD:file1 HEAD:file2 >output && 137 test_cmp expect output 138 ' 139 140 test_expect_success "diff from attributes with bare repo with invalid source" ' 141 test_must_fail git -C bare.git --attr-source=invalid-branch diff \ 142 HEAD:file1 HEAD:file2 143 ' 144 145 test_expect_success "$STRATEGY diff from attributes has valid diffstat" ' 146 echo "file* diff=driver" >.gitattributes && 147 git config diff.driver.algorithm "$STRATEGY" && 148 test_must_fail git diff --stat --no-index file1 file2 > output && 149 test_cmp expect_diffstat output 150 ' 151 152 test_expect_success "$STRATEGY diff" ' 153 test_must_fail git diff --no-index "--diff-algorithm=$STRATEGY" file1 file2 > output && 154 test_cmp expect output 155 ' 156 157 test_expect_success "$STRATEGY diff command line precedence before attributes" ' 158 echo "file* diff=driver" >.gitattributes && 159 git config diff.driver.algorithm myers && 160 test_must_fail git diff --no-index "--diff-algorithm=$STRATEGY" file1 file2 > output && 161 test_cmp expect output 162 ' 163 164 test_expect_success "$STRATEGY diff attributes precedence before config" ' 165 git config diff.algorithm default && 166 echo "file* diff=driver" >.gitattributes && 167 git config diff.driver.algorithm "$STRATEGY" && 168 test_must_fail git diff --no-index file1 file2 > output && 169 test_cmp expect output 170 ' 171 172 test_expect_success "$STRATEGY diff output is valid" ' 173 mv file2 expect && 174 git apply < output && 175 test_cmp expect file2 176 ' 177} 178 179test_diff_unique() { 180 cat >uniq1 <<\EOF 1811 1822 1833 1844 1855 1866 187EOF 188 189 cat >uniq2 <<\EOF 190a 191b 192c 193d 194e 195f 196EOF 197 198 uniq1=$(git rev-parse --short $(git hash-object uniq1)) 199 uniq2=$(git rev-parse --short $(git hash-object uniq2)) 200 cat >expect <<EOF 201diff --git a/uniq1 b/uniq2 202index $uniq1..$uniq2 100644 203--- a/uniq1 204+++ b/uniq2 205@@ -1,6 +1,6 @@ 206-1 207-2 208-3 209-4 210-5 211-6 212+a 213+b 214+c 215+d 216+e 217+f 218EOF 219 220 STRATEGY=$1 221 222 test_expect_success 'completely different files' ' 223 test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output && 224 test_cmp expect output 225 ' 226} 227