-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.bat
104 lines (92 loc) · 3.18 KB
/
test.bat
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
@echo off
set ERRORLEVEL=0
echo wurl.vbs unit tests:
echo TEST #1: Download a file
cscript wurl.vbs "http://httpbin.org/robots.txt" >NUL
call :basic_file_tests "1" "robots.txt"
if %ERRORLEVEL% NEQ 0 goto :eof
echo TEST #1: PASS
del /F /Q "robots.txt" 1>NUL 2>&1
echo TEST #2: Download a file to a specific filename
cscript wurl.vbs "http://httpbin.org/user-agent" "user-agent.json" >NUL
call :basic_file_tests "2" "user-agent.json"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "2" "user-agent.json" "user-agent"
if %ERRORLEVEL% NEQ 0 goto :eof
echo TEST #2: PASS
del /F /Q "user-agent.json" 1>NUL 2>&1
echo TEST #3: Support response headers
cscript wurl.vbs "http://httpbin.org/response-headers?wurl=vbs" "response-headers.json" >NUL
call :basic_file_tests "3" "response-headers.json"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "3" "response-headers.json" "wurl"
if %ERRORLEVEL% NEQ 0 goto :eof
echo TEST #3: PASS
del /F /Q "response-headers.json" 1>NUL 2>&1
echo TEST #4: Support no-clobber
cscript wurl.vbs "http://httpbin.org/ip" "httpbin.json" >NUL
call :basic_file_tests "4" "httpbin.json"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "4" "httpbin.json" "origin"
if %ERRORLEVEL% NEQ 0 goto :eof
cscript wurl.vbs "http://httpbin.org/user-agent" "httpbin.json" /NC >NUL
call :basic_file_tests "4" "httpbin.json"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "4" "httpbin.json" "user-agent" "assert-not"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "4" "httpbin.json" "origin"
if %ERRORLEVEL% NEQ 0 goto :eof
echo TEST #4: PASS
del /F /Q "httpbin.json" 1>NUL 2>&1
echo TEST #5: Support supression of prompting
cscript wurl.vbs "http://httpbin.org/ip" "httpbin.json" >NUL
call :basic_file_tests "5" "httpbin.json"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "5" "httpbin.json" "origin"
if %ERRORLEVEL% NEQ 0 goto :eof
cscript wurl.vbs "http://httpbin.org/user-agent" "httpbin.json" /Y >NUL
call :basic_file_tests "5" "httpbin.json"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "5" "httpbin.json" "user-agent"
if %ERRORLEVEL% NEQ 0 goto :eof
call :text_file_tests "5" "httpbin.json" "origin" "assert-not"
if %ERRORLEVEL% NEQ 0 goto :eof
echo TEST #5: PASS
del /F /Q "httpbin.json" 1>NUL 2>&1
echo ALL TESTS PASS
goto :eof
:basic_file_tests
if not exist "%~2" (
echo TEST #%1: FAIL: File "%~2" not created
set ERRORLEVEL=1
goto :eof
)
for /f "usebackq tokens=4 delims= " %%f in (`dir ^| find "%~2"`) do (
if %%f LEQ 0 (
echo TEST #%1: FAIL: File "%~2" is zero-length
set ERRORLEVEL=1
goto :eof
)
)
goto :eof
:text_file_tests
set OUTPUT=
for /f "usebackq tokens=1 delims=: " %%f in (`type "%~2" ^| find "%~3"`) do (
set OUTPUT=%%~f
)
if "%~4" == "assert-not" (
if not "%OUTPUT%" == "" (
echo TEST #%~1: FAIL: File "%~2" is not supposed to contain "%~3"
echo Found: "%OUTPUT%"
set ERRORLEVEL=1
goto :eof
)
) else (
if "%OUTPUT%" == "" (
echo TEST #%~1: FAIL: File "%~2" does not contain "%~3"
set ERRORLEVEL=1
goto :eof
)
)
goto :eof
:eof