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

@@ -1,11 +1,9 @@
11 # Regression: `ENV.fetch(key, default)` returns the env value when
22 # set, otherwise `default`. Pre-fix the codegen emitted "cannot
33 # resolve call to 'fetch' on int" and segfaulted at runtime.
4-#
5-# This test exercises the unset / default-fallback branch, since
6-# spinel doesn't currently expose `ENV[]=` for setting a var from
7-# Ruby. The set branch shares the same getenv() path.
84
5+# ---- unset / default branch ----
6+
97 # Literal default.
108 puts ENV.fetch("DEFINITELY_UNSET_VAR_XYZ_42", "fallback-value")
119
@@ -15,3 +13,24 @@
1513
1614 # Default by string concatenation.
1715 puts ENV.fetch("THIRD_UNSET_VAR_XYZ_42", "pre-" + "fix")
16+
17+# ---- set / retrieval branch ----
18+# Spinel doesn't currently expose `ENV[]=` from Ruby, so we can't
19+# set a var ourselves. HOME is always exported by POSIX `make` and
20+# in CI, so we use that as the "set" probe. We only assert "non-
21+# empty + not the fallback string" so the test stays portable
22+# across runners (the actual home value differs per machine).
23+# A regression that inverted the getenv-result ternary would
24+# return the fallback here and print "set=fallback-not-used".
25+home = ENV.fetch("HOME", "fallback-not-used")
26+if home.length > 0 && home != "fallback-not-used"
27+ puts "set=ok"
28+else
29+ puts "set=" + home
30+end
31+
32+# Symmetric: an unset var with a literal default round-trips
33+# through the same ternary. (Would catch a regression that always
34+# returned the env value -- empty string -- regardless.)
35+maybe = ENV.fetch("DEFINITELY_UNSET_VAR_ABC_99", "fallback-used")
36+puts "unset=" + maybe