Skip to content

Conversation

@ericmj
Copy link
Member

@ericmj ericmj commented Dec 17, 2013

Will now do raw string compare for doctests of #Module<...> format:

iex> HashDict.new a: 0, b: 1, c: 2
#HashDict<[a: 0, b: 1, c: 2]>

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 may look like a hack but the resulting error message is really nice:

     ** (ExUnit.ExpectationError)
       expected doctest: inspect (HashDict.new d: 3, e: 4, f: 5)
         to evaluate to: "#HashDict<[a: 0, b: 1, c: 2]>"
            instead got: "#HashDict<[d: 3, e: 4, f: 5]>"

You see exactly what is happening.

Copy link
Member

Choose a reason for hiding this comment

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

Looks nice. We just need to remove the space in between inspect and ( or get rid of parentheses.

@ericmj
Copy link
Member Author

ericmj commented Dec 17, 2013

Forgot docs, hold on.

@ericmj
Copy link
Member Author

ericmj commented Dec 17, 2013

Added docs.

@meh
Copy link
Contributor

meh commented Dec 17, 2013

👍 :rage4:

@vendethiel
Copy link

Seems to have a typo "<[" closed as "]"

@ericmj
Copy link
Member Author

ericmj commented Dec 17, 2013

@Nami-Doc Thank you. Apparently the DocTest module isn't doctested, go figure.

I also made Version use the new feature. Any other modules that may use this?

@josevalim
Copy link
Member

@Nami-Doc @ericmj the doctest module has example of bad doc tests and that would make it fail. :P

Copy link
Member

Choose a reason for hiding this comment

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

Why are we stripping? I don't think it is a good idea. Imagine this:

iex> """
...>   hello
...> """

Will now do raw string compare for doctests of #Module<...> format:

    iex> HashDict.new a: 0, b: 1, c: 2
    #HashDict<[a: 0, b: 1, c: 2]>
@ericmj
Copy link
Member Author

ericmj commented Dec 18, 2013

There was actually a problem with just prepending the expression string with "inspect " for expressions that span multiple lines or expressions that have multiple statements (for example assignment). So instead I added a new :inspect test case.

josevalim pushed a commit that referenced this pull request Dec 31, 2013
Add raw string compare in doctests for #Module<...>
@josevalim josevalim merged commit 9c9d8e8 into elixir-lang:master Dec 31, 2013
@ericmj ericmj deleted the doctest-inspect branch June 5, 2019 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants