From 8221df2a3f1451abfb675f94b876bfbb3f9f9141 Mon Sep 17 00:00:00 2001 From: edwmurph Date: Thu, 31 May 2018 18:46:54 -0400 Subject: [PATCH] renamed function; minor refactors; added test coverage; identified remaining work --- nvm.sh | 19 +++--- .../Unit tests/nvm_get_node_from_pkg_json | 61 +++++++++++-------- ..._valid_semver => nvm_is_normalized_semver} | 16 ++--- test/fast/Unit tests/nvm_normalize_semver | 50 ++++++++++++++- .../Unit tests/nvm_string_contains_regexp | 31 +++------- ...vm_trim_and_reduce_whitespace_to_one_space | 32 ++++++++-- test/generated_semvers.sh | 10 ++- test/slow/nvm_interpret_node_semver | 8 ++- 8 files changed, 152 insertions(+), 75 deletions(-) rename test/fast/Unit tests/{nvm_is_valid_semver => nvm_is_normalized_semver} (68%) diff --git a/nvm.sh b/nvm.sh index d632f56..6ddac0a 100644 --- a/nvm.sh +++ b/nvm.sh @@ -317,23 +317,18 @@ nvm_string_contains_regexp() { # semver ::= comparator_set ( ' || ' comparator_set )* # comparator_set ::= comparator ( ' ' comparator )* # comparator ::= ( '<' | '<=' | '>' | '>=' | '' ) [0-9]+ '.' [0-9]+ '.' [0-9]+ -nvm_is_valid_semver() { +nvm_is_normalized_semver() { nvm_string_contains_regexp "${1-}" '^( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+( \|\| ( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+)*$' } nvm_trim_and_reduce_whitespace_to_one_space() { command printf '%s' "${1-}" | - command tr -d '\n\r' | - command tr '\t' ' ' | + command tr '\n\r\t\v\b' ' ' | command tr -s ' ' | command sed 's/^ //; s/ $//; s/^ //' } -# Attempts to normalize the given semver to the following grammar: -# -# semver ::= comparator_set ( ' || ' comparator_set )* -# comparator_set ::= comparator ( ' ' comparator )* -# comparator ::= ( '<' | '<=' | '>' | '>=' | '' ) [0-9]+ '.' [0-9]+ '.' [0-9]+ +# Attempts to normalize the given semver to the grammar defined with the function nvm_is_normalized_semver nvm_normalize_semver() { # split the semantic version's comparator_set's onto their own lines for iteration local semver @@ -475,7 +470,7 @@ nvm_normalize_semver() { validated_semver=$(command printf '%s' "$validated_semver" | command sed -E 's/^ \|\| //') - if nvm_is_valid_semver "$validated_semver"; then + if nvm_is_normalized_semver "$validated_semver"; then command printf '%s' "$validated_semver" else return 1 @@ -490,7 +485,7 @@ nvm_interpret_complex_semver() { semver="${1-}" local version_list version_list="${2-}" # expected to be sorted from oldest to newest - if [ -z "$semver" ] || [ -z "$version_list" ] || ! nvm_is_valid_semver "$semver"; then + if [ -z "$semver" ] || [ -z "$version_list" ] || ! nvm_is_normalized_semver "$semver"; then return 1 fi @@ -506,6 +501,7 @@ nvm_interpret_complex_semver() { local current_comparator local stripped_version_from_comparator local highest_compatible_versions + # TODO make this just always store the highest possible compatible version highest_compatible_versions='' while [ -n "$semver" ]; do @@ -521,6 +517,7 @@ nvm_interpret_complex_semver() { current_version=$(command printf '%s' "$version_list_copy" | command tail -n1 | command sed -E 's/^ +//;s/ +$//' | nvm_grep -o '^[0-9]\+\.[0-9]\+\.[0-9]\+$') version_list_copy=$(command printf '%s' "$version_list_copy" | command sed '$d') [ -n "$current_version" ] || continue + # TODO if current_version is less than the highest version in highest_compatile_versions, no need to continue # For each comparator in the current_comparator_set_copy: # - If current_version is compatible with all comparators, we know current_version is the newest compatible version @@ -4078,7 +4075,7 @@ nvm() { nvm_curl_libz_support nvm_command_info \ nvm_get_node_from_pkg_json nvm_find_package_json nvm_package_json_version \ nvm_interpret_node_semver nvm_interpret_simple_semver nvm_interpret_complex_semver nvm_normalize_semver \ - nvm_is_valid_semver nvm_string_contains_regexp nvm_trim_and_reduce_whitespace_to_one_space \ + nvm_is_normalized_semver nvm_string_contains_regexp nvm_trim_and_reduce_whitespace_to_one_space \ > /dev/null 2>&1 unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \ NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \ diff --git a/test/fast/Unit tests/nvm_get_node_from_pkg_json b/test/fast/Unit tests/nvm_get_node_from_pkg_json index 163f293..5f1f3eb 100755 --- a/test/fast/Unit tests/nvm_get_node_from_pkg_json +++ b/test/fast/Unit tests/nvm_get_node_from_pkg_json @@ -8,21 +8,24 @@ # (TEST SET #1) uses valid TEST_SEMVER's and valid package.json templates -test_semvers_copy="$VALID_SEMVERS_FOR_PKG_JSON" +test_cases="$VALID_SEMVERS_FOR_PKG_JSON" +if [ -z "$test_cases" ]; then + die 'TEST SET 1 for nvm_get_node_from_pkg_json given an empty set of test cases' +fi 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) + while [ -n "$test_cases" ]; do + semver=$(echo "$test_cases" | head -n1) + test_cases=$(echo "$test_cases" | 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" + die "Problem iterating through test_cases (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) + 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" @@ -35,20 +38,23 @@ done # (TEST SET #2) uses valid TEST_SEMVER's but invalid package.json templates -test_semvers_copy="$VALID_SEMVERS_FOR_PKG_JSON" +test_cases="$VALID_SEMVERS_FOR_PKG_JSON" +if [ -z "$test_cases" ]; then + die 'TEST SET 2 for nvm_get_node_from_pkg_json given an empty set of test cases' +fi 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) + while [ -n "$test_cases" ]; do + semver=$(echo "$test_cases" | head -n1) + test_cases=$(echo "$test_cases" | 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" + die "Problem iterating through test_cases (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) + 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" @@ -58,20 +64,23 @@ done # (TEST SET #3) uses invalid TEST_SEMVER's but valid package.json templates -test_semvers_copy="$INVALID_SEMVERS_FOR_PKG_JSON" +test_cases="$INVALID_SEMVERS_FOR_PKG_JSON" +if [ -z "$test_cases" ]; then + die 'TEST SET 3 for nvm_get_node_from_pkg_json given an empty set of test cases' +fi 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) + while [ -n "$test_cases" ]; do + semver=$(echo "$test_cases" | head -n1) [ -n "$semver" ] || continue - test_semvers_copy=$(echo "$test_semvers_copy" | tail -n +2) + test_cases=$(echo "$test_cases" | 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" + die "Problem iterating through test_cases (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) + 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" @@ -80,24 +89,28 @@ for template_file_name in package_json_templates/_valid_*; do done # (TEST SET #4) uses invalid TEST_SEMVER's and invalid package.json templates -test_semvers_copy="$INVALID_SEMVERS_FOR_PKG_JSON" +test_cases="$INVALID_SEMVERS_FOR_PKG_JSON" +if [ -z "$test_cases" ]; then + die 'TEST SET 4 for nvm_get_node_from_pkg_json given an empty set of test cases' +fi 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) + while [ -n "$test_cases" ]; do + semver=$(echo "$test_cases" | head -n1) [ -n "$semver" ] || continue - test_semvers_copy=$(echo "$test_semvers_copy" | tail -n +2) + test_cases=$(echo "$test_cases" | 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" + die "Problem iterating through test_cases (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) + 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 +exit 0 diff --git a/test/fast/Unit tests/nvm_is_valid_semver b/test/fast/Unit tests/nvm_is_normalized_semver similarity index 68% rename from test/fast/Unit tests/nvm_is_valid_semver rename to test/fast/Unit tests/nvm_is_normalized_semver index cba9cd1..9e7d0fa 100755 --- a/test/fast/Unit tests/nvm_is_valid_semver +++ b/test/fast/Unit tests/nvm_is_normalized_semver @@ -3,7 +3,7 @@ \. ../../../nvm.sh \. ../../generated_semvers.sh -# nvm_is_valid_semver validates that given semvers adhere to the following grammer +# nvm_is_normalized_semver validates that given semvers adhere to the following grammer # # semver ::= comparator_set ( ' || ' comparator_set )* # comparator_set ::= comparator ( ' ' comparator )* @@ -13,14 +13,14 @@ positive_test_cases="$VALID_NORMALIZED_SEMVERS" if [ -z "$positive_test_cases" ]; then - die "positive test cases are empty" + die 'positive test cases are empty' fi prev_semver='' while [ -n "$positive_test_cases" ]; do semver=$(echo "$positive_test_cases" | head -n1) - if [ -z "$semver" ] || ! nvm_is_valid_semver "$semver"; then - die "nvm_string_contains_regexp POSITIVE test case failed. semver: '$semver'.\n" + if [ -z "$semver" ] || ! nvm_is_normalized_semver "$semver"; then + die "nvm_is_normalized_semver POSITIVE test case failed. semver: '$semver'.\n" fi if [ "$prev_semver" = "$semver" ]; then die "something is wrong. positive test cases received the same test case twice in a row. semver: '$semver'" @@ -31,16 +31,16 @@ done # NEGATIVE TEST CASES -negative_test_cases="$VALID_NON_NORMALIZED_SEMVERS" +negative_test_cases=$(printf "%s\n%s" "$VALID_NON_NORMALIZED_SEMVERS" "$INVALID_SEMVERS_FOR_PKG_JSON") if [ -z "$negative_test_cases" ]; then - die "negative test cases are empty" + die 'negative test cases are empty' fi prev_semver='initialized to non empty string' while [ -n "$negative_test_cases" ]; do semver=$(echo "$negative_test_cases" | head -n1) - if nvm_is_valid_semver "$semver"; then - die "nvm_string_contains_regexp NEGATIVE test case failed. semver: '$semver'.\n" + if nvm_is_normalized_semver "$semver"; then + die "nvm_is_normalized_semver NEGATIVE test case failed. semver: '$semver'.\n" fi if [ "$prev_semver" = "$semver" ]; then die "something is wrong. negative test cases received the same test case twice in a row. semver: '$semver'" diff --git a/test/fast/Unit tests/nvm_normalize_semver b/test/fast/Unit tests/nvm_normalize_semver index 8c7223b..e48b74a 100755 --- a/test/fast/Unit tests/nvm_normalize_semver +++ b/test/fast/Unit tests/nvm_normalize_semver @@ -3,9 +3,36 @@ \. ../../../nvm.sh \. ../../generated_semvers.sh -# TODO add more test cases here -# Some test cases should just test that valid semvers from 'Shared test tesources'/semvers just produce some result +# TEST 1: Validate that for already normalized semvers, nvm_normalize_semver outputs the same semver. +test_cases="$VALID_NORMALIZED_SEMVERS" +if [ -z "$test_cases" ]; then + die 'nvm_normalize_semver (TEST 1) was given an empty set of test cases' +fi +while [ -n "$test_cases" ]; do + semver=$(echo "$test_cases" | head -n1) + actual_output=$(nvm_normalize_semver "$semver") + if [ -z "$semver" ] || [ "$semver" != "$actual_output" ]; then + die "nvm_normalize_semver (TEST 1) test case failed. Expected output: '$semver'. Actual output: '$actual_output'. Input: '$semver'.\n" + fi + test_cases=$(echo "$test_cases" | tail -n +2) +done + +# TEST 2: Validate that non normalized valid semvers produce a normalized result +test_cases="$VALID_NON_NORMALIZED_SEMVERS" +if [ -z "$test_cases" ]; then + die 'nvm_normalize_semver (TEST 2) was given an empty set of test cases' +fi +while [ -n "$test_cases" ]; do + semver=$(echo "$test_cases" | head -n1) + actual_output=$(nvm_normalize_semver "$semver") + if [ -z "$semver" ] || [ -z "$actual_output" ] || [ "$semver" = "$actual_output" ]; then + die "nvm_normalize_semver (TEST 2) test case failed. Expected output: '$semver'. Actual output: '$actual_output'. Input: '$semver'.\n" + fi + test_cases=$(echo "$test_cases" | tail -n +2) +done + +# TEST 3: Validate specific outputs for some specific inputs to nvm_normalize_semver. # input:expected_output test_cases="1.2.3:1.2.3 1.2.3 - 1.2.4:>=1.2.3 <=1.2.4 @@ -42,13 +69,30 @@ a || 1.2.3: ^x.1.1:>0.0.0 11.22.33:11.22.33" +if [ -z "$test_cases" ]; then + die 'nvm_normalize_semver (TEST 3) was given an empty set of test cases' +fi while [ -n "$test_cases" ]; do line=$(echo "$test_cases" | head -n1) input=$(echo "$line" | awk -F: '{ print $1 }') expected_output=$(echo "$line" | awk -F: '{ print $2 }') actual_output=$(nvm_normalize_semver "$input") if [ -z "$input" ] || [ "$actual_output" != "$expected_output" ]; then - die "nvm_normalize_semver test case failed. Expected output: '$expected_output'. Actual output: '$actual_output'. Input: '$input'.\n" + die "nvm_normalize_semver (TEST 3) test case failed. Expected output: '$expected_output'. Actual output: '$actual_output'. Input: '$input'.\n" + fi + test_cases=$(echo "$test_cases" | tail -n +2) +done + +# TEST 4: Validate that invalid semvers with invalid characters that shouldn't be retrieved from the package.json produce no result from nvm_normalize_semver +test_cases="$INVALID_SEMVERS_FOR_PKG_JSON" +if [ -z "$test_cases" ]; then + die 'nvm_normalize_semver (TEST 4) was given an empty set of test cases' +fi +while [ -n "$test_cases" ]; do + semver=$(echo "$test_cases" | head -n1) + actual_output=$(nvm_normalize_semver "$semver") + if [ -z "$semver" ] || [ -n "$actual_output" ]; then + die "nvm_normalize_semver (TEST 4) test case failed. Expected no output but got: '$actual_output'. Input: '$semver'.\n" fi test_cases=$(echo "$test_cases" | tail -n +2) done diff --git a/test/fast/Unit tests/nvm_string_contains_regexp b/test/fast/Unit tests/nvm_string_contains_regexp index a43f30a..495b860 100755 --- a/test/fast/Unit tests/nvm_string_contains_regexp +++ b/test/fast/Unit tests/nvm_string_contains_regexp @@ -1,24 +1,17 @@ #!/bin/sh -die () { printf "$@" ; exit 1; } - \. ../../../nvm.sh +\. ../../generated_semvers.sh -valid_semver_regexp='^( ?(<|<=|>|>=|=|~|\^)?([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x))+$' +normalized_semver_regexp='^( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+( \|\| ( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+)*$' # POSITIVE TEST CASES -# TODO add more test cases -# string:regexp -test_cases="1.2.3:$valid_semver_regexp -11.22.33:$valid_semver_regexp" - +test_cases="$VALID_NORMALIZED_SEMVERS" while [ -n "$test_cases" ]; do - line=$(echo "$test_cases" | head -n1) - string=$(echo "$line" | awk -F: '{ print $1 }') - regexp=$(echo "$line" | awk -F: '{ print $2 }') - if [ -z "$regexp" ] || [ -z "$string" ] || ! nvm_string_contains_regexp "$string" "$regexp"; then - die "nvm_string_contains_regexp POSITIVE test case failed. regexp: '$regexp'. string: '$string'.\n" + string=$(echo "$test_cases" | head -n1) + if [ -z "$normalized_semver_regexp" ] || [ -z "$string" ] || ! nvm_string_contains_regexp "$string" "$normalized_semver_regexp"; then + die "nvm_string_contains_regexp POSITIVE test case failed. regexp: '$normalized_semver_regexp'. string: '$string'.\n" fi test_cases=$(echo "$test_cases" | tail -n +2) done @@ -26,16 +19,12 @@ done # NEGATIVE TEST CASES # string:regexp -test_cases="1.2.a:$valid_semver_regexp -:$valid_semver_regexp -11.22.a:$valid_semver_regexp" +test_cases=$(printf "%s\n%s" "$VALID_NON_NORMALIZED_SEMVERS" "$INVALID_SEMVERS_FOR_PKG_JSON") while [ -n "$test_cases" ]; do - line=$(echo "$test_cases" | head -n1) - string=$(echo "$line" | awk -F: '{ print $1 }') - regexp=$(echo "$line" | awk -F: '{ print $2 }') - if [ -z "$regexp" ] || nvm_string_contains_regexp "$string" "$regexp"; then - die "nvm_string_contains_regexp NEGATIVE test case failed. regexp: '$regexp'. string: '$string'.\n" + string=$(echo "$test_cases" | head -n1) + if [ -z "$normalized_semver_regexp" ] || nvm_string_contains_regexp "$string" "$normalized_semver_regexp"; then + die "nvm_string_contains_regexp NEGATIVE test case failed. regexp: '$normalized_semver_regexp'. string: '$string'.\n" fi test_cases=$(echo "$test_cases" | tail -n +2) done diff --git a/test/fast/Unit tests/nvm_trim_and_reduce_whitespace_to_one_space b/test/fast/Unit tests/nvm_trim_and_reduce_whitespace_to_one_space index 52f5f0a..0e5da6f 100755 --- a/test/fast/Unit tests/nvm_trim_and_reduce_whitespace_to_one_space +++ b/test/fast/Unit tests/nvm_trim_and_reduce_whitespace_to_one_space @@ -4,12 +4,11 @@ die () { printf "$@" ; exit 1; } \. ../../../nvm.sh -# TODO add more test cases +# Test cases that have no new lines # input:expected_output -test_cases="1.2.3:$valid_semver_regexp -11.22.33:$valid_semver_regexp" - test_cases='1:1 + 1 2 3:1 2 3 + 1.1 2.2 :1.1 2.2 1.2.3:1.2.3 1 1 :1 1 2 2 :2 2' @@ -24,5 +23,30 @@ while [ -n "$test_cases" ]; do fi test_cases=$(echo "$test_cases" | tail -n +2) done + +# Test cases that have new lines +expected_output='1 2 3' +new_line_1=' 1 + 2 3 ' +actual_output=$(nvm_trim_and_reduce_whitespace_to_one_space "$new_line_1") +if [ "$actual_output" != "$expected_output" ]; then + die "nvm_trim_and_reduce_whitespace_to_one_space test with new_line_1 failed. Actual output: '$actual_output' Expected output: '$expected_output'" +fi + +new_line_2=' 1 2 +3 ' +actual_output=$(nvm_trim_and_reduce_whitespace_to_one_space "$new_line_2") +if [ "$actual_output" != "$expected_output" ]; then + die "nvm_trim_and_reduce_whitespace_to_one_space test with new_line_2 failed. Actual output: '$actual_output' Expected output: '$expected_output'" +fi + +new_line_3=' 1 + +2 +3' +actual_output=$(nvm_trim_and_reduce_whitespace_to_one_space "$new_line_3") +if [ "$actual_output" != "$expected_output" ]; then + die "nvm_trim_and_reduce_whitespace_to_one_space test with new_line_3 failed. Actual output: '$actual_output' Expected output: '$expected_output'" +fi exit 0 diff --git a/test/generated_semvers.sh b/test/generated_semvers.sh index 9f1f891..7ea9384 100755 --- a/test/generated_semvers.sh +++ b/test/generated_semvers.sh @@ -96,7 +96,7 @@ VALID_NORMALIZED_COMPLEX_SEMVERS='10.3.0 || 8.1.1 || 4.1.0 8.0.0 || <6.12.0' # Valid semvers that should resolve to a node version but need to be validated/normalized before interpretting. -VALID_NON_NORMALIZED_SEMVERS='x +VALID_NON_NORMALIZED_COMPLEX_SEMVERS='x X * x.x @@ -175,10 +175,14 @@ VALID_NORMALIZED_SEMVERS=$(printf "%s\n%s\n%s" \ "$(generate_semvers "$VALID_NORMALIZED_VERSIONS" "$VALID_NORMALIZED_SEMVER_OPERATORS")" \ ) -VALID_SEMVERS=$(printf "%s\n%s\n%s" \ +VALID_NON_NORMALIZED_SEMVERS=$(printf "%s\n%s" \ + "$VALID_NON_NORMALIZED_COMPLEX_SEMVERS" \ + "$(generate_semvers "$VALID_NORMALIZED_VERSIONS" "$VALID_NON_NORMALIZED_SEMVER_OPERATORS" 0)" \ +) + +VALID_SEMVERS=$(printf "%s\n%s" \ "$VALID_NORMALIZED_SEMVERS" \ "$VALID_NON_NORMALIZED_SEMVERS" \ - "$(generate_semvers "$VALID_NORMALIZED_VERSIONS" "$VALID_NON_NORMALIZED_SEMVER_OPERATORS" 0)" \ ) VALID_SEMVERS_FOR_PKG_JSON=$(printf "%s\n%s" \ diff --git a/test/slow/nvm_interpret_node_semver b/test/slow/nvm_interpret_node_semver index c9b484f..379d923 100755 --- a/test/slow/nvm_interpret_node_semver +++ b/test/slow/nvm_interpret_node_semver @@ -30,6 +30,7 @@ while [ -n "$test_cases" ]; do done # TODO add more test cases here +# TODO get the following semvers working: ^7 ^7.x ^7.0 ~8 ~8.0 # Verify actual outputs given some inputs # input:expected_output test_cases="*:$NEWEST_NODE_VERSION @@ -38,7 +39,12 @@ x:$NEWEST_NODE_VERSION X:$NEWEST_NODE_VERSION 0.12.18:0.12.18 0.11.16:0.11.16 -222.22.2: +7.0.0||7.2.1:7.2.1 +7-8:8.0.0 +7.0:7.0.0 +^7.0.0:7.10.1 +~8.1.0:8.1.4 +^7.0.0||6.8.1:7.10.1 >0.12.18:$NEWEST_NODE_VERSION >=0.11.16:$NEWEST_NODE_VERSION 7.1.0 || 7.3.0 || 7.2.0:7.3.0