-
Notifications
You must be signed in to change notification settings - Fork 392
Add switch test #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add switch test #526
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ public void TestCoverageWithTestAssembly() | |
| } | ||
|
|
||
| [Fact] | ||
| public void Condition_If() | ||
| public void SelectionStatements_If() | ||
| { | ||
| // We need to pass file name to remote process where it save instrumentation result | ||
| // Similar to msbuild input/output | ||
|
|
@@ -73,7 +73,7 @@ public void Condition_If() | |
| RemoteExecutor.Invoke(async pathSerialize => | ||
| { | ||
| // Run load and call a delegate passing class as dynamic to simplify method call | ||
| CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<Conditions>(instance => | ||
| CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<SelectionStatements>(instance => | ||
| { | ||
| // We call method to trigger coverage hits | ||
| instance.If(true); | ||
|
|
@@ -91,7 +91,7 @@ public void Condition_If() | |
| CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); | ||
|
|
||
| // Asserts on doc/lines/branches | ||
| result.Document("Instrumentation.cs") | ||
| result.Document("Instrumentation.SelectionStatements.cs") | ||
| // (line, hits) | ||
| .AssertLinesCovered((11, 1), (15, 0)) | ||
| // (line,ordinal,hits) | ||
|
|
@@ -106,5 +106,35 @@ public void Condition_If() | |
| File.Delete(path); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SelectionStatements_Switch() | ||
| { | ||
| string path = Path.GetTempFileName(); | ||
| try | ||
| { | ||
| RemoteExecutor.Invoke(async pathSerialize => | ||
| { | ||
| CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<SelectionStatements>(instance => | ||
| { | ||
| instance.Switch(1); | ||
| return Task.CompletedTask; | ||
| }, pathSerialize); | ||
| return 0; | ||
| }, path).Dispose(); | ||
|
|
||
| CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); | ||
|
|
||
| result.Document("Instrumentation.SelectionStatements.cs") | ||
| .AssertLinesCovered(BuildConfiguration.Release, (24, 1), (26, 0), (28, 0)) | ||
| .AssertBranchesCovered(BuildConfiguration.Release, (24, 1, 1)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it make the test very dependent on the optimisations in the compiler, so they could start breaking on a different SDK version. Since these tests are about matching specific lines it seems better to just use Debug runs and not include any expected outcome for Release runs.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep it's true...talked also with Andrew #396 (comment) and we had same issue in past #389 |
||
| .AssertLinesCovered(BuildConfiguration.Debug, (20, 1), (21, 1), (24, 1), (30, 1)) | ||
| .AssertBranchesCovered(BuildConfiguration.Debug, (21, 0, 0), (21, 1, 1), (21, 2, 0), (21, 3, 0)); | ||
| } | ||
| finally | ||
| { | ||
| File.Delete(path); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Remember to use full name because adding new using directives change line numbers | ||
|
|
||
| namespace Coverlet.Core.Samples.Tests | ||
| { | ||
| public class SelectionStatements | ||
| { | ||
| public int If(bool condition) | ||
| { | ||
| if (condition) | ||
| { | ||
| return 1; | ||
| } | ||
| else | ||
| { | ||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| public int Switch(int caseSwitch) | ||
| { | ||
| switch (caseSwitch) | ||
| { | ||
| case 1: | ||
| return 1; | ||
| case 2: | ||
| return 2; | ||
| default: | ||
| return 0; | ||
| } | ||
| } | ||
| } | ||
| } |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.