Skip to content

rustdoc: Render doctest paths more conventionally as path/to/file.rs:LINE in output instead of path/to/file.rs … (line LINE) #60706

@phrohdoh

Description

@phrohdoh

Originally filed at rust-lang/cargo#6927


When running cargo test on a project with some doc tests I see the following output:

$ cargo test   
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running target/debug/deps/tq_parser-9edae091aa940c1c

running 1 test
test tokenizer::tests::string_literal::simple ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests tq-parser

running 3 tests
test src/tokenizer.rs - tokenizer::Tokenizer<'text>::new (line 158) ... ok
test src/tokenizer.rs - tokenizer::Tokenizer (line 36) ... ok
test src/tokenizer.rs - tokenizer::Token (line 122) ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

This ticket is focusing on this portion:

   Doc-tests tq-parser

running 3 tests
test src/tokenizer.rs - tokenizer::Tokenizer<'text>::new (line 158) ... ok
test src/tokenizer.rs - tokenizer::Tokenizer (line 36) ... ok
test src/tokenizer.rs - tokenizer::Token (line 122) ... ok

I believe this output could be more useful, perhaps at the cost of being 'pretty', if the line numbers were joined to the source file path with a : to produce a clickable (in some environments) path.

For example, if the output were the following

   Doc-tests tq-parser

running 3 tests
test src/tokenizer.rs:158 - tokenizer::Tokenizer<'text>::new ... ok
test src/tokenizer.rs:36 - tokenizer::Tokenizer ... ok
test src/tokenizer.rs:122 - tokenizer::Token ... ok

I could cmd-click on src/tokenizer.rs:158 and be taken, in my editor, directly to the doc test instead of having to open the file then navigate to the line.

This is more useful in the case of errors.

If I change the tokenizer::Tokenizer<'text>::new test to fail I get

test src/tokenizer.rs - tokenizer::Tokenizer<'text>::new (line 158) ... FAILED

Which could be

test src/tokenizer.rs:158 - tokenizer::Tokenizer<'text>::new ... FAILED

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocA-libtestArea: `#[test]` / the `test` libraryC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions