mirror of
https://github.com/levogevo/add-synced-lyrics.git
synced 2026-07-21 21:45:21 +00:00
increase coverage
This commit is contained in:
@@ -39,9 +39,9 @@ bash_dirname() {
|
|||||||
printf '%s\n' "${tmp:-/}"
|
printf '%s\n' "${tmp:-/}"
|
||||||
}
|
}
|
||||||
|
|
||||||
PROGPATH="$(readlink -f "$0")"
|
PROGPATH="$(readlink -f "$0")" || exit 1
|
||||||
PROGDIR="$(bash_dirname "${PROGPATH}")"
|
PROGDIR="$(bash_dirname "${PROGPATH}")" || exit 1
|
||||||
PROGNAME="$(bash_basename "${PROGPATH}")"
|
PROGNAME="$(bash_basename "${PROGPATH}")" || exit 1
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
readonly PROGPATH PROGDIR PROGNAME || exit 1
|
readonly PROGPATH PROGDIR PROGNAME || exit 1
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ dry() {
|
|||||||
# check required utilities for this project
|
# check required utilities for this project
|
||||||
check_required_utils() {
|
check_required_utils() {
|
||||||
local utils=(
|
local utils=(
|
||||||
|
mktemp
|
||||||
|
sort
|
||||||
base64
|
base64
|
||||||
cat
|
cat
|
||||||
ffprobe
|
ffprobe
|
||||||
|
|||||||
+60
-13
@@ -39,20 +39,24 @@ bash_dirname() {
|
|||||||
printf '%s\n' "${tmp:-/}"
|
printf '%s\n' "${tmp:-/}"
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly PROGPATH="$(readlink -f "$0")"
|
PROGPATH="$(readlink -f "$0")" || exit 1
|
||||||
readonly PROGDIR="$(bash_dirname "${PROGPATH}")"
|
PROGDIR="$(bash_dirname "${PROGPATH}")" || exit 1
|
||||||
readonly PROGNAME="$(bash_basename "${PROGPATH}")"
|
PROGNAME="$(bash_basename "${PROGPATH}")" || exit 1
|
||||||
|
readonly PROGPATH PROGDIR PROGNAME || exit 1
|
||||||
|
|
||||||
# to normalize paths
|
# to normalize paths
|
||||||
cd "${PROGDIR}"
|
cd "${PROGDIR}"
|
||||||
|
|
||||||
readonly TEST_DIR="test-dir"
|
readonly TEST_DIR="test-dir"
|
||||||
# lyrics exist for this song
|
# lyrics exist for this song
|
||||||
readonly GOOD_SONG="${TEST_DIR}/back burner.opus"
|
readonly GOOD_SONG="${TEST_DIR}/the cold sun.opus"
|
||||||
readonly GOOD_LYRICS="${GOOD_SONG//.opus/.lrc}"
|
readonly GOOD_LYRICS="${GOOD_SONG//.opus/.lrc}"
|
||||||
|
readonly GOOD_ISRC='TCJPF1733509'
|
||||||
# lyrics do not exist for this song
|
# lyrics do not exist for this song
|
||||||
readonly BAD_SONG="${TEST_DIR}/subdir/avalanche.opus"
|
readonly BAD_SONG="${TEST_DIR}/subdir/avalanche.opus"
|
||||||
readonly BAD_LYRICS="${BAD_SONG//.opus/.lrc}"
|
readonly BAD_LYRICS="${BAD_SONG//.opus/.lrc}"
|
||||||
|
readonly BAD_ISRC='US5261822978'
|
||||||
|
# program to test
|
||||||
readonly PROG="add-synced-lyrics.sh"
|
readonly PROG="add-synced-lyrics.sh"
|
||||||
# coverage
|
# coverage
|
||||||
readonly COVERAGE_DIR="coverage"
|
readonly COVERAGE_DIR="coverage"
|
||||||
@@ -158,28 +162,46 @@ test_determine_inputs_recurse() {
|
|||||||
RECURSE=true test_determine_inputs
|
RECURSE=true test_determine_inputs
|
||||||
}
|
}
|
||||||
|
|
||||||
test_determine_inputs_find() {
|
test_determine_inputs_bash() {
|
||||||
|
# TEST_ADD_BIN guaranteed to be single word
|
||||||
|
# shellcheck disable=SC2206
|
||||||
local utils=(
|
local utils=(
|
||||||
|
mktemp
|
||||||
|
sort
|
||||||
base64
|
base64
|
||||||
cat
|
cat
|
||||||
ffprobe
|
ffprobe
|
||||||
jq
|
jq
|
||||||
librelyrics
|
librelyrics
|
||||||
spotify
|
spotify
|
||||||
|
docker
|
||||||
|
node
|
||||||
|
readlink
|
||||||
|
bash
|
||||||
|
${TEST_ADD_BIN:-}
|
||||||
)
|
)
|
||||||
local path=()
|
|
||||||
for util in "${utils[@]}"; do
|
for util in "${utils[@]}"; do
|
||||||
path+=("$(bash_dirname "$(command -v "${util}")")")
|
test -f "${TEST_DIR}/${util}" && rm "${TEST_DIR}/${util}"
|
||||||
|
ln -s "$(command -v "${util}")" "${TEST_DIR}/${util}"
|
||||||
done
|
done
|
||||||
IFS=':' moddedPath="${path[*]}"
|
|
||||||
PATH="${moddedPath}" \
|
PATH="${TEST_DIR}" \
|
||||||
add-synced-lyrics \
|
add-synced-lyrics \
|
||||||
--dir "${TEST_DIR}" \
|
--dir "${TEST_DIR}" \
|
||||||
--dry-run "$@"
|
--dry-run "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_determine_inputs_bash_recurse() {
|
||||||
|
test_determine_inputs_bash --recurse
|
||||||
|
}
|
||||||
|
|
||||||
|
test_determine_inputs_find() {
|
||||||
|
TEST_ADD_BIN='find' test_determine_inputs_bash
|
||||||
|
}
|
||||||
|
|
||||||
test_determine_inputs_find_recurse() {
|
test_determine_inputs_find_recurse() {
|
||||||
test_determine_inputs_find --recurse
|
TEST_ADD_BIN='find' test_determine_inputs_bash_recurse
|
||||||
}
|
}
|
||||||
|
|
||||||
test_file_dry() {
|
test_file_dry() {
|
||||||
@@ -251,10 +273,31 @@ test_directory_recurse_ignore() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_not_music_file() {
|
||||||
|
local notMusicFile="${TEST_DIR}/dummy.txt"
|
||||||
|
test -f "${notMusicFile}" || touch "${notMusicFile}"
|
||||||
|
|
||||||
|
run_test_cmd \
|
||||||
|
1 \
|
||||||
|
add-synced-lyrics --file "${notMusicFile}"
|
||||||
|
|
||||||
|
[[ "${CMD_OUTPUT}" == *'is not a music file'* ]]
|
||||||
|
}
|
||||||
|
|
||||||
test_missing_utils() {
|
test_missing_utils() {
|
||||||
PATH="$(bash_dirname "$(command -v bash)")" run_test_cmd \
|
test -d "${TEST_DIR}" || setup_test_data
|
||||||
|
|
||||||
|
for bin in bash readlink; do
|
||||||
|
test -f "${TEST_DIR}/${bin}" && rm "${TEST_DIR}/${bin}"
|
||||||
|
ln -s "$(command -v ${bin})" "${TEST_DIR}/${bin}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# chmod +x "${TEST_DIR}/bash"
|
||||||
|
PATH="${TEST_DIR}" run_test_cmd \
|
||||||
1 \
|
1 \
|
||||||
add-synced-lyrics
|
add-synced-lyrics
|
||||||
|
|
||||||
|
[[ "${CMD_OUTPUT}" == *'missing node'* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_test_data() {
|
setup_test_data() {
|
||||||
@@ -269,10 +312,10 @@ setup_test_data() {
|
|||||||
-t 5
|
-t 5
|
||||||
)
|
)
|
||||||
"${ffmpegCmd[@]}" \
|
"${ffmpegCmd[@]}" \
|
||||||
-metadata ISRC=USTN10700139 \
|
-metadata ISRC=${GOOD_ISRC} \
|
||||||
"${GOOD_SONG}"
|
"${GOOD_SONG}"
|
||||||
"${ffmpegCmd[@]}" \
|
"${ffmpegCmd[@]}" \
|
||||||
-metadata ISRC=US5261822978 \
|
-metadata ISRC=${BAD_ISRC} \
|
||||||
"${BAD_SONG}"
|
"${BAD_SONG}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,8 +323,11 @@ TESTS=(
|
|||||||
test_help_option
|
test_help_option
|
||||||
test_determine_inputs
|
test_determine_inputs
|
||||||
test_determine_inputs_recurse
|
test_determine_inputs_recurse
|
||||||
|
test_determine_inputs_bash
|
||||||
|
test_determine_inputs_bash_recurse
|
||||||
test_determine_inputs_find
|
test_determine_inputs_find
|
||||||
test_determine_inputs_find_recurse
|
test_determine_inputs_find_recurse
|
||||||
|
test_not_music_file
|
||||||
test_bad_input
|
test_bad_input
|
||||||
test_directory_dry
|
test_directory_dry
|
||||||
test_directory_recurse_dry
|
test_directory_recurse_dry
|
||||||
@@ -409,4 +455,5 @@ if [[ $# -eq 0 ]]; then
|
|||||||
else
|
else
|
||||||
setup_coverage
|
setup_coverage
|
||||||
"$@"
|
"$@"
|
||||||
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user