if exist "./snapshots/!filename!.txt"
为真,因此进入子句,
但 fc
(和其他命令)无论如何都找不到该文件,打印出:
FC: cannot open ./SNAPSHOTS/*filename*.TXT - No such file or folder
@echo off
setlocal enabledelayedexpansion
set passed=0
set failed=0
set nosnaps=0
for %%i in (./tests/*) do (
set "filename=%%~ni"
dune exec ../_build/default/bin/main.exe ./tests/%%i > "./results/!filename!.txt" 2> nul
if exist "./snapshots/!filename!.txt" (
fc "./snapshots/!filename!.txt" "./results/!filename!.txt" > nul
if !errorlevel! == 0 (
echo PASSED TEST: !filename!
set /a passed+=1
) else (
echo FAILED TEST: !filename!
set /a failed+=1
)
) else (
echo NOSNAP TEST: !filename!
set /a nosnaps+=1
)
)
echo --------
echo PASSED: !passed!
echo FAILED: !failed!
echo NOSNAP: !nosnaps!
endlocal
虽然这可能无法解决您的问题,但它使用正确的语法。它还不会不必要地使用延迟扩展,或定义和使用不必要的变量。
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set /A passed=failed=nosnaps=0
For %%G In ("tests\*") Do (
dune.exe exec ../_build/default/bin/main.exe "./tests/%%G" 1>"results\%%~nG.txt" 2>NUL
If Exist "snapshots\%%~nG.txt" (
%SystemRoot%\System32\fc.exe "snapshots/%%~nG.txt" "results\%%~nG.txt" 1>NUL && (
Echo PASSED TEST: %%~nG
Set /A passed += 1
) || (
Echo FAILED TEST: %%~nG
Set /A failed += 1
)
) Else (
Echo NOSNAP TEST: %%~nG
Set /A nosnaps += 1
)
)
Echo --------
Echo PASSED: %passed%
Echo FAILED: %failed%
Echo NOSNAP: %nosnaps%
EndLocal
如果
"./tests/%%G"
.exe 不是为 Windows 操作系统引用语法设计的,您可能需要将 './tests/%%G'
更改为 dune
。