Should this result in a warning?

53 views
Skip to first unread message

thibaut...@gmail.com

unread,
Feb 3, 2022, 12:10:11 PM2/3/22
to elixir-lang-core
Hello,

While debugging some doctests I haven't written initially myself, I realised that one can create doctests that are bogus and will be skipped quite easily, just like this:

## Examples
iex > SomeModule.some_method("param")
"expected_output"

The culprit is the extra space between "iex" and ">", which prevents the test from being executed (and the developer is not aware of that at all!).

I wonder if some form of protection against that could be made, either in Elixir or in Credo maybe?

Not a huge issue, but it could result in some head-banging for some :-)

-- Thibaut

José Valim

unread,
Feb 3, 2022, 5:50:37 PM2/3/22
to elixir-lang-core
Hi Thibaut,

There are two questions I asked myself:

1. What are the broadcast cases we can warn on to help people running into situations like these?

2. Can we emit false positives?

One thing to keep in mind is that looking for "iex>" is already a bit lax today as it doesn't consider indentation. So having any line starting with "iex>" will be considered a doctest. Adding rules like "iex >" may make false positives more possible then, especially if we try to detect other typos.

So at the moment, I am not sure if it is worth it. It feels like this should be solved somehow (maybe change editors to highlight it), but I am not convinced.

What are everyone's thoughts?

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/bf7c0071-5540-409c-8e63-bdcf31fca68bn%40googlegroups.com.

Valter Sundström

unread,
Feb 4, 2022, 2:23:16 AM2/4/22
to elixir-l...@googlegroups.com
Personally I feel the risk of a false positives is very low for this: 
^ *iex *>
 In how many other situations would you want a line starting with this, before a test, and not mean for it to be a doctest? I really struggle to come up with an example, but I might definitely have blind spots.
Accidentally dropping tests silently seems a lot worse, even if I think that the situation shouldn't happen often if tests are properly run when being made (e.g watching them fail at least once, specifically to make sure your test is actually doing what you think).
In the worst case, it also seems a change like this could be reverted in a following minor release if it really turns out to give too many false positives.

Just my casual input
// Valter

Adam Lancaster

unread,
Feb 4, 2022, 3:09:59 AM2/4/22
to elixir-l...@googlegroups.com
Is it something the formatter could handle at all? Perhaps with a best effort if it ever sees `iex >` it makes it `iex>`

Best

Adam

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

José Valim

unread,
Feb 4, 2022, 3:21:28 AM2/4/22
to elixir-lang-core
As a general principle the formatter does not change the AST and changing the contents of a string would definitely change the AST. :)

Thibaut Barrère

unread,
Feb 4, 2022, 3:41:02 AM2/4/22
to elixir-l...@googlegroups.com
After sleeping on it, I realise that I've come across this specific problem only once, ever, since working with Elixir.

Also it reminds me of another case where the doctests were written, but not registered in the test case, causing similar consequences (if I recall well).

Maybe there is a broader theme of "how to make sure doctests cannot catch people off guard", but for the specific problem I've raised here, I believe some time is probably needed to see clearer, because the drawbacks of "managing" this (false positives / how to whitelist them etc) are very real too.

I'll comment back if I meet those issues in a later codebase :-)

-- Thibaut







You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/kqal5g87_EE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KAb5hHvvmuwrdFaUhbeFdauEghrOg0Tqmd1Vj4-V%3DofQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages