Windows bat: バッチファイルでJUnitのようにテストする

BatUnit
Windowsのバッチファイルで、JUnitのようにテストのサポートをするプログラムです。仕様はプログラム中のコメントに記載しています。

バッチファイル(GitHub)

随時追加しています。

機能一覧

AssertEquals.bat

2つの値(期待値と実際の値)が一致するか検証します。

実行に必要なバッチファイル(GitHub)
実行形式
call AssertEquals.bat テスト名 期待値 検証する値
実行例と結果
call AssertEquals.bat "Test 1" 4 4
Successful Test 1.

call AssertEquals.bat "Test 2" a a
Successful Test 2.

call AssertEquals.bat "Test 1" 4 a
Failed Test 3, Expected=4, Actual=a.

AssertNull.bat

値がNULL(未定義)であるか検証します。

実行に必要なバッチファイル(GitHub)
実行形式
call AssertNull.bat テスト名 検証する値
実行例と結果
set VALUE=
call AssertNull.bat "Test 1" %VALUE%
Successful Test 1.

set VALUE=abc
call AssertNull.bat "Test 2" %VALUE%
Failed Test 2, Actual=abc.

AssertFileExists.bat

ファイルが存在するか検証します。

実行に必要なバッチファイル(GitHub)
実行形式
call AssertFileExists.bat テスト名 検証するファイルパス
実行例と結果
call AssertFileExists.bat "Test 1" "C:¥file.txt"
Successful Test 1.

call AssertFileExists.bat "Test 2" "C:¥not found.txt"
Failed Test 2, File[C:¥not found.txt] is not found.

call AssertFileExists.bat "Test 3" "C:¥directory¥"
Failed Test 3, File[C:¥directory¥] is a directory.

AssertDirectoryExists.bat

フォルダが存在するか検証します。

実行に必要なバッチファイル(GitHub)
実行形式
call AssertDirectoryExists.bat テスト名 検証するファイルパス
実行例と結果
call AssertDirectoryExists.bat "Test 1" "C:¥directory¥"
Successful Test 1.

call AssertDirectoryExists.bat "Test 2" "C:¥not found¥"
Failed Test 2, Directory[C:¥not found¥] is not found.

call AssertDirectoryExists.bat "Test 3" "C:¥file.txt"
Failed Test 3, Directory[C:¥file.txt] is a file.

AssertFileNotExists.bat

ファイルもしくはフォルダが存在しないか検証します。

実行に必要なバッチファイル(GitHub)
実行形式
call AssertFileNotExists.bat テスト名 検証するファイルパス
実行例と結果
call AssertFileNotExists.bat "Test 1" "C:¥not found.txt"
Successful Test 1.

call AssertFileNotExists.bat "Test 2" "C:¥not found¥"
Successful Test 2.

call AssertFileNotExists.bat "Test 3" "C:¥file.txt"
Failed Test 3, File[C:¥file.txt] exists.

call AssertFileNotExists.bat "Test 4" "C:¥directory¥"
Failed Test 4, File[C:¥directory¥] exists.

AssertFileFirstLineEquals.bat

ファイルの先頭行と期待値が一致するか検証します。

実行形式
call AssertFileFirstLineEquals.bat テスト名 期待値 検証するファイルパス
ファイル a.txt
line 1
line 2
line 3
実行例と結果
call AssertFileFirstLineEquals.bat "Test 1" "line 1" "a.txt"
Successful Test 1.

call AssertFileFirstLineEquals.bat "Test 1" "line 2" "a.txt"
Failed Test 2, Expected=line 2, Actual=line 1.