Newer
Older
bash-utils / test / test_bash-utils.sh
#!/bin/bash
########################################################################
## Script   : test_bash-utils.sh
## Name     : bash-utils.sh 単体テスト用スクリプト
## Version  : 1.0
## Usage:
## |This is Test Usage
##
## test-key : test-value

# Load Test Target Script
. ../src/bash-utils.sh


# ----------------------------------------------------------------------
#  getAbsolutePath 単体テスト
#  指定されたファイルの絶対パス取得確認
# ----------------------------------------------------------------------
function test_getAbsolutePath_file()
{
	local BASE_PATH=`pwd | sed "s/\\/test$//"`
	local EXCEPT_PATH="${BASE_PATH}/src/bash-utils.sh"
	local ABSOLUTE_PATH=$(getAbsolutePath ../src/bash-utils.sh)
	assertEquals "getAbsolutePath [ファイルの絶対パス取得]" "${EXCEPT_PATH}" "${ABSOLUTE_PATH}"

}


# ----------------------------------------------------------------------
#  getAbsolutePath 単体テスト
#  指定されたディレクトリの絶対パス取得確認
# ----------------------------------------------------------------------
function test_getAbsolutePath_directory()
{
	local BASE_PATH=`pwd | sed "s/\\/test$//"`
	local EXCEPT_PATH="${BASE_PATH}/src"
	local ABSOLUTE_PATH=$(getAbsolutePath ../src)
	assertEquals "getAbsolutePath [ディレクトリの絶対パス取得]" "${EXCEPT_PATH}" "${ABSOLUTE_PATH}"

}


# ----------------------------------------------------------------------
#  getAbsolutePath 単体テスト
#  存在しないパスの指定
# ----------------------------------------------------------------------
function test_getAbsolutePath_invalid()
{
	getAbsolutePath ../abc/bash-utils.sh > /dev/null 2>&1
	assertFalse $?

}


# ----------------------------------------------------------------------
#  getProperty 単体テスト
#  プロパティ値の取得
# ----------------------------------------------------------------------
function test_getProperty()
{
	VALUE=$(getProperty "test-key")
	assertEquals "getProperty [test-key に対する値取得]" "test-value" "${VALUE}"

}


# ----------------------------------------------------------------------
#  version 単体テスト
#  バージョン情報の取得
# ----------------------------------------------------------------------
function test_version()
{
	VERSION=$(version)
	assertEquals "version [バージョン情報取得]" "test_bash-utils.sh  1.0" "${VERSION}"

}


# ----------------------------------------------------------------------
#  Usage 単体テスト
#  Usage の取得
# ----------------------------------------------------------------------
function test_usage()
{
	USAGE=$(usage)
	assertEquals "usage [usage 取得]" "This is Test Usage" "${USAGE}"

}


# ----------------------------------------------------------------------
#  confirm 単体テスト
#  デフォルト確認
# ----------------------------------------------------------------------
function test_confirm_default()
{
	$(echo "abc" | confirm "test" 1)
	RESULT=$?
	assertEquals "confirm [usage 取得]" "1" "${RESULT}"

}


# ----------------------------------------------------------------------
#  confirm 単体テスト
#  Yes 確認
# ----------------------------------------------------------------------
function test_confirm_yes()
{
	$(echo "Yes" | confirm "test" 0)
	RESULT=$?
	assertEquals "confirm [usage 取得]" "1" "${RESULT}"

	$(echo "yes" | confirm "test" 0)
	RESULT=$?
	assertEquals "confirm [usage 取得]" "1" "${RESULT}"

}


# ----------------------------------------------------------------------
#  confirm 単体テスト
#  No 確認
# ----------------------------------------------------------------------
function test_confirm_no()
{
	$(echo "No" | confirm "test" 0)
	RESULT=$?
	assertEquals "confirm [usage 取得]" "0" "${RESULT}"

	$(echo "no" | confirm "test" 0)
	RESULT=$?
	assertEquals "confirm [usage 取得]" "0" "${RESULT}"

}


# ----------------------------------------------------------------------
#  confirm 単体テスト
#  No 確認
# ----------------------------------------------------------------------
function test_confirm_no()
{
	$(echo "No" | confirm "test" 0)
	RESULT=$?
	assertEquals "confirm [usage 取得]" "0" "${RESULT}"

	$(echo "no" | confirm "test" 0)
	RESULT=$?
	assertEquals "confirm [usage 取得]" "0" "${RESULT}"

}


# ----------------------------------------------------------------------
#  isContains 単体テスト
#  含まれる場合の確認
# ----------------------------------------------------------------------
function test_isContains()
{
	isContains "abc def ghi" "def"
	RESULT=$?
	assertEquals "isContains [含まれるリスト確認]" "1" "${RESULT}"
}


# ----------------------------------------------------------------------
#  isContains 単体テスト
#  含まれない場合の確認
# ----------------------------------------------------------------------
function test_isContains_noContains()
{
	LIST="abc def gef"
	isContains "abc def ghi" "xyz"
	RESULT=$?
	assertEquals "isContains [含まれないリスト確認]" "0" "${RESULT}"
}


# ----------------------------------------------------------------------
#  isContainsRegex 単体テスト
#  含まれる場合の確認
# ----------------------------------------------------------------------
function test_isContainsRegex()
{
	LIST="abc def gef"
	isContainsRegex "abc def ghi" "g.i"
	RESULT=$?
	assertEquals "isContains [含まれるリスト確認]" "1" "${RESULT}"
}


# ----------------------------------------------------------------------
#  isContainsRegex 単体テスト
#  含まれない場合の確認
# ----------------------------------------------------------------------
function test_isContainsRegex_noContains()
{
	LIST="abc def gef"
	isContainsRegex "abc def ghj" "g.i"
	RESULT=$?
	assertEquals "isContains [含まれないリスト確認]" "0" "${RESULT}"
}




function suite()
{
	suite_addTest test_getAbsolutePath_file
	suite_addTest test_getAbsolutePath_directory
	suite_addTest test_getAbsolutePath_invalid
	suite_addTest test_getProperty
	suite_addTest test_version
	suite_addTest test_usage
	suite_addTest test_confirm_default
	suite_addTest test_confirm_yes
	suite_addTest test_confirm_no
	suite_addTest test_isContains
	suite_addTest test_isContains_noContains
	suite_addTest test_isContainsRegex
	suite_addTest test_isContainsRegex_noContains
}

. shunit2