Commit 92cd8d79
92cd8d792219Merged
Ori Pekelman <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
test: add ENV.fetch set-path coverage (HOME probe)
Per #390 review: extend test/env_fetch.rb to also exercise the
"env var is set" branch. Spinel doesn't expose ENV[]= from
Ruby so we can't set the var ourselves; HOME is always exported
by POSIX make and in CI, so it works as a portable probe. The
assertion is "non-empty + not the fallback string", which stays
host-agnostic (the actual value differs per machine).
A regression that inverted the getenv-result ternary -- returning the default when getenv succeeds -- would print "set=fallback- not-used" instead of "set=ok".
The symmetric unset=... line (with a literal default) catches
the inverse mistake of always returning the env value (empty
string) regardless of whether getenv succeeded.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 92cd8d792219
- Parent
- aff9b1fc536d
test/env_fetch.rbmodifiedView file
# Regression: `ENV.fetch(key, default)` returns the env value when# set, otherwise `default`. Pre-fix the codegen emitted "cannot# resolve call to 'fetch' on int" and segfaulted at runtime.## This test exercises the unset / default-fallback branch, since# spinel doesn't currently expose `ENV[]=` for setting a var from# Ruby. The set branch shares the same getenv() path.# ---- unset / default branch ----# Literal default.puts ENV.fetch("DEFINITELY_UNSET_VAR_XYZ_42", "fallback-value")# Default by string concatenation.puts ENV.fetch("THIRD_UNSET_VAR_XYZ_42", "pre-" + "fix")# ---- set / retrieval branch ----# Spinel doesn't currently expose `ENV[]=` from Ruby, so we can't# set a var ourselves. HOME is always exported by POSIX `make` and# in CI, so we use that as the "set" probe. We only assert "non-# empty + not the fallback string" so the test stays portable# across runners (the actual home value differs per machine).# A regression that inverted the getenv-result ternary would# return the fallback here and print "set=fallback-not-used".home = ENV.fetch("HOME", "fallback-not-used")if home.length > 0 && home != "fallback-not-used" puts "set=ok"else puts "set=" + homeend# Symmetric: an unset var with a literal default round-trips# through the same ternary. (Would catch a regression that always# returned the env value -- empty string -- regardless.)maybe = ENV.fetch("DEFINITELY_UNSET_VAR_ABC_99", "fallback-used")puts "unset=" + maybetest/env_fetch.rb.expectedmodifiedView file
Loading diff…