Change behavior of `--exact` doc-tests
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Rust
- Sterne
- 119k
- Forks
- 16.1k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die dokumentierten cargo test --doc doc_foo- und --exact-Befehle nachzuvollziehen, und vergleiche ihre Ausgabe mit cargo test -- --list. Verfolge den Einstiegspunkt der Doctest-Namensfilterung und füge eine Testabdeckung hinzu, die zeigt, dass --exact auf doc_foo passt, ohne das maskierte Zeilensuffix zu erfordern, während das bestehende Verhalten für vollständige Namen erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rust
- Bereich
- cli, testing-qa
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100