Skip to content

Instantly share code, notes, and snippets.

@mgulyaev
Last active December 9, 2015 17:28
Show Gist options
  • Save mgulyaev/4303658 to your computer and use it in GitHub Desktop.
Save mgulyaev/4303658 to your computer and use it in GitHub Desktop.
Universal simple tester that I use in some projects
@echo off
setlocal EnableDelayedExpansion
goto main
:writeHelp
echo UTester (Universal tester)
echo runs given command for all .in files from given testDir
echo and compares the result with the correct answer (same-name .out file)
echo Usage: utester.bat inputMode testDir command
echo Input mode:
echo -s: standart output
echo -a: as argument
echo Example: utester.bat -a Tests ACCompiler
exit /b 0
:main
for /f "tokens=2*" %%i in ("%*") do set command=%%j
set testDir=%~f2
set inputMode=--
if "%1"=="-s" set inputMode=^<
if "%1" == "-a" set inputMode=
if "%inputMode%" == "--" goto writeHelp
if "%testDir%" == "" goto writeHelp
if "%command%" == "" goto writeHelp
set testNum=0
set okNum=0
set out=%TMP%\output.txt
for /r %testDir% %%i in (*.in) do (
%command% %inputMode% %%~fi > %out%
set testName=test "%%~ni":
fc %%~dpni.out %out% > nul
if errorLevel == 1 (
echo.
echo !testName! Failed
echo Input:
type %%~fi
echo Expected:
type %%~dpni.out
echo Got:
type %out%
echo.
) else (
echo !testName! OK
set /a okNum += 1
)
set /a testNum += 1
)
echo.
echo Summary: passed %okNum% from %testNum%
del %out%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment