Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTesting stdout output in documentation tests #2270
Comments
newpavlov
changed the title
Testing stdin output in documentation tests
Testing stdout output in documentation tests
Dec 29, 2017
Centril
added
the
T-dev-tools
label
Dec 29, 2017
This comment has been minimized.
This comment has been minimized.
shingtaklam1324
commented
Jan 30, 2018
•
|
So this is similar to what Elixir has for doctests here, except for using stdout instead of iex? This can be very powerful for documenting functions that have IO. Regarding |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
newpavlov commentedDec 29, 2017
•
edited
Currently there is no standard way to specify what example code example writes to stdout in doctests, thus makinf it impossible to test this output. Borrowing from Python I would like to propose to add something like
\\> footo doctest to specify stdout output of snippets. For example:Using it
cargo testwill be able to test standard output of the program, thus making some testing cases a lot easier. Additionally it will be an incentive for crate authors to use this functionality thus making examples easier to understand for crate users.Because output will be checked after program execution this example will pass tests:
While it should be considered a bad practice to write doctests in such way, checking relations between code line and output will be technically challenging, so I think it's better to leave it for crate authors to handle.
Unresolved question: should stderr be considered as stdout for testing purposes, or is it better to add similar functionality for stderr as well, e.g.
//stderr> foo?