rust-lang / rust-lang/rust

Change behavior of `--exact` doc-tests

Đang mở
#147,653 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

A-doctests A-libtest C-discussion T-testing-devex
Ngôn ngữ chính
Rust
Star
119k
Fork
16.2k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện các lệnh cargo test --doc doc_foo--exact được ghi trong tài liệu, so sánh đầu ra của chúng với cargo test -- --list. Truy vết điểm bắt đầu của việc lọc tên doctest và bổ sung phần bao phủ cho thấy --exact khớp với doc_foo mà không yêu cầu hậu tố dòng đã được escape, đồng thời giữ nguyên hành vi hiện có đối với tên đầy đủ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
cli, testing-qa
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.