git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Hacks for AIX

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 20, 2008, 08:33 UTC
Message-ID
<7vd4l9c5ud.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7v3am9sn2p.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 6 quoted lines
>>     * /usr/bin/patch - really old version, doesn't do well with some
>> diff formats.   I avoid using it.
>
> t4109 seems to use patch to produce expected output for the tests; we
> should ship a precomputed expected results.  Do you know of any other
> places "patch" is used?

As usual, I won't commit this patch unless I hear from people who potentially would benefit from it. I do not need such a patch myself and I really shouldn't be spending too much of my time on these.

-- >8 -- [PATCH] do not rely on external "patch" in tests

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 <gitster@pobox.com>
---
 t/t4109-apply-multifrag.sh |  119 +++++++++++++++++++++++++++++++++++---------
 t/t4110-apply-scan.sh      |   35 ++++++++++---
 2 files changed, 123 insertions(+), 31 deletions(-)
diff --git a/t/t4109-apply-multifrag.sh b/t/t4109-apply-multifrag.sh
index bd40a21..4805863 100755
--- a/t/t4109-apply-multifrag.sh
+++ b/t/t4109-apply-multifrag.sh
@@ -138,39 +138,112 @@ diff --git a/main.c b/main.c
  
 EOF
 
-test_expect_success "S = git apply (1)" \
-    'git apply patch1.patch patch2.patch'
-mv main.c main.c.git
+cat >expect_1 <<\EOF
+#include <stdlib.h>
+#include <stdio.h>
 
-test_expect_success "S = patch (1)" \
-    'cat patch1.patch patch2.patch | patch -p1'
+int func(int num);
+void print_int(int num);
+void print_ln();
 
-test_expect_success "S = cmp (1)" \
-    'cmp main.c.git main.c'
+int main() {
+	int i;
 
-rm -f main.c main.c.git
+	for (i = 0; i < 10; i++) {
+		print_int(func(i));
+	}
 
-test_expect_success "S = git apply (2)" \
-    'git apply patch1.patch patch2.patch patch3.patch'
-mv main.c main.c.git
+	print_ln();
 
-test_expect_success "S = patch (2)" \
-    'cat patch1.patch patch2.patch patch3.patch | patch -p1'
+	return 0;
+}
 
-test_expect_success "S = cmp (2)" \
-    'cmp main.c.git main.c'
+int func(int num) {
+	return num * num;
+}
 
-rm -f main.c main.c.git
+void print_int(int num) {
+	printf("%d", num);
+}
 
-test_expect_success "S = git apply (3)" \
-    'git apply patch1.patch patch4.patch'
-mv main.c main.c.git
+void print_ln() {
+	printf("\n");
+}
 
-test_expect_success "S = patch (3)" \
-    'cat patch1.patch patch4.patch | patch -p1'
+EOF
+
+test_expect_success 'git apply (1)' '
+	git apply patch1.patch patch2.patch &&
+	mv main.c actual &&
+	test_cmp expect_1 actual
+'
+
+cat >expect_2 <<\EOF
+#include <stdio.h>
+
+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);
+}
+
+EOF
 
-test_expect_success "S = cmp (3)" \
-    'cmp main.c.git main.c'
+test_expect_success 'git apply (2)' '
+	rm -f main.c &&
+	git apply patch1.patch patch2.patch patch3.patch &&
+	mv main.c actual &&
+	test_cmp expect_2 actual
+'
+
+cat >expect_3 <<\EOF
+#include <stdio.h>
+
+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;
+}
+
+EOF
+
+test_expect_success 'git apply (3)' '
+	rm -f main.c &&
+	git apply patch1.patch patch4.patch &&
+	mv main.c actual &&
+	test_cmp expect_3 actual
+'
 
 test_done
 
diff --git a/t/t4110-apply-scan.sh b/t/t4110-apply-scan.sh
index db60652..ae300ca 100755
--- a/t/t4110-apply-scan.sh
+++ b/t/t4110-apply-scan.sh
@@ -86,15 +86,34 @@ diff --git a/new.txt b/new.txt
 +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
+cat >expect <<\EOF
+a1
+a11
+a111
+a1111
+b1
+b11
+b111
+b1111
+b2
+b22
+b222
+b2222
+c1
+c11
+c111
+c1111
+c2
+c22
+c222
+c2222
+EOF
 
-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 'apply series of patches' '
+	git apply patch1.patch patch2.patch patch3.patch patch4.patch patch5.patch &&
+	mv new.txt actual &&
+	test_cmp expect actual
+'
 
 test_done
Previous: Brandon CaseyNext: Brandon Casey
Message 4 of 7 in “Hacks for AIX”
  1. Chris CowanJul 16, 2008
  2. Junio C HamanoJul 16, 2008
  3. Brandon CaseyJul 18, 2008
  4. Junio C HamanoJul 20, 2008
  5. Brandon CaseyJul 21, 2008
  6. Brandon CaseyJul 22, 2008
  7. Linus TorvaldsJul 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.