0
0
mirror of https://github.com/tj/n.git synced 2024-11-22 11:37:26 +01:00
n/test/tests/version-resolve.bats
John Gee 59adcab8b4
Add auto label to read version from .node-version (#616)
* Add support for auto, reading version from .node-version

* Make version unique in tests

* Add support for auto doing a lookup for unresolved version

* Make auto description more consistent in style with other labels.
2020-04-11 14:10:29 +12:00

70 lines
1.6 KiB
Bash

#!/usr/bin/env bats
# Note: full semver is resolved without lookup, so can use arbitrary versions for testing like 999.999.999
load shared-functions
function setup() {
unset_n_env
tmpdir="${TMPDIR:-/tmp}"
export MY_DIR="${tmpdir}/n/test/run-version-resolve"
mkdir -p "${MY_DIR}"
}
@test "auto, missing file" {
cd "${MY_DIR}"
rm -f .node-version
run n N_MOCK_DISPLAY_LATEST_RESOLVED_VERSION auto
[ "$status" -ne 0 ]
}
@test "auto, no eol" {
cd "${MY_DIR}"
printf "101.0.1" > .node-version
run n N_MOCK_DISPLAY_LATEST_RESOLVED_VERSION auto
[ "$status" -eq 0 ]
[ "$output" = "101.0.1" ]
}
@test "auto, unix eol" {
cd "${MY_DIR}"
printf "101.0.2\n" > .node-version
run n N_MOCK_DISPLAY_LATEST_RESOLVED_VERSION auto
[ "$status" -eq 0 ]
[ "$output" = "101.0.2" ]
}
@test "auto, Windows eol" {
cd "${MY_DIR}"
printf "101.0.3\r\n" > .node-version
run n N_MOCK_DISPLAY_LATEST_RESOLVED_VERSION auto
[ "$status" -eq 0 ]
[ "$output" = "101.0.3" ]
}
@test "auto, leading v" {
cd "${MY_DIR}"
printf "v101.0.4\n" > .node-version
run n N_MOCK_DISPLAY_LATEST_RESOLVED_VERSION auto
[ "$status" -eq 0 ]
[ "$output" = "101.0.4" ]
}
@test "auto, first line only" {
cd "${MY_DIR}"
printf "101.0.5\nmore text\n" > .node-version
run n N_MOCK_DISPLAY_LATEST_RESOLVED_VERSION auto
[ "$status" -eq 0 ]
[ "$output" = "101.0.5" ]
}
@test "auto, lookup" {
# Check normal resolving, which is allowed but not required for MVP .node-version
cd "${MY_DIR}"
printf "4.9\n" > .node-version
run n N_MOCK_DISPLAY_LATEST_RESOLVED_VERSION auto
[ "$status" -eq 0 ]
[ "$output" = "4.9.1" ]
}