Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2008 by Denys Vlasenko |
| 3 | # Licensed under GPL v2, see file LICENSE for details. |
| 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 | |
Matheus Izvekov | 6f99c91 | 2010-01-21 18:58:03 -0200 | [diff] [blame] | 47 | testing "diff of empty file against nonempty one" \ |
| 48 | "diff -u - input | $TRIM_TAB" \ |
| 49 | "\ |
| 50 | --- - |
| 51 | +++ input |
| 52 | @@ -0,0 +1 @@ |
| 53 | +a |
| 54 | " \ |
| 55 | "a\n" \ |
| 56 | "" |
| 57 | |
Denys Vlasenko | b972f94 | 2010-01-18 01:04:20 +0100 | [diff] [blame] | 58 | testing "diff -b treats EOF as whitespace" \ |
| 59 | 'diff -ub - input; echo $?' \ |
| 60 | "0\n" \ |
| 61 | "abc" \ |
| 62 | "abc " |
| 63 | |
Denys Vlasenko | b972f94 | 2010-01-18 01:04:20 +0100 | [diff] [blame] | 64 | testing "diff -b treats all spaces as equal" \ |
| 65 | 'diff -ub - input; echo $?' \ |
| 66 | "0\n" \ |
| 67 | "a \t c\n" \ |
| 68 | "a\t \tc\n" |
| 69 | |
Matheus Izvekov | 6f99c91 | 2010-01-21 18:58:03 -0200 | [diff] [blame] | 70 | testing "diff -B ignores changes whose lines are all blank" \ |
| 71 | 'diff -uB - input; echo $?' \ |
| 72 | "0\n" \ |
| 73 | "a\n" \ |
| 74 | "\na\n\n" |
| 75 | |
| 76 | testing "diff -B does not ignore changes whose lines are not all blank" \ |
| 77 | "diff -uB - input | $TRIM_TAB" \ |
| 78 | "\ |
| 79 | --- - |
| 80 | +++ input |
| 81 | @@ -1,3 +1 @@ |
| 82 | - |
| 83 | -b |
| 84 | - |
| 85 | +a |
| 86 | " \ |
| 87 | "a\n" \ |
| 88 | "\nb\n\n" |
| 89 | |
Denys Vlasenko | b972f94 | 2010-01-18 01:04:20 +0100 | [diff] [blame] | 90 | testing "diff always takes context from old file" \ |
| 91 | "diff -ub - input | $TRIM_TAB" \ |
| 92 | "\ |
| 93 | --- - |
| 94 | +++ input |
| 95 | @@ -1 +1,3 @@ |
| 96 | +abc |
| 97 | a c |
| 98 | +def |
| 99 | " \ |
| 100 | "abc\na c\ndef\n" \ |
| 101 | "a c\n" |
| 102 | |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 103 | # testing "test name" "commands" "expected result" "file input" "stdin" |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 104 | |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 105 | # clean up |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 106 | rm -rf diff1 diff2 |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 107 | |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 108 | mkdir diff1 diff2 diff2/subdir |
| 109 | echo qwe >diff1/- |
| 110 | echo asd >diff2/subdir/- |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 111 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 112 | testing "diff diff1 diff2/subdir" \ |
| 113 | "diff -ur diff1 diff2/subdir | $TRIM_TAB" \ |
| 114 | "\ |
| 115 | --- diff1/- |
| 116 | +++ diff2/subdir/- |
| 117 | @@ -1 +1 @@ |
| 118 | -qwe |
| 119 | +asd |
| 120 | " \ |
| 121 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 122 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 123 | |
| 124 | # using directory structure from prev test... |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 125 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 126 | testing "diff dir dir2/file/-" \ |
| 127 | "diff -ur diff1 diff2/subdir/- | $TRIM_TAB" \ |
| 128 | "\ |
| 129 | --- diff1/- |
| 130 | +++ diff2/subdir/- |
| 131 | @@ -1 +1 @@ |
| 132 | -qwe |
| 133 | +asd |
| 134 | " \ |
| 135 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 136 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 137 | |
| 138 | # using directory structure from prev test... |
| 139 | mkdir diff1/test |
| 140 | mkfifo diff2/subdir/test |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 141 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 142 | testing "diff of dir and fifo" \ |
| 143 | "diff -ur diff1 diff2/subdir | $TRIM_TAB" \ |
| 144 | "\ |
| 145 | --- diff1/- |
| 146 | +++ diff2/subdir/- |
| 147 | @@ -1 +1 @@ |
| 148 | -qwe |
| 149 | +asd |
| 150 | Only in diff2/subdir: test |
| 151 | " \ |
| 152 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 153 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 154 | |
| 155 | # using directory structure from prev test... |
| 156 | rmdir diff1/test |
| 157 | echo >diff1/test |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 158 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 159 | testing "diff of file and fifo" \ |
| 160 | "diff -ur diff1 diff2/subdir | $TRIM_TAB" \ |
| 161 | "\ |
| 162 | --- diff1/- |
| 163 | +++ diff2/subdir/- |
| 164 | @@ -1 +1 @@ |
| 165 | -qwe |
| 166 | +asd |
| 167 | File diff2/subdir/test is not a regular file or directory and was skipped |
| 168 | " \ |
| 169 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 170 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 171 | |
| 172 | # using directory structure from prev test... |
| 173 | mkfifo diff1/test2 |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 174 | optional FEATURE_DIFF_DIR |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 175 | testing "diff -rN does not read non-regular files" \ |
| 176 | "diff -urN diff1 diff2/subdir | $TRIM_TAB" \ |
| 177 | "\ |
| 178 | --- diff1/- |
| 179 | +++ diff2/subdir/- |
| 180 | @@ -1 +1 @@ |
| 181 | -qwe |
| 182 | +asd |
| 183 | File diff2/subdir/test is not a regular file or directory and was skipped |
| 184 | File diff1/test2 is not a regular file or directory and was skipped |
| 185 | " \ |
| 186 | "" "" |
Denys Vlasenko | bfa1b2e | 2010-05-11 03:53:57 +0200 | [diff] [blame] | 187 | SKIP= |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 188 | |
| 189 | # clean up |
| 190 | rm -rf diff1 diff2 |
| 191 | |
Matheus Izvekov | 61f5f78 | 2010-07-09 19:40:00 +0200 | [diff] [blame] | 192 | # NOT using directory structure from prev test... |
| 193 | mkdir diff1 diff2 |
| 194 | echo qwe >diff1/- |
| 195 | echo rty >diff2/- |
| 196 | optional FEATURE_DIFF_DIR |
| 197 | testing "diff diff1 diff2/" \ |
| 198 | "diff -ur diff1 diff2/ | $TRIM_TAB; diff -ur .///diff1 diff2//// | $TRIM_TAB" \ |
| 199 | "\ |
| 200 | --- diff1/- |
| 201 | +++ diff2/- |
| 202 | @@ -1 +1 @@ |
| 203 | -qwe |
| 204 | +rty |
| 205 | --- .///diff1/- |
| 206 | +++ diff2////- |
| 207 | @@ -1 +1 @@ |
| 208 | -qwe |
| 209 | +rty |
| 210 | " \ |
| 211 | "" "" |
| 212 | SKIP= |
| 213 | |
| 214 | # clean up |
| 215 | rm -rf diff1 diff2 |
| 216 | |
Denis Vlasenko | cee01cf | 2008-03-24 20:33:47 +0000 | [diff] [blame] | 217 | exit $FAILCOUNT |