Skip to content

Instantly share code, notes, and snippets.

@alanstevens
Last active November 13, 2019 22:38
Show Gist options
  • Save alanstevens/fa96b1a8956819b6b19b6912ead6e8e3 to your computer and use it in GitHub Desktop.
Save alanstevens/fa96b1a8956819b6b19b6912ead6e8e3 to your computer and use it in GitHub Desktop.
RunTests.cmd
@echo off
setlocal enableextensions
set SCRIPT=%0
set DQUOTE="
set OLDDIR=%CD%
set start=%time%
:: Detect how script was launched
@echo %SCRIPT:~0,1% | findstr /l %DQUOTE% > NUL
if %ERRORLEVEL% EQU 0 set PAUSE_ON_CLOSE=1
:: Change to the directory containing the script
cd /d %0\..
:: Update the database
call NewScriptRunner.bat
IF %ERRORLEVEL% NEQ 0 goto ON_ERROR
:: Find MSBuild
SET PATH=%PATH%;%ProgramFiles(x86)%\Microsoft Visual Studio\Installer
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set InstallDir=%%i
)
if exist "%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" (
:: Build the solution
"%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe" PremierBankcard.NextGen.sln /t:Rebuild /p:Configuration=Debug
)
IF %ERRORLEVEL% NEQ 0 goto ON_ERROR
:: Run the tests
PremierBankcard.NextGen.ExternalLibraries\NUnit.Console\nunit3-console.exe PremierBankcard.NextGen.UnitTests\bin\Debug\PremierBankcard.NextGen.UnitTests.dll PremierBankcard.NextGen.IntegrationTests\bin\Debug\PremierBankcard.NextGen.IntegrationTests.dll --labels=All --x86
goto FINISH
:ON_ERROR
echo There was a problem. Please check console output for more detail.
goto FINISH
:FINISH
:: Do messy time calculations
set end=%time%
set options="tokens=1-4 delims=:.,"
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
echo.
echo The command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total) to execute.
echo.
:: Return to the original directory
cd /d %OLDDIR%
:: Keep the window open if launched from explorer
if defined PAUSE_ON_CLOSE pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment