Skip to content
Myr

[Tests] `aliases`: cover the regex-metachar cycle fix; clean up fixtures in teardown

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The cycle scenarios all pass with the old grep-based detection too; the bug the `case`-based detection actually fixes is resolved names interpolated into the grep pattern as regexes, where resolving axb -> a.b falsely reported ∞ because the pattern `a.b` matches the seen name `axb`. Pin both directions: the fixed false positive, and a genuine cycle through a metachar name. Also correct the space-name scenario comment (the old anchored grep passed that scenario; only token-delimited seen-storage would not), and register every new fixture name in the suite teardown, so a mid-test failure can not leak aliases into later tests.

authored by Jordan Harband · committed by Jordan Harband · parent 0a9dead · Browse files · 2 files+29 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−2 removed

  • tests:+29 added−2 removed

2 files+29 added−2 removed

modified:test/fast/Aliases/nvm_resolve_alias handles cycles+24 added-2 removed
36 unmodified lines
3738rm -f '../../../alias/foo bar' '../../../alias/midway'3940# Non-cycle through an alias name containing a space.41# Token-based cycle detection would false-positive on this chain because42# 'bar' appears as a substring of the multi-token alias name 'foo bar'.41# Guards the newline-delimited SEEN_ALIASES storage: with space- or42# token-delimited storage, seen name 'foo bar' would falsely match 'bar'.43# Resolves: 'foo bar' -> 'midway' -> 'bar' -> 0.0.9944echo 'midway' > '../../../alias/foo bar'45echo 'bar' > '../../../alias/midway'46echo '0.0.99' > '../../../alias/bar'
2 unmodified lines
49EXPECTED='v0.0.99'50[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}< for space-name chain, got >${ACTUAL}<"5152rm -f '../../../alias/foo bar' '../../../alias/midway' '../../../alias/bar'5354# Non-cycle through an alias name containing a regex metacharacter.55# Guards the literal `case` matching: the previous grep-based detection56# interpolated the resolved name into an anchored regex, so resolving 'axb'57# matched the seen name 'axb' against the pattern 'a.b' and falsely58# reported a cycle.59# Resolves: 'axb' -> 'a.b' -> 0.0.9960echo 'a.b' > '../../../alias/axb'61echo '0.0.99' > '../../../alias/a.b'6263ACTUAL="$(nvm_resolve_alias axb)"64EXPECTED='v0.0.99'65[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}< for metachar-name chain, got >${ACTUAL}<"6667# ... while a genuine cycle through a metachar name is still detected68echo 'axb' > '../../../alias/a.b'6970ACTUAL="$(nvm_resolve_alias axb)"71EXPECTED='∞'72[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}< for metachar-name cycle, got >${ACTUAL}<"7374rm -f '../../../alias/axb' '../../../alias/a.b'
modified:test/fast/Aliases/teardown+5 added
15 unmodified lines
16rm -f "../../../alias/iojs"17rm -f "../../../alias/default"18rm -f "../../../alias/test-blank-lines"19rm -f "../../../alias/test-multi-lines"20rm -f "../../../alias/test-edge-"* "../../../alias/test edge spaces"21rm -f "../../../alias/self" "../../../alias/link1" "../../../alias/link2" "../../../alias/link3"22rm -f "../../../alias/foo bar" "../../../alias/midway" "../../../alias/bar"23rm -f "../../../alias/hop1" "../../../alias/hop2" "../../../alias/hop3" "../../../alias/hop4"24rm -f "../../../alias/axb" "../../../alias/a.b"