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

runnableExamples that are only compiled #10731

Closed
FedericoCeratto opened this issue Feb 24, 2019 · 7 comments · Fixed by #14384
Closed

runnableExamples that are only compiled #10731

FedericoCeratto opened this issue Feb 24, 2019 · 7 comments · Fixed by #14384
Labels

Comments

@FedericoCeratto
Copy link
Member

FedericoCeratto commented Feb 24, 2019

runnableExamples are run by nim doc. Some code examples should not be run due to side effects or other reasons, but parsing and compiling the code is still beneficial to prevent code rot.

For example: httpclient fetching a remote URL; deleting files; and so on.

This can become quite dangerous when running nim doc on 3rd party libraries where the authors might have written examples without realizing they would be execute automatically!

@Araq Araq added the Feature label Feb 25, 2019
@juancarlospaco
Copy link
Collaborator

runnableExamples:
  if off:
    echo "I am and example, but too lazy to Run"

@alaviss
Copy link
Collaborator

alaviss commented Feb 28, 2019

runnableExamples:
  proc main() =
    echo "I'm not running"

^ that's also a way.

@FedericoCeratto
Copy link
Member Author

Any "if false", "when false", "def main" line is confusing to people reading the examples (as they are unaware of the hack). Also nim doc still tries to execute the file without need.

@Araq
Copy link
Member

Araq commented Mar 1, 2019

Non-running runnable examples are confusing, you might as well use .. code-block:: nim for the example then.

@FedericoCeratto
Copy link
Member Author

@Araq the code-block renders differently and (as you said before) leads to code rot. I guess proc example() could be the least confusing:

runnableExamples:
  proc example() =
    echo "I'm not running"

@timotheecour
Copy link
Member

fixing this more generally in #14384, which allows passing an arbitrary cmd

@FedericoCeratto
Copy link
Member Author

This sounds like a good use-case for the Effect system - if there was a way to ensure that examples are not doing I/O and other unwanted activities.

Araq pushed a commit that referenced this issue May 20, 2020
* runnableExamples "-b:cpp -r:off": code
EchoPouet pushed a commit to EchoPouet/Nim that referenced this issue Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants