aboutsummaryrefslogtreecommitdiff
path: root/tests/diff.test
blob: ddca4766c988966d30f31ae3b906e02e604a5ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash

#testing "name" "command" "result" "infile" "stdin"

seq 10 > left
seq 11 > right

testcmd "unknown argument" '--oops left right 2>/dev/null ; echo $?' "2\n" "" ""
testcmd "missing" 'missing1 missing2 2>/dev/null ; echo $?' "2\n" "" ""

testcmd "- -" '- - ; echo $?' "0\n" "" "whatever"

testcmd "simple" "-u -L lll -L rrr left right" '--- lll
+++ rrr
@@ -8,3 +8,4 @@
 8
 9
 10
+11
' "" ""

mkdir -p tree1 tree2
echo foo > tree1/file
echo food > tree2/file

# Debian's diff gratuitously echoes its command line with -r. No idea why.
testcmd "-r" "-u -r -L tree1/file -L tree2/file tree1 tree2 | grep -v ^diff" \
  '--- tree1/file
+++ tree2/file
@@ -1 +1 @@
-foo
+food
' "" ""

echo -e "hello\r\nworld\r\n"> a
echo -e "hello\nworld\n"> b
testcmd "--strip-trailing-cr off" "-q a b" "Files a and b differ\n" "" ""
testcmd "--strip-trailing-cr on" '-u --strip-trailing-cr a b; echo $?' \
  "0\n" "" ""

echo -e "1\n2" > aa
echo -e "1\n3" > bb
testcmd "line format" "--unchanged-line-format=U%l --old-line-format=D%l --new-line-format=A%l aa bb" "U1D2A3" "" ""
testcmd "line format empty" "--unchanged-line-format= --old-line-format=D%l --new-line-format=A%l aa bb" "D2A3" "" ""

mkfifo fifo1
mkfifo fifo2
echo -e "1\n2" > fifo1&
echo -e "1\n3" > fifo2&
testcmd "fifos" "-u -L fifo1 -L fifo2 fifo1 fifo2" '--- fifo1
+++ fifo2
@@ -1,2 +1,2 @@
 1
-2
+3
' "" ""

echo -e 'int bar() {
}

int foo() {
}

int baz() {
  1
  {2
  3
  4
  foo
}
'> a
echo -e 'int barbar() {
}

int foo() {
}

int baz() {
  1a
  {2
  3
  4
  bar
}
'> b
testcmd 'show function' "--show-function-line=' {$' -U1 -L lll -L rrr a b" \
'--- lll
+++ rrr
@@ -1,2 +1,2 @@
-int bar() {
+int barbar() {
 }
@@ -7,3 +7,3 @@ int foo() {
 int baz() {
-  1
+  1a
   {2
@@ -11,3 +11,3 @@ int baz() {
   4
-  foo
+  bar
 }
' \
'' ''

seq 1 100000 > one
seq 1 4 100000 > two
testcmd 'big hunk' '-u --label nope --label nope one two' \
  "$(echo -e '--- nope\n+++ nope\n@@ -1,100000 +1,25000 @@'; for((i=1;i<=100000;i++)); do (((i-1)&3)) && echo "-$i" || echo " $i"; done)\n" '' ''
rm one two