2011-07-07 21 views

cevap

4

Farkında olduğumdan değil, başka bir toplu iş komut dosyasına kolayca yazabilirsiniz. Dize bulunmazsa ve dize yoksa sıfırdan% sıfır değerini% 0 olarak sıfırlayacak ve . Bunu IF ERRORLEVEL 1 goto :fail ile test edebilir ve :fail etiketinden sonra istediğiniz kodu çalıştırabilirsiniz.

Bu tür dizelerin kompakt değerlendirmesini istiyorsanız, || sözdizimi:

call TestBatchScript.cmd > console_output.txt 
findstr /C:"teststring1" console_output.txt || goto :fail 
findstr /C:"teststring2" console_output.txt || goto :fail 
findstr /C:"teststring3" console_output.txt || goto :fail 
findstr /C:"teststring4" console_output.txt || goto :fail 
goto :eof 

:fail 
echo You Suck! 
goto :eof 

Veya, daha da ileri gidip bir dosyaya ben windows toplu birim test için bir kütüphane oluşturduk

call TestBatchScript.cmd > console_output.txt 
set success=1 
for /f "tokens=*" %%a in (teststrings.txt) do findstr /C:"%%a" console_output.txt || call :fail %%a 
if %success% NEQ 1 echo You Suck! 
goto :eof 

:fail 
echo Didn't find string "%*" 
set success=0 
goto :eof 
1

Ben filter tip komutlar için aşağıdaki kullanın: toplu dosya foo.cmd için

oluşturmak aşağıdaki dosyaları:

foo.in.txt:
hello

foo.expected.txt:

foo.test.cmd
merhaba dünya:

@echo off 

echo Testing foo.cmd ^< foo.in.txt ^> foo.out.txt 

call foo.cmd <foo.in.txt> foo.out.txt || exit /b 1 

:: fc compares the output and the expected output files: 
call fc foo.out.txt foo.expected.txt || exit /b 1 

exit /b 0 

Sonra da foo.test.cmd

İlgili konular