0
0
mirror of https://github.com/tj/n.git synced 2024-11-24 19:46:56 +01:00

Remove anti-pattern use of run in more tests

This commit is contained in:
John Gee 2020-12-20 16:42:27 +13:00
parent 228dc1c4d7
commit feddb99772
5 changed files with 47 additions and 84 deletions

View File

@ -28,7 +28,7 @@ function teardown() {
@test "n --quiet 4.9.1" {
# just checking option is allowed, not testing functionality
n --quiet 4.9.1
run node --version
output="$(node --version)"
[ "${output}" = "v4.9.1" ]
}
@ -40,23 +40,23 @@ function teardown() {
local LTS_VERSION="$(display_remote_version lts)"
n ${ARGON_VERSION}
run "${N_PREFIX}/bin/node" --version
output="$("${N_PREFIX}/bin/node" --version)"
[ "$output" = "${ARGON_VERSION}" ]
run "${N_PREFIX}/bin/npm" --version
output="$("${N_PREFIX}/bin/npm" --version)"
[ "$output" = "${ARGON_NPM_VERSION}" ]
n --preserve "${LTS_VERSION}"
run "${N_PREFIX}/bin/node" --version
output="$("${N_PREFIX}/bin/node" --version)"
[ "$output" = "v${LTS_VERSION}" ]
run "${N_PREFIX}/bin/npm" --version
output="$("${N_PREFIX}/bin/npm" --version)"
[ "$output" = "${ARGON_NPM_VERSION}" ]
N_PRESERVE_NPM=1 n "${LTS_VERSION}"
run "${N_PREFIX}/bin/npm" --version
output="$("${N_PREFIX}/bin/npm" --version)"
[ "$output" = "${ARGON_NPM_VERSION}" ]
N_PRESERVE_NPM=1 n --no-preserve "${LTS_VERSION}"
run "${N_PREFIX}/bin/npm" --version
output="$("${N_PREFIX}/bin/npm" --version)"
[ "$output" != "${ARGON_NPM_VERSION}" ]
}

View File

@ -18,20 +18,20 @@ function teardown() {
@test "n 4.9.1" {
n 4.9.1
run node --version
output="$(node --version)"
[ "${output}" = "v4.9.1" ]
}
@test "n lts" {
n lts
run node --version
output="$(node --version)"
[ "${output}" = "v$(display_remote_version lts)" ]
}
@test "n latest" {
n latest
run node --version
output="$(node --version)"
[ "${output}" = "v$(display_remote_version latest)" ]
}

View File

@ -11,26 +11,22 @@ function setup() {
# labels
@test "n lsr lts" {
run n lsr lts
[ "${status}" -eq "0" ]
output="$(n lsr lts)"
[ "${output}" = "$(display_remote_version lts)" ]
}
@test "n lsr stable" {
run n lsr lts
[ "${status}" -eq "0" ]
output="$(n lsr lts)"
[ "${output}" = "$(display_remote_version lts)" ]
}
@test "n ls-remote latest" {
run n ls-remote latest
[ "${status}" -eq "0" ]
output="$(n ls-remote latest)"
[ "${output}" = "$(display_remote_version latest)" ]
}
@test "n list-remote current" {
run n list-remote current
[ "${status}" -eq "0" ]
output="$(n list-remote current)"
[ "${output}" = "$(display_remote_version latest)" ]
}
@ -38,14 +34,12 @@ function setup() {
# codenames
@test "n=1 n lsr argon" {
N_MAX_REMOTE_MATCHES=1 run n lsr argon
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr argon)"
[ "${output}" = "4.9.1" ]
}
@test "n=1 n lsr Argon # case" {
N_MAX_REMOTE_MATCHES=1 run n lsr Argon
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr Argon)"
[ "${output}" = "4.9.1" ]
}
@ -53,32 +47,27 @@ function setup() {
# numeric versions
@test "n=1 n lsr 4" {
N_MAX_REMOTE_MATCHES=1 run n lsr 4
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr 4)"
[ "${output}" = "4.9.1" ]
}
@test "n=1 n lsr v4" {
N_MAX_REMOTE_MATCHES=1 run n lsr v4
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr v4)"
[ "${output}" = "4.9.1" ]
}
@test "n=1 n lsr 4.9" {
N_MAX_REMOTE_MATCHES=1 run n lsr 4.9
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr 4.9)"
[ "${output}" = "4.9.1" ]
}
@test "n=1 n lsr 4.9.1" {
N_MAX_REMOTE_MATCHES=1 run n lsr 4.9.1
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr 4.9.1)"
[ "${output}" = "4.9.1" ]
}
@test "n=1 n lsr v4.9.1" {
N_MAX_REMOTE_MATCHES=1 run n lsr v4.9.1
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr v4.9.1)"
[ "${output}" = "4.9.1" ]
}
@ -103,8 +92,7 @@ function setup() {
# Checking does not match 8.11
@test "n=1 n lsr v8.1 # numeric match" {
N_MAX_REMOTE_MATCHES=1 run n lsr v8.1
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr v8.1)"
[ "${output}" = "8.1.4" ]
}
@ -112,45 +100,38 @@ function setup() {
# Nightly
@test "n=1 n lsr nightly" {
N_MAX_REMOTE_MATCHES=1 run n lsr nightly
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr nightly)"
[ "${output}" = "$(display_remote_version nightly)" ]
}
@test "n=1 n lsr nightly/" {
N_MAX_REMOTE_MATCHES=1 run n lsr nightly/
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr nightly/)"
[ "${output}" = "$(display_remote_version nightly)" ]
}
@test "n=1 n lsr nightly/latest" {
N_MAX_REMOTE_MATCHES=1 run n lsr nightly/latest
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr nightly/latest)"
[ "${output}" = "$(display_remote_version nightly)" ]
}
@test "n=1 n lsr nightly/v10.8.1-nightly201808 # partial match" {
N_MAX_REMOTE_MATCHES=1 run n lsr nightly/v10.8.1-nightly201808
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr nightly/v10.8.1-nightly201808)"
[ "${output}" = "10.8.1-nightly2018081382830a809b" ]
}
# Numeric match should not find v7.10.1-nightly2017050369a8053e8a
@test "n=1 n lsr nightly/7.1 # numeric match" {
N_MAX_REMOTE_MATCHES=1 run n lsr nightly/7.1
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr nightly/7.1)"
[ "${output}" = "7.1.1-nightly201611093daf11635d" ]
}
# Numeric match should not find v7.10.1-nightly2017050369a8053e8a
@test "n=1 n lsr nightly/v7.1 # numeric match" {
N_MAX_REMOTE_MATCHES=1 run n lsr nightly/v7.1
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr nightly/v7.1)"
[ "${output}" = "7.1.1-nightly201611093daf11635d" ]
}
@test "n lsr nightly/v6.10.3-nightly2017040479546c0b5a # exact" {
N_MAX_REMOTE_MATCHES=1 run n lsr nightly/v6.10.3-nightly2017040479546c0b5a
[ "${status}" -eq "0" ]
output="$(N_MAX_REMOTE_MATCHES=1 n lsr nightly/v6.10.3-nightly2017040479546c0b5a)"
[ "${output}" = "6.10.3-nightly2017040479546c0b5a" ]
}

