-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cmd
274 lines (220 loc) · 8.93 KB
/
test.cmd
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
@echo off & setlocal
:: =================================================================================================
:: Acceptance testing for `timeprint`. Note that to properly pass % characters, they must be escaped
:: (sometimes twice).
::
:: NOTE: This test requires the `diff` tool to be on your path.
::
:: Usage: test [release|debug]
::
:: By default, tests the release build.
::
:: =================================================================================================
set testOut=out
:: This script sets up runtime parameters and then calls itself with the `--run` argument to capture
:: test output and report results. You can find the :runTests label after the equals line below.
if "%1" equ "run" goto :runTests
if not exist %testOut% mkdir %testOut%
set testScript=%0
set interactive=1
if "%1" equ "--non-interactive" (
set interactive=0
shift
)
if "%1" equ "release" (
set buildConfig=release
) else if "%1" equ "" (
set buildConfig=release
) else if "%1" equ "debug" (
set buildConfig=debug
) else (
echo 1>&2ERROR: Invalid build configuation ^(%1^). Expected "release" or "debug".
exit /b 1
)
if %buildConfig% equ release (
call cmake --build build --config release
set timePrint=build\Release\timeprint.exe
) else (
call cmake --build build --config debug
set timePrint=build\Debug\timeprint.exe
)
echo.
echo Testing %timePrint%.
if not exist %timePrint% (
echo ERROR: Executable %timePrint% not found. 1>&2
exit /b 1
)
call %testScript% run %timePrint% > %testOut%\tests-output.txt
diff -u3 tests-accepted.txt %testOut%\tests-output.txt | more
diff -u3 --brief tests-accepted.txt %testOut%\tests-output.txt
if %errorlevel% equ 0 (
echo PASS: All output matches.
goto :pass
)
echo.
if %interactive% equ 0 (
echo FAIL: Output changed.
goto :fail
)
set /p response="Differences found. Accept new results (yes/no/manual)? "
if /i "%response%" equ "n" goto :failUnaccepted
if /i "%response%" equ "no" goto :failUnaccepted
if /i "%response%" equ "y" goto :failAcceptAll
if /i "%response%" equ "yes" goto :failAcceptAll
if /i "%response%" equ "m" goto :failAcceptManual
if /i "%response%" equ "merge" goto :failAcceptManual
if /i "%response%" equ "manual" goto :failAcceptManual
goto :failUnaccepted
:failAcceptManual
if not defined MERGETOOL (
echo 1>&2ERROR: Cannot merge; environment variable MERGETOOL is not defined.
goto :fail
)
call "%MERGETOOL%" %testOut%\tests-output.txt tests-accepted.txt
goto :pass
:failAcceptAll
copy %testOut%\tests-output.txt tests-accepted.txt
echo PASS: New output accepted entirely.
goto :pass
:failUnaccepted
echo FAIL: Output changed, differences unaccepted.
goto :fail
:fail
echo.
exit /b 1
:pass
echo.
exit /b 0
::==================================================================================================
:runTests
set timePrint=%2
set testNum=1
echo Acceptance Tests for `timeprint`
echo ================================================================================
echo.
echo.--------------------------------------------------------------------------------
echo Test %testNum%: [/?]
%timePrint% /? | findstr -v github.com/hollasch/timeprint
set /a testNum = testNum + 1
call :test --help examples
call :test --help deltaTime
call :test --help FORMATCODES
call :test --help full
call :test -H timeSyntax
call :test -htimezone
call :test /hexamples
set comment="User time format from env var"
set TIMEFORMAT=Test TIMEFORMAT environment variable.
call :test
set TIMEFORMAT=
set comment="User time delta format from env var"
set TIMEFORMAT_DELTA=Test TIMEFORMAT_DELTA environment variable.
call :testDefCode --time 08:00 --time 15:00
call :test --time 08:00 --time 15:00
set comment="Default time delta format"
set TIMEFORMAT_DELTA=
call :testDefCode --time 2000-01-01T00:00:00 --time 2018-11-16T15:57:05
call :test --time 2000-01-01T00:00:00 --time 2018-11-16T15:57:05
call :testCapture general-help --help
call :testEqual general-help -h bogusHelpTopic
call :testEqual general-help -hbogusHelpTopic
call :testEqual general-help --help bogusHelpTopic
call :test --
call :test -
call :test --bogusSwitch
call :errTest -a
call :errTest --access
call :errTest --access someBogusFile
call :errTest -c
call :errTest --creation
call :errTest --creation someBogusFile
call :errTest -m
call :errTest --modification
call :errTest --modification someBogusFile
call :errTest --time
call :errTest --time 12:00 --access file1 --modification file2
call :errTest --now --access file1 --modification file2
call :errTest --access file1 --modification file2 --now
call :errTest --modification file2 --now --time 12:00
call :errTest -z
call :errTest --timezone
call :test A b c d e Hello world f g h i j
call :test "A b c d e Hello world f g h i j"
call :test "A\nB\nC"
call :test "A\tB\tC"
call :testDefCode "A%%%%nB%%%%nC"
call :testDefCode "A%%%%tB%%%%tC"
call :testDefCode Percent sign = %%%%%%%%
call :testDefCode --codeChar $ --time 2000-01-02T03:04:05 $Y $m $d $H $M $S
call :test "A$nB$nC"
call :test "A$tB$tC"
call :test "Dollar sign = $$"
call :test Bogus codes: ($E $f $J $k $K $l $L $N $o $O $P $q $Q $s $v)
call :test Bogus codes: ($_a $_z)
call :test --time 2023-11-01T14:15:11 --timezone UTC-12:34 ($i)
call :test --timezone UTC --time 2000-01-01T00:00:00Z
call :test --timezone UTC --time 2000-01-02T03:04:05+67
call :test --timezone UTC --time 2000-01-02T03:04:05-67:89
call :test --timezone UTC --time 2000-01-02T03:04:05-6789
call :test --timezone UTC --time 2000-01-01T12:00Z "$1a $2a $3a $4a $5a $6a $7a $8a $9a $20a"
call :test --timezone PST+08 --time 2000-01-01T00:00:00Z "$#c $z $Z"
call :test --time 2000-01-01T00:00:00Z --time 2000-01-02T00:00:00Z "$_S"
call :test --time 2000-01-01T00:00:00Z --time 2000-01-02T03:04:05Z "$_Dd $_dH:$_hM:$_mS"
call :test --time 2000-01-01T00:00:00Z --time 2000-01-02T03:04:05Z "$_Dd $_d0H:$_h0M:$_m0S"
call :test --time 2000-01-01T00:00:00Z --time 2000-01-02T03:04:05Z "$_D."
call :test --time 2000-01-01T00:00:00Z --time 2000-01-02T03:04:05Z "$_D.8"
call :test --time 2000-01-01T00:00:00Z --time 2002-05-07T09:07:53Z "$_M.4"
call :test --time 2000-01-01T00:00:00Z --time 2002-05-07T09:07:53Z "$_'|_M.4"
call :test --time 2000-01-01T00:00:00Z --time 2002-05-07T09:07:53Z "$_'0_M.4"
call :test --now --creation timeprint.cpp "$_ (bogus delta time value)"
call :test --now --creation timeprint.cpp "$_y (bogus delta time value)"
call :test --now --creation timeprint.cpp "$_y. (bogus delta time value)"
call :test --now --creation timeprint.cpp "$_yy (bogus delta time value)"
call :test --now --creation timeprint.cpp "$_tt (bogus delta time value)"
call :test --now --creation timeprint.cpp "$_xy (bogus delta time modulo unit type)"
call :test --now --creation timeprint.cpp "$_xt (bogus delta time modulo unit type)"
call :test --now --creation timeprint.cpp "$_xd (bogus delta time modulo unit type)"
call :test --now --creation timeprint.cpp "$_xh (bogus delta time modulo unit type)"
call :test --now --creation timeprint.cpp "$_xm (bogus delta time modulo unit type)"
call :test --now --creation timeprint.cpp "$_'yM.0 (spurious delta time lead character)"
echo.--------------------------------------------------------------------------------
exit /b 0
:test
echo.--------------------------------------------------------------------------------
if defined comment echo %comment%
set comment=
echo [--codeChar $ %*]
%timePrint% --codeChar $ %*
set /a testNum = testNum + 1
goto :eof
:testDefCode
echo.--------------------------------------------------------------------------------
if defined comment echo %comment%
set comment=
echo [%*]
%timePrint% %*
set /a testNum = testNum + 1
goto :eof
:testCapture
%timePrint% %2 %3 %4 %5 %6 %7 %8 %9 > %testOut%\test-output-%1.txt
goto :eof
:testEqual
echo.--------------------------------------------------------------------------------
echo Output [%2 %3 %4 %5 %6 %7 %8 %9] equal to %1
%timePrint% %2 %3 %4 %5 %6 %7 %8 %9 > %testOut%\test-output-%testNum%.txt
fc >nul %testOut%\test-output-%testNum%.txt %testOut%\test-output-%1.txt
if %ERRORLEVEL% equ 0 (
echo Test passed.
) else (
echo Test failed.
)
set /a testNum = testNum + 1
goto :eof
:errTest
echo.--------------------------------------------------------------------------------
echo Error Test [%*]
%timePrint% %* 1>nul 2>%TEMP%\timeprint-test-error-output.txt
type %TEMP%\timeprint-test-error-output.txt
del %TEMP%\timeprint-test-error-output.txt
set /a testNum = testNum + 1
goto :eof