Skip to content

Doctesting examples don't work #1656

Closed
@maxwellmckinnon

Description

@maxwellmckinnon

Summary

Doctests are such a great idea, but I'm struggling to get started. The examples don't work, ironically :P. I'm a Rust Noobie, and I was thinking by making some doctests I could build up a project I want to do in Rust more easily. I did get the unit testing section to work, currently 21.1. This was the section before documentation testing, currently 21.2.

Steps to Reproduce

  1. Take doctest example and paste it into https://play.rust-lang.org/
  2. Click the button that says equivalent to cargo test

Expected Results

Test to run and pass

Actual Results

Test runs but fails

use of undeclared crate or module `doccomments`

Attempts to fix

I tried taking off the doccomments scope, that didn't help it to pass.

cannot find function `add` in this scope

I tried googling for doctest examples and couldn't get them to work in either the rust sandbox or my local computer with rust installed.

doctest example:
https://doc.rust-lang.org/rust-by-example/testing/doc_testing.html

source:
https://github.com/rust-lang/rust-by-example/blob/47a386d1af7e7ddd79464d0078f9c2bc1d515c06/src/testing/doc_testing.md

I'm doing something noobie wrong, but it would be great if the doc examples run out of the box correctly. Thanks :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions