Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2008 by Denys Vlasenko |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 4 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 5 | . ./testing.sh |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 6 | |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 7 | # testing "test name" "commands" "expected result" "file input" "stdin" |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 8 | |
| 9 | # diff outputs date/time in the header, which should not be analysed |
| 10 | # NB: sed has tab character in s command! |
| 11 | TRIM_TAB="sed 's/ .*//'" |
| 12 | |
| 13 | testing "diff of stdin" \ |
| 14 | "diff -u - input | $TRIM_TAB" \ |
| 15 | "\ |
| 16 | --- - |
| 17 | +++ input |
| 18 | @@ -1 +1,3 @@ |
| 19 | +qwe |
| 20 | asd |
| 21 | +zxc |
| 22 | " \ |
| 23 | "qwe\nasd\nzxc\n" \ |
| 24 | "asd\n" |
| 25 | |
| 26 | testing "diff of stdin, no newline in the file" \ |
| 27 | "diff -u - input | $TRIM_TAB" \ |
| 28 | "\ |
| 29 | --- - |
| 30 | +++ input |
| 31 | @@ -1 +1,3 @@ |
| 32 | +qwe |
| 33 | asd |
| 34 | +zxc |
| 35 | \\ No newline at end of file |
| 36 | " \ |
| 37 | "qwe\nasd\nzxc" \ |
| 38 | "asd\n" |
| 39 | |
| 40 | # we also test that stdin is in fact NOT read |
| 41 | testing "diff of stdin, twice" \ |
Denys Vlasenko | b972f94 | 2010-01-18 01:04:20 +0100 | [diff] [blame] | 42 | 'diff - -; echo $?; wc -c' \ |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 43 | "0\n5\n" \ |
| 44 | "" \ |
| 45 | "stdin" |
| 46 | |
Denys Vlasenko | 39f0172 | 2015-01-11 16:41:54 +0100 | [diff] [blame^] | 47 | testing "diff of empty file against stdin" \ |
| 48 | "diff -u - input | $TRIM_TAB" \ |
| 49 | "\ |
| 50 | --- - |
| 51 | +++ input |
| 52 | @@ -1 +0,0 @@ |
| 53 | -a |
| 54 | " \ |
| 55 | "" \ |
| 56 | "a\n" |
| 57 | |
Matheus Izvekov | 6f99c91 | 2010-01-21 18:58:03 -0200 | [diff] [blame] | 58 | testing "diff of empty file against nonempty one" \ |
| 59 | "diff -u - input | $TRIM_TAB" \ |
| 60 | "\ |
| 61 | --- - |
| 62 | +++ input |
| 63 | @@ -0,0 +1 @@ |
| 64 | +a |
| 65 | " \ |
| 66 | "a\n" \ |
| 67 | "" |
| 68 | |
Denys Vlasenko | b972f94 | 2010-01-18 01:04:20 +0100 | [diff] [blame] | 69 | testing "diff -b treats EOF as whitespace" \ |
| 70 | 'diff -ub - input; echo $?' \ |
| 71 | "0\n" \ |
| 72 | "abc" \ |
| 73 | "abc " |
| 74 | |
Denys Vlasenko | b972f94 | 2010-01-18 01:04:20 +0100 | [diff] [blame] | 75 | testing "diff -b treats all spaces as equal" \ |
| 76 | 'diff -ub - input; echo $?' \ |
| 77 | "0\n" \ |
| 78 | "a \t c\n" \ |
| 79 | "a\t \tc\n" |
| 80 | |
Matheus Izvekov | 6f99c91 | 2010-01-21 18:58:03 -0200 | [diff] [blame] | 81 | testing "diff -B ignores changes whose lines are all blank" \ |
| 82 | 'diff -uB - input; echo $?' \ |
| 83 | "0\n" \ |
| 84 | "a\n" \ |
| 85 | "\na\n\n" |
| 86 | |
| 87 | testing "diff -B does not ignore changes whose lines are not all blank" \ |
| 88 | "diff -uB - input | $TRIM_TAB" \ |
| 89 | "\ |
| 90 | --- - |
| 91 | +++ input |
| 92 | @@ -1,3 +1 @@ |
| 93 | - |
| 94 | -b |
| 95 | - |
| 96 | +a |
| 97 | " \ |
| 98 | "a\n" \ |
| 99 | "\nb\n\n" |
| 100 | |
Denys Vlasenko | b972f94 | 2010-01-18 01:04:20 +0100 | [diff] [blame] | 101 | testing "diff always takes context from old file" \ |
| 102 | "diff -ub - input | $TRIM_TAB" \ |
| 103 | "\ |
| 104 | --- - |
| 105 | +++ input |
| 106 | @@ -1 +1,3 @@ |
| 107 | +abc |
| 108 | a c |
| 109 | +def |
| 110 | " \ |
| 111 | "abc\na c\ndef\n" \ |
| 112 | "a c\n" |
| 113 | |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 114 | # testing "test name" "commands" "expected result" "file input" "stdin" |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 115 | |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 116 | # clean up |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 117 | rm -rf diff1 diff2 |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 118 | |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 119 | mkdir diff1 diff2 diff2/subdir |
| 120 | echo qwe >diff1/- |
| 121 | echo asd >diff2/subdir/- |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 122 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 123 | testing "diff diff1 diff2/subdir" \ |
| 124 | "diff -ur diff1 diff2/subdir | $TRIM_TAB" \ |
| 125 | "\ |
| 126 | --- diff1/- |
| 127 | +++ diff2/subdir/- |
| 128 | @@ -1 +1 @@ |
| 129 | -qwe |
| 130 | +asd |
| 131 | " \ |
| 132 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 133 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 134 | |
| 135 | # using directory structure from prev test... |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 136 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 137 | testing "diff dir dir2/file/-" \ |
| 138 | "diff -ur diff1 diff2/subdir/- | $TRIM_TAB" \ |
| 139 | "\ |
| 140 | --- diff1/- |
| 141 | +++ diff2/subdir/- |
| 142 | @@ -1 +1 @@ |
| 143 | -qwe |
| 144 | +asd |
| 145 | " \ |
| 146 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 147 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 148 | |
| 149 | # using directory structure from prev test... |
| 150 | mkdir diff1/test |
| 151 | mkfifo diff2/subdir/test |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 152 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 153 | testing "diff of dir and fifo" \ |
| 154 | "diff -ur diff1 diff2/subdir | $TRIM_TAB" \ |
| 155 | "\ |
| 156 | --- diff1/- |
| 157 | +++ diff2/subdir/- |
| 158 | @@ -1 +1 @@ |
| 159 | -qwe |
| 160 | +asd |
| 161 | Only in diff2/subdir: test |
| 162 | " \ |
| 163 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 164 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 165 | |
| 166 | # using directory structure from prev test... |
| 167 | rmdir diff1/test |
| 168 | echo >diff1/test |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 169 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 170 | testing "diff of file and fifo" \ |
| 171 | "diff -ur diff1 diff2/subdir | $TRIM_TAB" \ |
| 172 | "\ |
| 173 | --- diff1/- |
| 174 | +++ diff2/subdir/- |
| 175 | @@ -1 +1 @@ |
| 176 | -qwe |
| 177 | +asd |
| 178 | File diff2/subdir/test is not a regular file or directory and was skipped |
| 179 | " \ |
| 180 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 181 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 182 | |
| 183 | # using directory structure from prev test... |
| 184 | mkfifo diff1/test2 |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 185 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 186 | testing "diff -rN does not read non-regular files" \ |
| 187 | "diff -urN diff1 diff2/subdir | $TRIM_TAB" \ |
| 188 | "\ |
| 189 | --- diff1/- |
| 190 | +++ diff2/subdir/- |
| 191 | @@ -1 +1 @@ |
| 192 | -qwe |
| 193 | +asd |
| 194 | File diff2/subdir/test is not a regular file or directory and was skipped |
| 195 | File diff1/test2 is not a regular file or directory and was skipped |
| 196 | " \ |
| 197 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 198 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 199 | |
| 200 | # clean up |
| 201 | rm -rf diff1 diff2 |
| 202 | |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 203 | # NOT using directory structure from prev test... |
| 204 | mkdir diff1 diff2 |
| 205 | echo qwe >diff1/- |
| 206 | echo rty >diff2/- |
| 207 | optional FEATURE_DIFF_DIR |
| 208 | testing "diff diff1 diff2/" \ |
| 209 | "diff -ur diff1 diff2/ | $TRIM_TAB; diff -ur .///diff1 diff2//// | $TRIM_TAB" \ |
| 210 | "\ |
| 211 | --- diff1/- |
| 212 | +++ diff2/- |
| 213 | @@ -1 +1 @@ |
| 214 | -qwe |
| 215 | +rty |
| 216 | --- .///diff1/- |
| 217 | +++ diff2////- |
| 218 | @@ -1 +1 @@ |
| 219 | -qwe |
| 220 | +rty |
| 221 | " \ |
| 222 | "" "" |
| 223 | SKIP= |
| 224 | |
| 225 | # clean up |
| 226 | rm -rf diff1 diff2 |
| 227 | |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 228 | exit $FAILCOUNT |