-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitTest.sh
156 lines (138 loc) · 3.16 KB
/
UnitTest.sh
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#/bin/bash
#
# unit test for cpXmlCmd
# Author: Jay Sprenkle
#
# create a temp directory. Remove everything when the script completes
MYTMPDIR=tmp
mkdir $MYTMPDIR
trap "rm -rf $MYTMPDIR" EXIT
#
# where is the binary?
#
cpXmlCmd=dist/Release/MinGW-Windows/cpXmlCmd.exe
#
# nothing on command line, should fail
#
echo Begin negative parameters test
$cpXmlCmd 2>$MYTMPDIR/null
rc=$?
if [ "$rc" != "2" ]
then
exit 2
fi
#
# happy path
#
echo Begin happy path test
rm two.file 2>one.file
cat >$MYTMPDIR/FilesToCopy.xml <<xyzzy
<ns:cpXmlCmd xmlns:ns="http://www.XmlCommandLine.org/cpXmlCmd/1.0">
<ns:Content>
<ns:cp Source="one.file" Destination="two.file" />
</ns:Content>
</ns:cpXmlCmd>
xyzzy
if [ ! -f $MYTMPDIR/FilesToCopy.xml ]
then
echo "FilesToCopy.xml" does not exist but should
exit 1
fi
rm $MYTMPDIR/outputdocument.xml 2>one.file
$cpXmlCmd -l $MYTMPDIR/outputdocument.xml $MYTMPDIR/FilesToCopy.xml
rc=$?
if [ "$rc" != "0" ]
then
echo cpXmlCmd failed
exit 1
fi
if [ ! -f $MYTMPDIR/outputdocument.xml ]
then
echo "outputdocument.xml" does not exist but should
exit 1
fi
# compare to expected output
# ignore dates and environmental differences
cat >$MYTMPDIR/RemoveDates <<xyzzy
s/<Environment>.*<\/Environment>//g
s/="[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z"//g
xyzzy
sed -f $MYTMPDIR/RemoveDates ExpectedOutput.xml >$MYTMPDIR/file1
sed -f $MYTMPDIR/RemoveDates $MYTMPDIR/outputdocument.xml >$MYTMPDIR/file2
diff $MYTMPDIR/file1 $MYTMPDIR/file2
rc=$?
if [ "$rc" != "0" ]
then
echo Output document does not match the expected output
exit 1
fi
echo " "Output document is correct
if [ ! -f one.file ]
then
echo "one.file" does not exist but should
exit 1
fi
if [ ! -f two.file ]
then
echo "two.file" does not exist but should
exit 1
fi
diff one.file two.file
rc=$?
if [ "$rc" != "0" ]
then
echo the copied file is not identical to the source
exit 1
fi
echo " "operation succeeded
rm two.file
#
# test directory creation on local file system
#
echo Begin directory creation test
rm $MYTMPDIR/x/y/z/two.file 2>one.file
cat >$MYTMPDIR/FilesToCopy.xml <<xyzzy2
<ns:cpXmlCmd xmlns:ns="http://www.XmlCommandLine.org/cpXmlCmd/1.0">
<ns:Content>
<ns:cp Source="one.file" Destination="$MYTMPDIR/x/y/z/two.file" />
</ns:Content>
</ns:cpXmlCmd>
xyzzy2
if [ ! -f $MYTMPDIR/FilesToCopy.xml ]
then
echo "FilesToCopy.xml" does not exist but should
exit 1
fi
rm $MYTMPDIR/outputdocument.xml 2>one.file
$cpXmlCmd -l $MYTMPDIR/outputdocument.xml $MYTMPDIR/FilesToCopy.xml
rc=$?
if [ "$rc" != "0" ]
then
echo cpXmlCmd failed
exit 1
fi
if [ ! -f $MYTMPDIR/outputdocument.xml ]
then
echo "outputdocument.xml" does not exist but should
exit 1
fi
if [ ! -f one.file ]
then
echo "one.file" does not exist but should
exit 1
fi
if [ ! -f $MYTMPDIR/x/y/z/two.file ]
then
echo "x/y/z/two.file" does not exist but should
exit 1
fi
diff one.file $MYTMPDIR/x/y/z/two.file
rc=$?
if [ "$rc" != "0" ]
then
echo the copied file is not identical to the source
exit 1
fi
echo " "operation succeeded
rm $MYTMPDIR/x/y/z/two.file
echo Tests completed