View File

@ -32,37 +32,32 @@ function teardown() {
# n which
@test "n which 4" {
run n which 4
[ "$status" -eq 0 ]
output="$(n which 4)"
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n which v4.9.1" {
run n which v4.9.1
[ "$status" -eq 0 ]
output="$(n which v4.9.1)"
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n bin v4.9.1" {
run n bin v4.9.1
[ "$status" -eq 0 ]
output="$(n bin v4.9.1)"
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n which argon" {
run n which argon
[ "$status" -eq 0 ]
output="$(n which argon)"
[ "$output" = "${N_PREFIX}/n/versions/node/4.9.1/bin/node" ]
}
@test "n which lts" {
run n which lts
output="$(n which lts)"
local LTS_VERSION="$(display_remote_version lts)"
[ "$status" -eq 0 ]
[ "$output" = "${N_PREFIX}/n/versions/node/${LTS_VERSION}/bin/node" ]
}
@ -70,30 +65,26 @@ function teardown() {
# n run
@test "n run 4" {
run n run 4 --version
[ "$status" -eq 0 ]
output="$(n run 4 --version)"
[ "$output" = "v4.9.1" ]
}
@test "n run lts" {
run n run lts --version
output="$(n run lts --version)"
local LTS_VERSION="$(display_remote_version lts)"
[ "$status" -eq 0 ]
[ "$output" = "v${LTS_VERSION}" ]
}
@test "n use 4" {
run n use 4 --version
[ "$status" -eq 0 ]
output="$(n use 4 --version)"
[ "$output" = "v4.9.1" ]
}
@test "n as 4" {
run n as 4 --version
[ "$status" -eq 0 ]
output="$(n as 4 --version)"
[ "$output" = "v4.9.1" ]
}
@ -103,22 +94,19 @@ function teardown() {
# n exec
@test "n exec v4.9.1 node" {
run n exec v4.9.1 node --version
[ "$status" -eq 0 ]
output="$(n exec v4.9.1 node --version)"
[ "$output" = "v4.9.1" ]
}
@test "n exec 4 npm" {
run n exec 4 npm --version
[ "$status" -eq 0 ]
output="$(n exec 4 npm --version)"
[ "$output" = "2.15.11" ]
}
@test "n exec lts" {
run n exec lts node --version
output="$(n exec lts node --version)"
local LTS_VERSION="$(display_remote_version lts)"
[ "$status" -eq 0 ]
[ "$output" = "v${LTS_VERSION}" ]
}

View File

@ -14,42 +14,36 @@ function setup() {
@test "display_latest_resolved_version active" {
local TARGET_VERSION="$(display_remote_version latest)"
run n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION active
[ "$status" -eq 0 ]
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION active)"
[ "$output" = "${TARGET_VERSION}" ]
}
@test "display_latest_resolved_version lts_active" {
local TARGET_VERSION="$(display_remote_version lts)"
run n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION lts_active
[ "$status" -eq 0 ]
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION lts_active)"
[ "$output" = "${TARGET_VERSION}" ]
}
@test "display_latest_resolved_version lts_latest" {
local TARGET_VERSION="$(display_remote_version lts)"
run n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION lts_latest
[ "$status" -eq 0 ]
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION lts_latest)"
[ "$output" = "${TARGET_VERSION}" ]
}
@test "display_latest_resolved_version lts" {
local TARGET_VERSION="$(display_remote_version lts)"
run n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION lts
[ "$status" -eq 0 ]
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION lts)"
[ "$output" = "${TARGET_VERSION}" ]
}
@test "display_latest_resolved_version current" {
local TARGET_VERSION="$(display_remote_version latest)"
run n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION current
[ "$status" -eq 0 ]
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION current)"
[ "$output" = "${TARGET_VERSION}" ]
}
@test "display_latest_resolved_version supported" {
local TARGET_VERSION="$(display_remote_version latest)"
run n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION supported
[ "$status" -eq 0 ]
output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION supported)"
[ "$output" = "${TARGET_VERSION}" ]
}