rust-lang / rust-lang/rust

Change behavior of `--exact` doc-tests

オープン
#147,653 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

A-doctests A-libtest C-discussion T-testing-devex
主要言語
Rust
スター
119k
フォーク
16.2k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、ドキュメントに記載された cargo test --doc doc_foo--exact のコマンドを再現し、その出力を cargo test -- --list と比較します。doctest の名前フィルタリングのエントリポイントを追跡し、既存の完全な名前に対する動作を維持しつつ、--exact がエスケープされた行サフィックスを必要とせずに doc_foo に一致することを示すカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
cli, testing-qa
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。