Add support for UnreachableException in .NET code
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- csharp
- Lĩnh vực
- testing-qa, tooling
Hướng nghiên cứu
Issue không nêu tên tệp nào trong repository, test hay entry point. Hãy bắt đầu với ví dụ switch trong C# và các tham chiếu UnreachableException được liên kết, sau đó lần theo cách các công cụ coverage tạo ra XML được hiển thị; công việc được xem là hoàn thành khi các đường đi UnreachableException bị loại khỏi các dòng và branch có thể được đo coverage như trong output mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
.NET 7 added the UnreachableException class, which is meant to be thrown when executing a branch that isn't isn't expected to execute, due to the developer believing it to be unreachable. The Microsoft code coverage tools should analyze code that throws UnreachableException and reduce the number of coverable lines and branches accordingly.
Consider the following example:
using System.Diagnostics;
enum E
{
A,
B,
C,
}
static partial class C
{
public static void M()
{
E value = GetValue();
switch (value) // line 16
{
case E.A:
PerformActionA();
break;
case E.B:
PerformActionB();
break;
case E.C:
PerformActionC();
break;
default:
throw new UnreachableException(); // line 31
}
}
}
Currently, this will yield coverage data for M() like so:
<method line-rate="0.9090909090909091" branch-rate="0.75" complexity="4" name="M" signature="()">
<lines>
<line number="13" hits="1" branch="False" />
<line number="14" hits="1" branch="False" />
<line number="16" hits="1" branch="True" condition-coverage="75% (3/4)">
<conditions>
<condition number="0" type="switch" coverage="75%" />
</conditions>
</line>
<line number="19" hits="1" branch="False" />
<line number="20" hits="1" branch="False" />
<line number="23" hits="1" branch="False" />
<line number="24" hits="1" branch="False" />
<line number="27" hits="1" branch="False" />
<line number="28" hits="1" branch="False" />
<line number="31" hits="0" branch="False" />
<line number="33" hits="1" branch="False" />
</lines>
</method>
We see that the condition on line 16 shows four branches (one of which is the default case and is uncovered) and that line 31 shows no hits. If the developer has otherwise guaranteed that GetValue() will return a valid value of E—one of the known enum cases—and they handle the remaining case in the above sample by throwing UnreachableException, the code coverage findings should reflect that. Given the above example, if the code coverage tools were aware of UnreachableException, I would instead expect to see the following coverage data:
<method line-rate="1" branch-rate="1" complexity="4" name="M" signature="()">
<lines>
<line number="13" hits="1" branch="False" />
<line number="14" hits="1" branch="False" />
<line number="16" hits="1" branch="True" condition-coverage="100% (3/3)">
<conditions>
<condition number="0" type="switch" coverage="100%" />
</conditions>
</line>
<line number="19" hits="1" branch="False" />
<line number="20" hits="1" branch="False" />
<line number="23" hits="1" branch="False" />
<line number="24" hits="1" branch="False" />
<line number="27" hits="1" branch="False" />
<line number="28" hits="1" branch="False" />
<line number="33" hits="1" branch="False" />
</lines>
</method>
Recognizing the developer's intent with regards to intentionally unreachable code will provide for more accurate code coverage results, and will make the tooling more usable for teams who want to enforce 100% code coverage in their test suites.
References:
- Ngôn ngữ chính
- C#
- Star
- 125
- Fork
- 17
- Merge trung bình
- 1 giờ 17 phút
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/codecoverage
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
microsoft/codecoverage#246 · 6 bình luận ·
-
Forward SIGTERM to child process Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
microsoft/codecoverage#237 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
microsoft/codecoverage#234 · 1 bình luận · 2 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
microsoft/codecoverage#233 · 2 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
microsoft/codecoverage#232 · 6 bình luận ·
Tất cả issue của microsoft/codecoverage
Issue tương tự
-
bug documentation frontend
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
azurenoops/spin_agent#975 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SubtitleEdit/subtitleedit#15108 · 1 bình luận ·
-
area/docs-content Bug pulumi/docs
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 94/100