From ac2e28c0a43ced3837fbbcf66fd693244b6c6693 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 20 Jul 2008 01:33:46 -0700 Subject: [PATCH] tests: do not rely on external "patch" Some of our tests assumed a working "patch" command to produce expected results when checking "git-apply", but some systems have broken "patch". We can compare our output with expected output that is precomputed instead to sidestep this issue. Signed-off-by: Junio C Hamano --- t/t4109-apply-multifrag.sh | 55 ++++++++-------------- t/t4109/expect-1 | 31 ++++++++++++ t/t4109/expect-2 | 23 +++++++++ t/t4109/expect-3 | 24 ++++++++++ t/t4110-apply-scan.sh | 96 ++++---------------------------------- t/t4110/expect | 20 ++++++++ t/t4110/patch1.patch | 17 +++++++ t/t4110/patch2.patch | 11 +++++ t/t4110/patch3.patch | 14 ++++++ t/t4110/patch4.patch | 11 +++++ t/t4110/patch5.patch | 11 +++++ 11 files changed, 190 insertions(+), 123 deletions(-) create mode 100644 t/t4109/expect-1 create mode 100644 t/t4109/expect-2 create mode 100644 t/t4109/expect-3 create mode 100644 t/t4110/expect create mode 100644 t/t4110/patch1.patch create mode 100644 t/t4110/patch2.patch create mode 100644 t/t4110/patch3.patch create mode 100644 t/t4110/patch4.patch create mode 100644 t/t4110/patch5.patch diff --git a/t/t4109-apply-multifrag.sh b/t/t4109-apply-multifrag.sh index ff5fdf35f..ac58083fe 100755 --- a/t/t4109-apply-multifrag.sh +++ b/t/t4109-apply-multifrag.sh @@ -4,49 +4,32 @@ # Copyright (c) 2005 Robert Fitzsimons # -test_description='git apply test patches with multiple fragments. +test_description='git apply test patches with multiple fragments.' -' . ./test-lib.sh -cp ../t4109/patch1.patch . -cp ../t4109/patch2.patch . -cp ../t4109/patch3.patch . -cp ../t4109/patch4.patch . - -test_expect_success "S = git apply (1)" \ - 'git apply patch1.patch patch2.patch' -mv main.c main.c.git - -test_expect_success "S = patch (1)" \ - 'cat patch1.patch patch2.patch | patch -p1' - -test_expect_success "S = cmp (1)" \ - 'cmp main.c.git main.c' - -rm -f main.c main.c.git - -test_expect_success "S = git apply (2)" \ - 'git apply patch1.patch patch2.patch patch3.patch' -mv main.c main.c.git - -test_expect_success "S = patch (2)" \ - 'cat patch1.patch patch2.patch patch3.patch | patch -p1' +cp "$TEST_DIRECTORY/t4109/patch1.patch" . +cp "$TEST_DIRECTORY/t4109/patch2.patch" . +cp "$TEST_DIRECTORY/t4109/patch3.patch" . +cp "$TEST_DIRECTORY/t4109/patch4.patch" . -test_expect_success "S = cmp (2)" \ - 'cmp main.c.git main.c' +test_expect_success 'git apply (1)' ' + git apply patch1.patch patch2.patch && + test_cmp "$TEST_DIRECTORY/t4109/expect-1" main.c +' +rm -f main.c -rm -f main.c main.c.git +test_expect_success 'git apply (2)' ' + git apply patch1.patch patch2.patch patch3.patch && + test_cmp "$TEST_DIRECTORY/t4109/expect-2" main.c +' +rm -f main.c -test_expect_success "S = git apply (3)" \ - 'git apply patch1.patch patch4.patch' +test_expect_success 'git apply (3)' ' + git apply patch1.patch patch4.patch && + test_cmp "$TEST_DIRECTORY/t4109/expect-3" main.c +' mv main.c main.c.git -test_expect_success "S = patch (3)" \ - 'cat patch1.patch patch4.patch | patch -p1' - -test_expect_success "S = cmp (3)" \ - 'cmp main.c.git main.c' - test_done diff --git a/t/t4109/expect-1 b/t/t4109/expect-1 new file mode 100644 index 000000000..1db5ff105 --- /dev/null +++ b/t/t4109/expect-1 @@ -0,0 +1,31 @@ +#include +#include + +int func(int num); +void print_int(int num); +void print_ln(); + +int main() { + int i; + + for (i = 0; i < 10; i++) { + print_int(func(i)); + } + + print_ln(); + + return 0; +} + +int func(int num) { + return num * num; +} + +void print_int(int num) { + printf("%d", num); +} + +void print_ln() { + printf("\n"); +} + diff --git a/t/t4109/expect-2 b/t/t4109/expect-2 new file mode 100644 index 000000000..bc5292411 --- /dev/null +++ b/t/t4109/expect-2 @@ -0,0 +1,23 @@ +#include + +int func(int num); +void print_int(int num); + +int main() { + int i; + + for (i = 0; i < 10; i++) { + print_int(func(i)); + } + + return 0; +} + +int func(int num) { + return num * num; +} + +void print_int(int num) { + printf("%d", num); +} + diff --git a/t/t4109/expect-3 b/t/t4109/expect-3 new file mode 100644 index 000000000..cd2a475fe --- /dev/null +++ b/t/t4109/expect-3 @@ -0,0 +1,24 @@ +#include + +int func(int num); +int func2(int num); + +int main() { + int i; + + for (i = 0; i < 10; i++) { + printf("%d", func(i)); + printf("%d", func3(i)); + } + + return 0; +} + +int func(int num) { + return num * num; +} + +int func2(int num) { + return num * num * num; +} + diff --git a/t/t4110-apply-scan.sh b/t/t4110-apply-scan.sh index db60652a3..09f58112e 100755 --- a/t/t4110-apply-scan.sh +++ b/t/t4110-apply-scan.sh @@ -9,92 +9,14 @@ test_description='git apply test for patches which require scanning forwards and ' . ./test-lib.sh -# setup - -cat > patch1.patch <<\EOF -diff --git a/new.txt b/new.txt -new file mode 100644 ---- /dev/null -+++ b/new.txt -@@ -0,0 +1,12 @@ -+a1 -+a11 -+a111 -+a1111 -+b1 -+b11 -+b111 -+b1111 -+c1 -+c11 -+c111 -+c1111 -EOF -cat > patch2.patch <<\EOF -diff --git a/new.txt b/new.txt ---- a/new.txt -+++ b/new.txt -@@ -1,7 +1,3 @@ --a1 --a11 --a111 --a1111 - b1 - b11 - b111 -EOF -cat > patch3.patch <<\EOF -diff --git a/new.txt b/new.txt ---- a/new.txt -+++ b/new.txt -@@ -6,6 +6,10 @@ - b11 - b111 - b1111 -+b2 -+b22 -+b222 -+b2222 - c1 - c11 - c111 -EOF -cat > patch4.patch <<\EOF -diff --git a/new.txt b/new.txt ---- a/new.txt -+++ b/new.txt -@@ -1,3 +1,7 @@ -+a1 -+a11 -+a111 -+a1111 - b1 - b11 - b111 -EOF -cat > patch5.patch <<\EOF -diff --git a/new.txt b/new.txt ---- a/new.txt -+++ b/new.txt -@@ -10,3 +10,7 @@ - c11 - c111 - c1111 -+c2 -+c22 -+c222 -+c2222 -EOF - -test_expect_success "S = git apply scan" \ - 'git apply patch1.patch patch2.patch patch3.patch patch4.patch patch5.patch' -mv new.txt apply.txt - -test_expect_success "S = patch scan" \ - 'cat patch1.patch patch2.patch patch3.patch patch4.patch patch5.patch | patch' -mv new.txt patch.txt - -test_expect_success "S = cmp" \ - 'cmp apply.txt patch.txt' +test_expect_success 'git apply scan' ' + git apply \ + "$TEST_DIRECTORY/t4110/patch1.patch" \ + "$TEST_DIRECTORY/t4110/patch2.patch" \ + "$TEST_DIRECTORY/t4110/patch3.patch" \ + "$TEST_DIRECTORY/t4110/patch4.patch" \ + "$TEST_DIRECTORY/t4110/patch5.patch" && + test_cmp new.txt "$TEST_DIRECTORY/t4110/expect" +' test_done diff --git a/t/t4110/expect b/t/t4110/expect new file mode 100644 index 000000000..87cc493ec --- /dev/null +++ b/t/t4110/expect @@ -0,0 +1,20 @@ +a1 +a11 +a111 +a1111 +b1 +b11 +b111 +b1111 +b2 +b22 +b222 +b2222 +c1 +c11 +c111 +c1111 +c2 +c22 +c222 +c2222 diff --git a/t/t4110/patch1.patch b/t/t4110/patch1.patch new file mode 100644 index 000000000..56139080d --- /dev/null +++ b/t/t4110/patch1.patch @@ -0,0 +1,17 @@ +diff --git a/new.txt b/new.txt +new file mode 100644 +--- /dev/null ++++ b/new.txt +@@ -0,0 +1,12 @@ ++a1 ++a11 ++a111 ++a1111 ++b1 ++b11 ++b111 ++b1111 ++c1 ++c11 ++c111 ++c1111 diff --git a/t/t4110/patch2.patch b/t/t4110/patch2.patch new file mode 100644 index 000000000..04974247e --- /dev/null +++ b/t/t4110/patch2.patch @@ -0,0 +1,11 @@ +diff --git a/new.txt b/new.txt +--- a/new.txt ++++ b/new.txt +@@ -1,7 +1,3 @@ +-a1 +-a11 +-a111 +-a1111 + b1 + b11 + b111 diff --git a/t/t4110/patch3.patch b/t/t4110/patch3.patch new file mode 100644 index 000000000..26bd4427f --- /dev/null +++ b/t/t4110/patch3.patch @@ -0,0 +1,14 @@ +diff --git a/new.txt b/new.txt +--- a/new.txt ++++ b/new.txt +@@ -6,6 +6,10 @@ + b11 + b111 + b1111 ++b2 ++b22 ++b222 ++b2222 + c1 + c11 + c111 diff --git a/t/t4110/patch4.patch b/t/t4110/patch4.patch new file mode 100644 index 000000000..9ffb9c2d7 --- /dev/null +++ b/t/t4110/patch4.patch @@ -0,0 +1,11 @@ +diff --git a/new.txt b/new.txt +--- a/new.txt ++++ b/new.txt +@@ -1,3 +1,7 @@ ++a1 ++a11 ++a111 ++a1111 + b1 + b11 + b111 diff --git a/t/t4110/patch5.patch b/t/t4110/patch5.patch new file mode 100644 index 000000000..c5ac6914f --- /dev/null +++ b/t/t4110/patch5.patch @@ -0,0 +1,11 @@ +diff --git a/new.txt b/new.txt +--- a/new.txt ++++ b/new.txt +@@ -10,3 +10,7 @@ + c11 + c111 + c1111 ++c2 ++c22 ++c222 ++c2222 -- 2.30.2