rust-lang / rust-lang/rust

Change behavior of `--exact` doc-tests

Aperta
#147,653 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

A-doctests A-libtest C-discussion T-testing-devex
Lingua principale
Rust
Stelle
119k
Fork
16.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Problem

I have this code:

#[test]
fn foo() {}

#[test]
fn foo_more() {}

/// ```
/// let foo = 10;
/// ```
fn doc_foo() {}

/// ```
/// let foo_more = 10;
/// ```
fn doc_foo_more() {}

Command cargo test foo runs both (non-doc) tests. Command cargo test foo -- --exact runs 1 test named foo.

Command cargo test --doc doc_foo runs both doc tests. Command cargo test --doc doc_foo -- --exact doesn't run any tests, but I expect it to run 1 doc test named doc_foo.

cargo test -- --list shows this 4 tests:

foo: test
foo_more: test

src\lib.rs - doc_foo (line 7): test
src\lib.rs - doc_foo_more (line 12): test

I am able to run specific doc test named doc_foo using cargo test --doc 'doc_foo\ (line\ 7)' thanks to this issue on rust-lang.org.

This solution is not ideal imo because of the need for escape sequences and line number. I think its very hard to use this in complex cases such as doctests in structs or inline modules, basically places with namespace nesting.

This issue originates from my issue in rust-analyzer but the more I think about it, the more I feel like this problem is not about rust-analyzer. It's too tedious to run specific doc test even manually in a shell.

Proposed Solution

Change behavior of --exact flag to match only the name of the test in doc tests by default as it does in non-doc tests.

  • This solution still allows to run specific test if you modify test name to match 'test_name\ (line\ 4)'
  • Currently existing scripts will remain unchanged
Notes

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo i comandi documentati cargo test --doc doc_foo e --exact, confrontando il loro output con quello di cargo test -- --list. Segui il punto di ingresso del filtraggio dei nomi dei doctest e aggiungi una copertura che dimostri che --exact corrisponde a doc_foo senza richiedere il suffisso di riga con escape, preservando al contempo il comportamento esistente per i nomi completi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
cli, testing-qa
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.