Skip to content

fix(rct): handle reader conditionals#10

Merged
robertluo merged 1 commit into
robertluo:mainfrom
parth-io:fix/multiline-expectations-and-reader-conditionals
Mar 23, 2026
Merged

fix(rct): handle reader conditionals#10
robertluo merged 1 commit into
robertluo:mainfrom
parth-io:fix/multiline-expectations-and-reader-conditionals

Conversation

@parth-io
Copy link
Copy Markdown

@parth-io parth-io commented Mar 18, 2026

Support #? reader conditionals in test expectations

Problem

RCT expectations containing reader conditionals (#?(:clj ... :cljr ...)) fail with Conditional read not allowed. This affects .cljc projects that need platform-specific expected values.

;; This fails:
(my-fn args)
;=>
{:result #?(:clj 1 :cljr 2)}

There are two independent issues:

Issue 1: default-read-expectation uses read-string without :read-cond

default-read-expectation calls (read-string expectation-string), which throws on #?.

Fix: (read-string {:read-cond :allow} expectation-string)

This affects both inline (;=> #?(:clj 1 :cljr 2)) and separate-line expectations.

Issue 2: Separate-line expectations are evaluated as standalone test expressions

test-sexpr-zlocs returns all z/sexpr-able? nodes inside a ^:rct/test (comment ...) block, including forms that serve as separate-line expectations:

(+ 1 1)
;=>
2  ;; ← this is ALSO picked up as a standalone test expression

For normal values this is harmless ((eval 2) → 2). But rewrite-clj's ReaderMacroNode.sexpr* converts #?(:clj x :cljr y) into the form (read-string "#?(:clj x :cljr y)"), and evaluating this calls clojure.core/read-string without :read-cond :allow → error.

Fix: Filter out nodes that directly follow an empty result comment — they are expectations, not test expressions. The actual assertion still runs via expectation-data (which traverses forward from the test expression).

@parth-io parth-io changed the title fix(rct): handle multiline expectations and reader conditionals fix(rct): handle reader conditionals Mar 18, 2026
@robertluo robertluo merged commit 6765d3b into robertluo:main Mar 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants