-
Notifications
You must be signed in to change notification settings - Fork 16
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
Feature idea: file-level filtering option #11
Comments
Thank you for such a detailed proposal, I appreciate that! In the current implementation, we can filter the files to use using Rake task's require 'yard/doctest/rake'
YARD::Doctest::RakeTask.new do |task|
task.pattern = 'app/**/*.rb'
end Your point of more adoption is a valid one, so it makes sense to allow for one-by-one adoption. In this case, we need Another possible solution is to generate configuration which will skip all failing tests by default. Something similar to RuboCop |
In regards to |
TL;DR I like the config generation idea. It doesn't complicate the runtime code, it gives you a clear list of what doesn't work, doesn't involve any file-flagging mess, and lets you get going right away in an existing codebase. On Implementation CLI or Rake task? Does pretty much everyone depend on Rake (and if you don't, well, do if you want to use this)? I personally never liked Rake much... the "ENV vars are kind-of arguments sometimes and oh let's also use short generic ones like The way I understand the config generation approach is that you would want to generate the config when you first added YARD Doctest, since that's the only time a failed example may not mean a failed doctest, then probably update it by hand any time you added an example that isn't meant to doctest? Yeah, that seems like it would work. It gives you a list of everything being skipped in one place, which is nice if you're aiming to eventually aiming to have all The major downside I see is having to remember check that list to make sure I don't think something is working when it's getting skipped, and possibly end up incorporating a false pretense into the library if you forget or miss it. I realize that in addition to Ruby that "should run", I traditionally use It seems like doctest's inherent paradigm is all-or-nothing: you doctest, and all From this angle, I like the config generation solution: it doesn't mess with the runtime code but it can buy you some time to get everything in order, with a clear list of what isn't yet. The other road - some There's always code blocks to demonstrate stuff that doesn't run. |
The more I think about this, the more it seems to me that yard-doctest can behave in the following way:
This way we can get initially passing doctests and disable those that are not passing, but also guarantee that as soon as any they start passing - they won't be forgotten. |
My idea was that any |
@p0deje One case that comes to mind is if there is a significant amount of context required for the example to work. As a very simple example
However one could argue that in such a scenario you should have some static pre-amble module to get your context. Would possibly become (or event just
Disabling doctest on a per-example level instead of a per-file level makes most sense to me. |
@chriscz In this particular scenario, why don't you want to provide |
That's my mistake @p0deje, I see it in the README. Thank you! |
Summary
Add a CLI option to only doc-test source files containing a special comment or YARD tag.
This would allow for gradual file-by-file incorporation into existing code bases that already have
@example
tags all over the place that were not written to doc-test.Like how Flow uses
// @flow
comments to activate type checking at a file level, if you happen to have used that. I swear I've seen this sort of thing in other softwares as well, but they're not coming to mind at the moment.Usage
Add comments or tags to the desired file and add a flag to the CLI command, something like:
I'm not sure about the name
--opt-in
, but I'm having trouble thinking of something better right now.Background
I'm doing this right now by sticking a
# doctest: true
comment in the files that I've migrated over to use doc-tests, then running via a harness script
However, I think it would ease adoption into existing code bases to have this functionality built-in. And I'd like to see more adoption, 'cause I feel there is little more frustrating than wasting precious time with new software in "what the hell am I doing wrong?"-land only to eventually figure out that the example itself is broken.
Implementation Thoughts
Ruby already has "magic" file-level comments like
# frozen_string_literal: true
, etc., so there's some basis for the# doctest: true
approach, though it might be confusing since the other magic comments people are used to seeing are Ruby VM directives, and this is not. But magic comments are also used to tell editors things about the file and such, so it seems reasonable. Maybe# yard-doctest: true
would be more clear.Using a YARD tag is possibly another option, like
@doctest true
, but it's a least a bit more complicated... I'm not familiar how (if at all) YARD binds file-level doc-strings as I've only ever used "code-object"-level stuff.A YARD tag could be naturally be extended to finer granularity: putting
@doctest true
or@doctest false
on method docs to switch those on or off individually.The text was updated successfully, but these errors were encountered: