Naming example tests when run

Hi all,

When I run cargo test, the examples which are run are named with a appended string like _0, _1, ...

Is there a way to name such a test ?

2 Likes

Maybe should I need to be more specific.

When testing module examples, what's displayed is the name of the module with _0 which is not very meaningful.

For example, my examples are shown this way on the console:

running 9 tests
test _0 ... ignored
test reader::Reader::next_0 ... ignored
test fieldtype_0 ... ok
test record::Record::filter_0 ... ignored
test field_0 ... ok
test vector_of_0 ... ignored
test layout_0 ... ok
test reader_0 ... ok
test record_0 ... ok

Any hint ?

1 Like

I think those are doc tests. I don't know how to give doc tests names. fns with #[test] should have more meaningful names. But maybe point us at a repo or some kind of reproducible example, and we may be more helpful.

1 Like

For instance, the _0 is an example I've put in the lib.rs header, with //! as comments.
I've set it to ignore, but it doesn't change the fact I can't see anything but

test _0

It could be useful to add: name='my_fancy_example' and print it out as

test my_fancy_example

I've noticed starting in 1.17 that doc tests report file and line numbers.

e.g. 1.16 said: test _0 ... ok
1.17 says: test src/lib.rs - (line 3) ... ok

1 Like

Yes indeed, that's much better. I noticed this also, but I would be even more useful to be able to specify additional text when displayed.