lua: require/package via package.preload +5 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -876,6 +876,18 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1507)
|
||||
(eval "(lua-eval-ast \"return type(os.tmpname())\")")
|
||||
|
||||
;; ── Phase 7: require / package ────────────────────────────────
|
||||
(epoch 1600)
|
||||
(eval "(lua-eval-ast \"package.preload.mymath = function() local m = {} m.add = function(a, b) return a + b end return m end local mm = require(\\\"mymath\\\") return mm.add(3, 4)\")")
|
||||
(epoch 1601)
|
||||
(eval "(lua-eval-ast \"package.preload.counter = function() local n = 0 local m = {} m.inc = function() n = n + 1 return n end return m end local c1 = require(\\\"counter\\\") local c2 = require(\\\"counter\\\") c1.inc() c1.inc() return c2.inc()\")")
|
||||
(epoch 1602)
|
||||
(eval "(lua-eval-ast \"local ok, err = pcall(require, \\\"nope\\\") if ok then return 0 else return 1 end\")")
|
||||
(epoch 1603)
|
||||
(eval "(lua-eval-ast \"package.preload.x = function() return {val = 42} end require(\\\"x\\\") return package.loaded.x.val\")")
|
||||
(epoch 1604)
|
||||
(eval "(lua-eval-ast \"package.preload.noret = function() end local r = require(\\\"noret\\\") return type(r)\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1317,6 +1329,13 @@ check 1505 "os.date(*t).year" '1970'
|
||||
check 1506 "os.getenv → nil" '1'
|
||||
check 1507 "os.tmpname → string" '"string"'
|
||||
|
||||
# ── Phase 7: require / package ────────────────────────────────
|
||||
check 1600 "require(preload) + call" '7'
|
||||
check 1601 "require returns cached" '3'
|
||||
check 1602 "require unknown module errors" '1'
|
||||
check 1603 "package.loaded populated" '42'
|
||||
check 1604 "nil return caches as true" '"boolean"'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL Lua-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user