blob: ac68a089035c8eeea5aae3bfb1bd9dea15767ba6 [file] [log] [blame]
Denis Vlasenkocee01cf2008-03-24 20:33:47 +00001#!/bin/sh
2# Copyright 2008 by Denys Vlasenko
3# Licensed under GPL v2, see file LICENSE for details.
4
5. testing.sh
6
7# testing "test name" "options" "expected result" "file input" "stdin"
8
9# diff outputs date/time in the header, which should not be analysed
10# NB: sed has tab character in s command!
11TRIM_TAB="sed 's/ .*//'"
12
13testing "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
26testing "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
41testing "diff of stdin, twice" \
42 "diff - -; echo $?; wc -c" \
43 "0\n5\n" \
44 "" \
45 "stdin"
46
47# testing "test name" "options" "expected result" "file input" "stdin"
48
49rm -rf diff1 diff2
50mkdir diff1 diff2 diff2/subdir
51echo qwe >diff1/-
52echo asd >diff2/subdir/-
53testing "diff diff1 diff2/subdir" \
54 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
55"\
56--- diff1/-
57+++ diff2/subdir/-
58@@ -1 +1 @@
59-qwe
60+asd
61" \
62 "" ""
63
64# using directory structure from prev test...
65testing "diff dir dir2/file/-" \
66 "diff -ur diff1 diff2/subdir/- | $TRIM_TAB" \
67"\
68--- diff1/-
69+++ diff2/subdir/-
70@@ -1 +1 @@
71-qwe
72+asd
73" \
74 "" ""
75
76# using directory structure from prev test...
77mkdir diff1/test
78mkfifo diff2/subdir/test
79testing "diff of dir and fifo" \
80 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
81"\
82--- diff1/-
83+++ diff2/subdir/-
84@@ -1 +1 @@
85-qwe
86+asd
87Only in diff2/subdir: test
88" \
89 "" ""
90
91# using directory structure from prev test...
92rmdir diff1/test
93echo >diff1/test
94testing "diff of file and fifo" \
95 "diff -ur diff1 diff2/subdir | $TRIM_TAB" \
96"\
97--- diff1/-
98+++ diff2/subdir/-
99@@ -1 +1 @@
100-qwe
101+asd
102File diff2/subdir/test is not a regular file or directory and was skipped
103" \
104 "" ""
105
106# using directory structure from prev test...
107mkfifo diff1/test2
108testing "diff -rN does not read non-regular files" \
109 "diff -urN diff1 diff2/subdir | $TRIM_TAB" \
110"\
111--- diff1/-
112+++ diff2/subdir/-
113@@ -1 +1 @@
114-qwe
115+asd
116File diff2/subdir/test is not a regular file or directory and was skipped
117File diff1/test2 is not a regular file or directory and was skipped
118" \
119 "" ""
120
121# clean up
122rm -rf diff1 diff2
123
124exit $FAILCOUNT