echo off
rem *** run this batch file if you suspect mv does not work properly on
rem *** your system
echo This batch file is used to test MV. Run in an empty directory.
echo Make sure path points to MV.
echo ÿ
if %2.==root. goto ok
if %2.==notroot. goto ok
goto noarg
:ok
echo > a
if not exist %1:a goto userr
pause

echo The DOS is
ver

rem *** create files and directories to play with
echo Creating files and sub-directories to test MV
echo > b
echo > c
echo > e
md f
echo > f\x.x
md g
echo > g\y.y

rem *** test #1 - #19 exercise the "front" module

echo test#1 (file rename)
rem *** should not cause any error
mv e d > mv.log
if errorlevel 1 goto err
if exist e goto wrong
if not exist d goto wrong

echo test#2 (sub-directory rename)
rem *** should not cause any error
mv f e > mv.log
if errorlevel 1 goto err
if exist f\x.x goto wrong
if not exist e\x.x goto wrong

echo test#3 (try to rename file to another existing file)
rem *** MV should detect error
mv a b > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#4 (try to move multiple sources to a file name)
rem *** MV should detect error
mv * x. > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if exist x goto wrong

echo test#5 (similar to test#4)
rem *** MV should detect error
mv a b c > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong
if not exist b goto wrong

echo test#6 (try to move multiple source to a name)
rem *** MV should detect error
mv * x > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if exist x goto wrong

echo test#7 (try to move file into non-existing sub-directory)
rem *** MV should detect error
mv a f\. > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#8 (destination path not exist)
rem *** MV should detect error
mv a f\a > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#9 (destination path includes a file)
rem *** MV should detect error
mv a b\c > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#10 (destination specified as sub-directory but exists as a file)
rem *** MV should detect error
mv a b\. > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#11 (destination is ambigious)
rem *** MV should detect error
mv a * > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#12 (similar to test#11)
rem *** MV should detect error
mv a *\. > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#13 (rename file to itself)
rem *** MV should detect error
mv a . > mv.log
if errorlevel 1 goto err
if not exist a goto wrong

echo test#14 (source not exist)
rem *** MV should detect error
mv x y > mv.log
if errorlevel 1 goto err
if exist y goto wrong

echo test#15 (move files and sub-directory into sub-directory)
rem *** no error
mv *. e > mv.log
if errorlevel 1 goto err
if not exist e\a goto wrong
if not exist e\b goto wrong
if not exist e\c goto wrong
if not exist e\d goto wrong
if not exist e\g\y.y goto wrong
if exist a goto wrong
if exist b goto wrong
if exist c goto wrong
if exist d goto wrong
if exist g\y.y goto wrong

echo test#16 (move sub-directory to current directory)
rem *** no error
mv e\g . > mv.log
if errorlevel 1 goto err
if not exist g\y.y goto wrong
if exist e\g\y.y goto wrong

echo test#17 (move one sub-directory into another)
rem *** no error
mv e g > mv.log
if errorlevel 1 goto err
if not exist g\e\a goto wrong
if exist e\a goto wrong

echo test#18 (move file to current directory)
rem *** no error
mv g\e\a .\a > mv.log
if errorlevel 1 goto err
if not exist a goto wrong
if exist g\e\a goto wrong

echo test#19 (multiple sources with one missing source)
mv g\e\a g\e\b g\e\* . > mv.log
if errorlevel 1 goto err
if not exist b goto wrong
if not exist c goto wrong
if not exist d goto wrong

rem *** the following tests exercise the "mv" module

echo test#20 (try to move current directory)
rem *** should cause error
mv . x > mv.log
if errorlevel 2 goto err
rem *** if current directory is root it'll cause errorlevel 1;
if %2==root if not errorlevel 1 goto noerr
rem *** otherwise no errorlevel
if %2==notroot if errorlevel 1 goto err

echo test#21 (try to move parent into child)
rem *** should cause error but no errorlevel
mv g g\e > mv.log
if errorlevel 1 goto err
if not exist g\y.y goto wrong

echo test#22 (similar to test#21)
mv g g\e\egg > mv.log
if errorlevel 1 goto err
if not exist g\y.y goto wrong

echo test#23 (similar to test#21)
mv g g > mv.log
if errorlevel 1 goto err
if not exist g\y.y goto wrong

echo test#24 (try to move parent of current directory)
mv .. g > mv.log
rem *** depending on where you are, you either get
rem *** "sorry, but root directory has no parent" (errorlevel 1) or
rem *** "not moved to preserve current directory" (errorlevel 0) or
rem *** "move root directory? You're joking" (errorlevel 1)
if not exist a goto wrong
if %2==root if not errorlevel 1 goto noerr
rem *** if %2==notroot if errorlevel 1 goto err

rem ** the following tests exercise the "normal" module

echo test#25 (path includes drive letters but no root)
mv %1:a %1:h > mv.log
if errorlevel 1 goto err
if not exist h goto wrong
if exist a goto wrong

echo test#26 (path includes drive letters and root)
mv %1:h %1:\i > mv.log
if errorlevel 1 goto err
if not exist \i goto wrong
if exist h goto wrong

echo test#27 (path has upper case letters)
mv %1:\I A > mv.log
if errorlevel 1 goto err
if not exist a goto wrong
if exist %1:\i goto wrong

echo test#28 (missing sub-directory name before \..)
mv a \\.. > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#29 (sub-directory name too long)
mv a aaaaaaaaaaaaaaaaaaaaa > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#30 (referencing root's parent)
mv a \.. > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#31 (.. not preceded by \)
mv a .... > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist a goto wrong

echo test#32 (source is "*\a\..")
rem *** this is equal to mv g g which won't be performed
mv *\a\.. g > mv.log
if errorlevel 1 goto err
if not exist a goto wrong
if not exist g\y.y goto wrong

echo test#33 (no \ before .)
mv %1:\g:.\y.y . > mv.log
if errorlevel 2 goto err
if not errorlevel 1 goto noerr
if not exist g\y.y goto wrong
if exist y.y goto wrong

echo MV passed all tests! Note the tests in here are not exhaustive.
echo Now removing test files created awhile ago...
del g\e\x.x > nul
rd g\e > nul
del g\y.y > nul
rd g > nul
del a > nul
del b > nul
del c > nul
del d > nul
del mv.log > nul
goto dos

rem *** error handling routines
:err
echo MV reported an error that shouldn't happen:
goto abort

:noerr
echo MV failed to detect an error and did this:
goto abort

:wrong
echo MV performed an operation incorrectly:
goto abort

:abort
type mv.log
echo Please report this problem to the author (type MV without parameters
echo to get the author's email address).
goto dos

:userr
del a
echo You have entered the incorrect parameters to testmv.

:noarg
echo Usage: testmv [drv] [where]
echo ÿ
echo   [drv] is the drive letter of the drive you're running testmv on (e.g
echo	  "A"). No quote, no colon.
echo ÿ
echo   [where] is
echo	  "root" if you're running testmv in a root directory
echo	  "notroot" if you're running testmv in a sub-directory
goto dos

:dos
