-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bat
More file actions
129 lines (114 loc) · 4.57 KB
/
Copy pathtest.bat
File metadata and controls
129 lines (114 loc) · 4.57 KB
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
@echo off
REM ─────────────────────────────────────────────────────────────
REM test.bat - run tests for runner.bat
REM Usage: test.bat
REM ─────────────────────────────────────────────────────────────
setlocal EnableDelayedExpansion
set "RUNNER=runner.bat"
set "PASS=0"
set "FAIL=0"
REM ── Test: successful run exits 0 ──────────────────────────────
call %RUNNER% examples\HelloWorld.java >"%TEMP%\runner_out.txt" 2>&1
if !ERRORLEVEL! EQU 0 (
call :pass "successful run exits 0"
) else (
call :fail "successful run exits 0"
)
REM ── Test: successful run prints expected output ───────────────
findstr /C:"Hello, World" "%TEMP%\runner_out.txt" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
call :pass "successful run prints expected output"
) else (
call :fail "successful run prints expected output"
)
REM ── Test: successful run shows elapsed time ───────────────────
findstr /R "Finished in [0-9]*ms" "%TEMP%\runner_out.txt" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
call :pass "successful run shows elapsed time"
) else (
call :fail "successful run shows elapsed time"
)
REM ── Test: compile error exits non-zero ────────────────────────
call %RUNNER% tests\CompileError.java >nul 2>&1
if !ERRORLEVEL! NEQ 0 (
call :pass "compile error exits non-zero"
) else (
call :fail "compile error exits non-zero"
)
REM ── Test: compile error prints 'Compilation failed' ──────────
call %RUNNER% tests\CompileError.java >"%TEMP%\runner_out.txt" 2>&1
findstr /C:"Compilation failed" "%TEMP%\runner_out.txt" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
call :pass "compile error prints 'Compilation failed'"
) else (
call :fail "compile error prints 'Compilation failed'"
)
REM ── Test: runtime error exits non-zero ────────────────────────
call %RUNNER% tests\RuntimeError.java >nul 2>&1
if !ERRORLEVEL! NEQ 0 (
call :pass "runtime error exits non-zero"
) else (
call :fail "runtime error exits non-zero"
)
REM ── Test: runtime error shows exit code in output ────────────
call %RUNNER% tests\RuntimeError.java >"%TEMP%\runner_out.txt" 2>&1
findstr /C:"exit code" "%TEMP%\runner_out.txt" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
call :pass "runtime error shows exit code in output"
) else (
call :fail "runtime error shows exit code in output"
)
REM ── Test: missing file exits non-zero ─────────────────────────
call %RUNNER% tests\DoesNotExist.java >nul 2>&1
if !ERRORLEVEL! NEQ 0 (
call :pass "missing file exits non-zero"
) else (
call :fail "missing file exits non-zero"
)
REM ── Test: auto-detect single file in directory ────────────────
set "TMPDIR=%TEMP%\java-runner-test-%RANDOM%"
mkdir "%TMPDIR%"
copy examples\HelloWorld.java "%TMPDIR%\" >nul
pushd "%TMPDIR%"
call "%~dp0%RUNNER%" >"%TEMP%\runner_out.txt" 2>&1
set "AUTODETECT_EXIT=!ERRORLEVEL!"
popd
rmdir /s /q "%TMPDIR%"
if !AUTODETECT_EXIT! EQU 0 (
call :pass "auto-detect single file in directory exits 0"
) else (
call :fail "auto-detect single file in directory exits 0"
)
findstr /C:"Hello, World" "%TEMP%\runner_out.txt" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
call :pass "auto-detect single file produces correct output"
) else (
call :fail "auto-detect single file produces correct output"
)
REM ── Test: auto-detect falls back to examples\ ─────────────────
set "TMPDIR=%TEMP%\java-runner-test-%RANDOM%"
mkdir "%TMPDIR%"
mkdir "%TMPDIR%\examples"
copy examples\HelloWorld.java "%TMPDIR%\examples\" >nul
pushd "%TMPDIR%"
call "%~dp0%RUNNER%" >nul 2>&1
set "FALLBACK_EXIT=!ERRORLEVEL!"
popd
rmdir /s /q "%TMPDIR%"
if !FALLBACK_EXIT! EQU 0 (
call :pass "auto-detect falls back to examples\ exits 0"
) else (
call :fail "auto-detect falls back to examples\ exits 0"
)
REM ── Summary ───────────────────────────────────────────────────
echo.
echo Results: !PASS! passed, !FAIL! failed
if !FAIL! EQU 0 (exit /b 0) else (exit /b 1)
:pass
echo [PASS] %~1
set /a PASS+=1
exit /b
:fail
echo [FAIL] %~1
set /a FAIL+=1
exit /b