Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/lib-diff-alternative.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / lib-diff-alternative.sh` 227 lines ยท 4422 bytes Raw Blame History 1 # Helpers shared by the test scripts for diff algorithms (patience, 2 # histogram, etc). 3 4 test_diff_frobnitz() { 5 cat >file1 <<\EOF 6 #include 7 8 // Frobs foo heartily 9 int 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 19 int fact(int n) 20 { 21 if(n > 1) 22 { 23 return fact(n-1) * n; 24 } 25 return 1; 26 } 27 28 int main(int argc, char **argv) 29 { 30 frobnitz(fact(10)); 31 } 32 EOF 33 34 cat >file2 <<\EOF 35 #include 36 37 int 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 47 int frobnitz(int foo) 48 { 49 int i; 50 for(i = 0; i < 10; i++) 51 { 52 printf("%d\n", foo); 53 } 54 } 55 56 int main(int argc, char **argv) 57 { 58 frobnitz(fib(10)); 59 } 60 EOF 61 62 file1=$(git rev-parse --short $(git hash-object file1)) 63 file2=$(git rev-parse --short $(git hash-object file2)) 64 cat >expect < 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 } 106 EOF 107 108 cat >expect_diffstat < file2 | 21 ++++++++++----------- 110 1 file changed, 10 insertions(+), 11 deletions(-) 111 EOF 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 179 test_diff_unique() { 180 cat >uniq1 <<\EOF 181 1 182 2 183 3 184 4 185 5 186 6 187 EOF 188 189 cat >uniq2 <<\EOF 190 a 191 b 192 c 193 d 194 e 195 f 196 EOF 197 198 uniq1=$(git rev-parse --short $(git hash-object uniq1)) 199 uniq2=$(git rev-parse --short $(git hash-object uniq2)) 200 cat >expect < output && 224 test_cmp expect output 225 ' 226 } 227