-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #16993, #18054, #17835 runnableExamples now works with templates and nested templates #18082
fix #16993, #18054, #17835 runnableExamples now works with templates and nested templates #18082
Conversation
assertImpl(cond, msg, astToStr(cond), true) | ||
|
||
template onFailedAssert*(msg, code: untyped): untyped {.dirty.} = | ||
## Sets an assertion failure handler that will intercept any assert | ||
## statements following `onFailedAssert` in the current scope. | ||
runnableExamples: | ||
type MyError = object of CatchableError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've also improved a bit the examples after moving them at template scope
action: "compile" | ||
nimoutFull: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
25300b7
to
656e602
Compare
<p><strong class="examples_text">Example:</strong></p> | ||
<pre class="listing"><span class="Identifier">assert</span> <span class="DecNumber">3</span><span class="Operator">*</span><span class="DecNumber">2</span> <span class="Operator">==</span> <span class="DecNumber">6</span></pre>ditto | ||
<pre class="listing"><span class="Keyword">discard</span> <span class="StringLit">"should be in utils.html only, not in module that calls fromUtilsGen"</span></pre>ditto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's there, see hould be in utils.html only, not in module that calls fromUtilsGen
runnableExamples: | ||
assert 3*2 == 6 | ||
discard "should be in utils.html only, not in module that calls fromUtilsGen" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this changed? Does the assert
inside a runnableExample inside a template still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, of course assert still works, the new comment makes it clear when you look at nim sources + generated file where it came from and where it should end up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also tested via tests/nimdoc/trunnableexamples.nim btw
ping @Araq |
…ow works with templates and nested templates (nim-lang#18082)
fix #16993
fix #18054
fix #17835
close #17842 as this is a proper fix whereas #17842 was a workaround
the diff in nimdoc/testproject/subdir/subdir_b/utils.nim sums it up.
future work
code-block
has almost no use cases left in nim sources and should be replaced byrunnableExamples
runnableExamples(inject = true)
to inject the runnableExamples of a templatefoo
at the place wherefoo
is called, but this is a niche feature, and the main use case is the one implemented by this PR (as evidenced by those bug reports)notes
related past issues (dealing with doc comments instead of runnableExamples):
#9596, #9432, #9626, #9473, #9469
I also encountered #18077 while fixing this (EDIT: fixing it here: #18086)