From 46c8f2988dc9a6012babd5833a6245ceff214483 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 7 Jul 2011 12:23:58 +0800 Subject: [PATCH] t4033-diff-patience: factor out tests Group the test cases into two functions, test_diff_(frobnitz|unique). This in preparation for the histogram diff algorithm, which would also re-use these test cases. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- ...33-diff-patience.sh => lib-diff-alternative.sh} | 53 +++--- t/t4033-diff-patience.sh | 180 ++------------------- 2 files changed, 37 insertions(+), 196 deletions(-) copy t/{t4033-diff-patience.sh => lib-diff-alternative.sh} (69%) mode change 100755 => 100644 rewrite t/t4033-diff-patience.sh (95%) diff --git a/t/t4033-diff-patience.sh b/t/lib-diff-alternative.sh old mode 100755 new mode 100644 similarity index 69% copy from t/t4033-diff-patience.sh copy to t/lib-diff-alternative.sh index 1eb14989df..75ffd9174f --- a/t/t4033-diff-patience.sh +++ b/t/lib-diff-alternative.sh @@ -1,10 +1,7 @@ #!/bin/sh -test_description='patience diff algorithm' - -. ./test-lib.sh - -cat >file1 <<\EOF +test_diff_frobnitz() { + cat >file1 <<\EOF #include // Frobs foo heartily @@ -33,7 +30,7 @@ int main(int argc, char **argv) } EOF -cat >file2 <<\EOF + cat >file2 <<\EOF #include int fib(int n) @@ -61,7 +58,7 @@ int main(int argc, char **argv) } EOF -cat >expect <<\EOF + cat >expect <<\EOF diff --git a/file1 b/file2 index 6faa5a3..e3af329 100644 --- a/file1 @@ -105,22 +102,22 @@ index 6faa5a3..e3af329 100644 } EOF -test_expect_success 'patience diff' ' - - test_must_fail git diff --no-index --patience file1 file2 > output && - test_cmp expect output - -' + STRATEGY=$1 -test_expect_success 'patience diff output is valid' ' + test_expect_success "$STRATEGY diff" ' + test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output && + test_cmp expect output + ' - mv file2 expect && - git apply < output && - test_cmp expect file2 - -' + test_expect_success "$STRATEGY diff output is valid" ' + mv file2 expect && + git apply < output && + test_cmp expect file2 + ' +} -cat >uniq1 <<\EOF +test_diff_unique() { + cat >uniq1 <<\EOF 1 2 3 @@ -129,7 +126,7 @@ cat >uniq1 <<\EOF 6 EOF -cat >uniq2 <<\EOF + cat >uniq2 <<\EOF a b c @@ -138,7 +135,7 @@ e f EOF -cat >expect <<\EOF + cat >expect <<\EOF diff --git a/uniq1 b/uniq2 index b414108..0fdf397 100644 --- a/uniq1 @@ -158,11 +155,11 @@ index b414108..0fdf397 100644 +f EOF -test_expect_success 'completely different files' ' + STRATEGY=$1 - test_must_fail git diff --no-index --patience uniq1 uniq2 > output && - test_cmp expect output - -' + test_expect_success 'completely different files' ' + test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output && + test_cmp expect output + ' +} -test_done diff --git a/t/t4033-diff-patience.sh b/t/t4033-diff-patience.sh dissimilarity index 95% index 1eb14989df..3c9932edf3 100755 --- a/t/t4033-diff-patience.sh +++ b/t/t4033-diff-patience.sh @@ -1,168 +1,12 @@ -#!/bin/sh - -test_description='patience diff algorithm' - -. ./test-lib.sh - -cat >file1 <<\EOF -#include - -// Frobs foo heartily -int frobnitz(int foo) -{ - int i; - for(i = 0; i < 10; i++) - { - printf("Your answer is: "); - printf("%d\n", foo); - } -} - -int fact(int n) -{ - if(n > 1) - { - return fact(n-1) * n; - } - return 1; -} - -int main(int argc, char **argv) -{ - frobnitz(fact(10)); -} -EOF - -cat >file2 <<\EOF -#include - -int fib(int n) -{ - if(n > 2) - { - return fib(n-1) + fib(n-2); - } - return 1; -} - -// Frobs foo heartily -int frobnitz(int foo) -{ - int i; - for(i = 0; i < 10; i++) - { - printf("%d\n", foo); - } -} - -int main(int argc, char **argv) -{ - frobnitz(fib(10)); -} -EOF - -cat >expect <<\EOF -diff --git a/file1 b/file2 -index 6faa5a3..e3af329 100644 ---- a/file1 -+++ b/file2 -@@ -1,26 +1,25 @@ - #include - -+int fib(int n) -+{ -+ if(n > 2) -+ { -+ return fib(n-1) + fib(n-2); -+ } -+ return 1; -+} -+ - // Frobs foo heartily - int frobnitz(int foo) - { - int i; - for(i = 0; i < 10; i++) - { -- printf("Your answer is: "); - printf("%d\n", foo); - } - } - --int fact(int n) --{ -- if(n > 1) -- { -- return fact(n-1) * n; -- } -- return 1; --} -- - int main(int argc, char **argv) - { -- frobnitz(fact(10)); -+ frobnitz(fib(10)); - } -EOF - -test_expect_success 'patience diff' ' - - test_must_fail git diff --no-index --patience file1 file2 > output && - test_cmp expect output - -' - -test_expect_success 'patience diff output is valid' ' - - mv file2 expect && - git apply < output && - test_cmp expect file2 - -' - -cat >uniq1 <<\EOF -1 -2 -3 -4 -5 -6 -EOF - -cat >uniq2 <<\EOF -a -b -c -d -e -f -EOF - -cat >expect <<\EOF -diff --git a/uniq1 b/uniq2 -index b414108..0fdf397 100644 ---- a/uniq1 -+++ b/uniq2 -@@ -1,6 +1,6 @@ --1 --2 --3 --4 --5 --6 -+a -+b -+c -+d -+e -+f -EOF - -test_expect_success 'completely different files' ' - - test_must_fail git diff --no-index --patience uniq1 uniq2 > output && - test_cmp expect output - -' - -test_done +#!/bin/sh + +test_description='patience diff algorithm' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-diff-alternative.sh + +test_diff_frobnitz "patience" + +test_diff_unique "patience" + +test_done -- 2.11.4.GIT