mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-11 06:41:50 +00:00
106 lines
4.6 KiB
Bash
Executable File
106 lines
4.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { printf "$@" ; exit 1; }
|
|
|
|
\. ../../../nvm.sh
|
|
\. sharedTestResources/semvers
|
|
|
|
|
|
# POSITIVE TEST CASES
|
|
|
|
|
|
# (TEST SET #1) uses valid TEST_SEMVER's and valid package.json templates
|
|
test_semvers_copy="$VALID_SEMVERS_FOR_PKG_JSON"
|
|
prev_semver=''
|
|
for template_file_name in package_json_templates/_valid_*; do
|
|
while [ -n "$test_semvers_copy" ]; do
|
|
semver=$(echo "$test_semvers_copy" | head -n1)
|
|
test_semvers_copy=$(echo "$test_semvers_copy" | tail -n +2)
|
|
[ -n "$semver" ] || continue
|
|
expectedOutput=$(nvm_trim_and_reduce_whitespace_to_one_space "$semver")
|
|
|
|
if [ "$prev_semver" = "$semver" ]; then
|
|
die "Problem iterating through test_semvers_copy (TEST SET #1). Encountered the same value twice in a row. prev_semver='$prev_semver' semver='$semver'.\n"
|
|
fi
|
|
prev_semver="$semver"
|
|
|
|
pkg_json_contents=$(sed 's/NODE_SEMVER/'"$semver"'/g' "$template_file_name" | tail -n +3)
|
|
actual_output=$(nvm_get_node_from_pkg_json "$pkg_json_contents")
|
|
if [ "$actual_output" != "$expectedOutput" ] || [ -z "$actual_output" ] || [ -z "$pkg_json_contents" ]; then
|
|
die "'nvm_get_node_from_pkg_json' POSITIVE test case failed (TEST SET #1). Expected '$expectedOutput' but got '$actual_output' when given input '$semver' and template '$template_file_name':\n$pkg_json_contents"
|
|
fi
|
|
done
|
|
done
|
|
|
|
|
|
# NEGATIVE TEST CASES
|
|
|
|
|
|
# (TEST SET #2) uses valid TEST_SEMVER's but invalid package.json templates
|
|
test_semvers_copy="$VALID_SEMVERS_FOR_PKG_JSON"
|
|
prev_semver=''
|
|
for template_file_name in package_json_templates/_invalid_*; do
|
|
while [ -n "$test_semvers_copy" ]; do
|
|
semver=$(echo "$test_semvers_copy" | head -n1)
|
|
test_semvers_copy=$(echo "$test_semvers_copy" | tail -n +2)
|
|
[ -n "$semver" ] || continue
|
|
|
|
if [ "$prev_semver" = "$semver" ]; then
|
|
die "Problem iterating through test_semvers_copy (TEST SET #2). Encountered the same value twice in a row. prev_semver='$prev_semver' semver='$semver'.\n"
|
|
fi
|
|
prev_semver="$semver"
|
|
|
|
pkg_json_contents=$(sed 's/NODE_SEMVER/'"$semver"'/g' "$template_file_name" | tail -n +3)
|
|
actual_output=$(nvm_get_node_from_pkg_json "$pkg_json_contents")
|
|
if [ "$actual_output" != "" ] || [ -z "$semver" ] || [ -z "$pkg_json_contents" ]; then
|
|
die "'nvm_get_node_from_pkg_json' NEGATIVE test case failed (TEST SET #2). Expected to get empty string but got '$actual_output' when given input template '$template_file_name':\n$pkg_json_contents"
|
|
fi
|
|
done
|
|
done
|
|
|
|
|
|
# (TEST SET #3) uses invalid TEST_SEMVER's but valid package.json templates
|
|
test_semvers_copy="$INVALID_SEMVERS_FOR_PKG_JSON"
|
|
prev_semver=''
|
|
for template_file_name in package_json_templates/_valid_*; do
|
|
while [ -n "$test_semvers_copy" ]; do
|
|
semver=$(echo "$test_semvers_copy" | head -n1)
|
|
[ -n "$semver" ] || continue
|
|
test_semvers_copy=$(echo "$test_semvers_copy" | tail -n +2)
|
|
|
|
if [ "$prev_semver" = "$semver" ]; then
|
|
die "Problem iterating through test_semvers_copy (TEST SET #3). Encountered the same value twice in a row. prev_semver='$prev_semver' semver='$semver'.\n"
|
|
fi
|
|
prev_semver=$(printf "%s" "$semver")
|
|
|
|
pkg_json_contents=$(sed 's/NODE_SEMVER/'"$semver"'/g' "$template_file_name" | tail -n +3)
|
|
actual_output=$(nvm_get_node_from_pkg_json "$pkg_json_contents")
|
|
if [ "$actual_output" != "" ] || [ -z "$semver" ] || [ -z "$pkg_json_contents" ]; then
|
|
die "'nvm_get_node_from_pkg_json' NEGATIVE test case failed (TEST SET #3). Expected to get empty string but got '$actual_output' when given input template '$template_file_name':\n$pkg_json_contents"
|
|
fi
|
|
done
|
|
done
|
|
|
|
# (TEST SET #4) uses invalid TEST_SEMVER's and invalid package.json templates
|
|
test_semvers_copy="$INVALID_SEMVERS_FOR_PKG_JSON"
|
|
prev_semver=''
|
|
for template_file_name in package_json_templates/_invalid_*; do
|
|
while [ -n "$test_semvers_copy" ]; do
|
|
semver=$(echo "$test_semvers_copy" | head -n1)
|
|
[ -n "$semver" ] || continue
|
|
test_semvers_copy=$(echo "$test_semvers_copy" | tail -n +2)
|
|
|
|
if [ "$prev_semver" = "$semver" ]; then
|
|
die "Problem iterating through test_semvers_copy (TEST SET #4). Encountered the same value twice in a row. prev_semver='$prev_semver' semver='$semver'.\n"
|
|
fi
|
|
prev_semver=$(printf "%s" "$semver")
|
|
|
|
pkg_json_contents=$(sed 's/NODE_SEMVER/'"$semver"'/g' "$template_file_name" | tail -n +3)
|
|
actual_output=$(nvm_get_node_from_pkg_json "$pkg_json_contents")
|
|
if [ "$actual_output" != "" ] || [ -z "$semver" ] || [ -z "$pkg_json_contents" ]; then
|
|
die "'nvm_get_node_from_pkg_json' NEGATIVE test case failed (TEST SET #4). Expected to get empty string but got '$actual_output' when given input template '$template_file_name':\n$pkg_json_contents"
|
|
fi
|
|
done
|
|
done
|
|
|