• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3#testing "name" "command" "result" "infile" "stdin"
4
5seq 10 > left
6seq 11 > right
7
8testcmd "unknown argument" '--oops left right 2>/dev/null ; echo $?' "2\n" "" ""
9testcmd "missing" 'missing1 missing2 2>/dev/null ; echo $?' "2\n" "" ""
10
11testcmd "- -" '- - ; echo $?' "0\n" "" "whatever"
12
13testcmd "simple" "-u -L lll -L rrr left right" '--- lll
14+++ rrr
15@@ -8,3 +8,4 @@
16 8
17 9
18 10
19+11
20' "" ""
21
22mkdir -p tree1 tree2
23echo foo > tree1/file
24echo food > tree2/file
25
26# Debian's diff gratuitously echoes its command line with -r. No idea why.
27testcmd "-r" "-u -r -L tree1/file -L tree2/file tree1 tree2 | grep -v ^diff" \
28  '--- tree1/file
29+++ tree2/file
30@@ -1 +1 @@
31-foo
32+food
33' "" ""
34
35echo -e "hello\r\nworld\r\n"> a
36echo -e "hello\nworld\n"> b
37testcmd "--strip-trailing-cr off" "-q a b" "Files a and b differ\n" "" ""
38testcmd "--strip-trailing-cr on" '-u --strip-trailing-cr a b; echo $?' \
39  "0\n" "" ""
40
41echo -e "1\n2" > aa
42echo -e "1\n3" > bb
43testcmd "line format" "--unchanged-line-format=U%l --old-line-format=D%l --new-line-format=A%l aa bb" "U1D2A3" "" ""
44testcmd "line format empty" "--unchanged-line-format= --old-line-format=D%l --new-line-format=A%l aa bb" "D2A3" "" ""
45
46mkfifo fifo1
47mkfifo fifo2
48echo -e "1\n2" > fifo1&
49echo -e "1\n3" > fifo2&
50testcmd "fifos" "-u -L fifo1 -L fifo2 fifo1 fifo2" '--- fifo1
51+++ fifo2
52@@ -1,2 +1,2 @@
53 1
54-2
55+3
56' "" ""
57
58echo -e 'int bar() {
59}
60
61int foo() {
62}
63
64int baz() {
65  1
66  {2
67  3
68  4
69  foo
70}
71'> a
72echo -e 'int barbar() {
73}
74
75int foo() {
76}
77
78int baz() {
79  1a
80  {2
81  3
82  4
83  bar
84}
85'> b
86testcmd 'show function' "--show-function-line=' {$' -U1 -L lll -L rrr a b" \
87'--- lll
88+++ rrr
89@@ -1,2 +1,2 @@
90-int bar() {
91+int barbar() {
92 }
93@@ -7,3 +7,3 @@ int foo() {
94 int baz() {
95-  1
96+  1a
97   {2
98@@ -11,3 +11,3 @@ int baz() {
99   4
100-  foo
101+  bar
102 }
103' \
104'' ''
105
106seq 1 100000 > one
107seq 1 4 100000 > two
108testcmd 'big hunk' '-u --label nope --label nope one two' \
109  "$(echo -e '--- nope\n+++ nope\n@@ -1,100000 +1,25000 @@'; for i in $(seq 1 100000); do (((i-1)&3)) && echo "-$i" || echo " $i"; done)\n" '' ''
110rm one two
111