Skip to content
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

Merged

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented May 24, 2021

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

  • after this PR, code-block has almost no use cases left in nim sources and should be replaced by runnableExamples
  • we could also introduce a flag runnableExamples(inject = true) to inject the runnableExamples of a template foo at the place where foo 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)

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
Copy link
Member Author

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without nimoutFull, this test wouldn't be sufficient to check that the bugs were fixed; so because of #18077 i have to split the test in 2 files temporarily until #18077 gets fixed

@timotheecour timotheecour added the Ready For Review (please take another look): ready for next review round label May 24, 2021
<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">&quot;should be in utils.html only, not in module that calls fromUtilsGen&quot;</span></pre>ditto
Copy link
Member Author

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"
Copy link
Member

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?

Copy link
Member Author

@timotheecour timotheecour May 26, 2021

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

Copy link
Member Author

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

@timotheecour
Copy link
Member Author

ping @Araq

@timotheecour
Copy link
Member Author

@timotheecour timotheecour merged commit 0de3d42 into nim-lang:devel Jun 2, 2021
@timotheecour timotheecour deleted the pr_runnableExamples_template branch June 2, 2021 16:02
PMunch pushed a commit to PMunch/Nim that referenced this pull request Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review (please take another look): ready for next review round
Projects
None yet
3 participants