Skip to content

Commit cf200cf

Browse files
committed
refactoring
1 parent 4bb46b4 commit cf200cf

File tree

4 files changed

+189
-177
lines changed

4 files changed

+189
-177
lines changed

test/coverlet.core.coverage.tests/Coverage/CoverageTests.AutoProps.cs

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -60,143 +60,5 @@ public void SkipAutoProps(bool skipAutoProps)
6060
File.Delete(path);
6161
}
6262
}
63-
64-
[Theory]
65-
[InlineData(true)]
66-
[InlineData(false)]
67-
public void SkipAutoPropsInRecords(bool skipAutoProps)
68-
{
69-
string path = Path.GetTempFileName();
70-
try
71-
{
72-
FunctionExecutor.RunInProcess(async (string[] parameters) =>
73-
{
74-
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<RecordWithPropertyInit>(instance =>
75-
{
76-
instance.RecordAutoPropsNonInit = string.Empty;
77-
instance.RecordAutoPropsInit = string.Empty;
78-
string readValue = instance.RecordAutoPropsInit;
79-
readValue = instance.RecordAutoPropsNonInit;
80-
return Task.CompletedTask;
81-
},
82-
persistPrepareResultToFile: parameters[0], skipAutoProps: bool.Parse(parameters[1]));
83-
84-
return 0;
85-
}, [path, skipAutoProps.ToString()]);
86-
87-
if (skipAutoProps)
88-
{
89-
TestInstrumentationHelper.GetCoverageResult(path)
90-
.GenerateReport(show:true)
91-
.Document("Instrumentation.AutoProps.cs")
92-
.AssertNonInstrumentedLines(BuildConfiguration.Debug, 23, 24)
93-
.AssertNonInstrumentedLines(BuildConfiguration.Release, 23, 24)
94-
.AssertLinesCovered(BuildConfiguration.Debug, (18, 1), (20, 1), (21, 1), (22, 1))
95-
.AssertLinesCovered(BuildConfiguration.Release, (21, 1));
96-
}
97-
else
98-
{
99-
TestInstrumentationHelper.GetCoverageResult(path)
100-
.GenerateReport(show: true)
101-
.Document("Instrumentation.AutoProps.cs")
102-
.AssertLinesCoveredFromTo(BuildConfiguration.Debug, 18, 24)
103-
.AssertLinesCoveredFromTo(BuildConfiguration.Release, 21, 21)
104-
.AssertLinesCoveredFromTo(BuildConfiguration.Release, 23, 24);
105-
}
106-
}
107-
finally
108-
{
109-
File.Delete(path);
110-
}
111-
}
112-
113-
[Theory]
114-
[InlineData(true)]
115-
[InlineData(false)]
116-
public void SkipRecordWithProperties(bool skipAutoProps)
117-
{
118-
string path = Path.GetTempFileName();
119-
try
120-
{
121-
FunctionExecutor.RunInProcess(async (string[] parameters) =>
122-
{
123-
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<ClassWithRecordsAutoProperties>(instance =>
124-
{
125-
return Task.CompletedTask;
126-
},
127-
persistPrepareResultToFile: parameters[0], skipAutoProps: bool.Parse(parameters[1]));
128-
129-
return 0;
130-
}, [path, skipAutoProps.ToString()]);
131-
132-
if (skipAutoProps)
133-
{
134-
TestInstrumentationHelper.GetCoverageResult(path)
135-
.GenerateReport(show: true)
136-
.Document("Instrumentation.AutoProps.cs")
137-
.AssertNonInstrumentedLines(BuildConfiguration.Debug, 29, 29)
138-
.AssertNonInstrumentedLines(BuildConfiguration.Release, 29, 29)
139-
.AssertLinesCovered(BuildConfiguration.Debug, (32, 1), (33, 1), (34, 1))
140-
.AssertLinesCovered(BuildConfiguration.Release, (33, 1));
141-
}
142-
else
143-
{
144-
TestInstrumentationHelper.GetCoverageResult(path)
145-
.GenerateReport(show: true)
146-
.Document("Instrumentation.AutoProps.cs")
147-
.AssertLinesCovered(BuildConfiguration.Debug, (29, 1), (31, 1), (32, 1), (33, 1), (34, 1))
148-
.AssertLinesCovered(BuildConfiguration.Release, (29, 1), (31, 1), (33, 1));
149-
}
150-
}
151-
finally
152-
{
153-
File.Delete(path);
154-
}
155-
}
156-
157-
[Theory]
158-
[InlineData(true)]
159-
[InlineData(false)]
160-
public void SkipInheritingRecordsWithProperties(bool skipAutoProps)
161-
{
162-
string path = Path.GetTempFileName();
163-
try
164-
{
165-
FunctionExecutor.RunInProcess(async (string[] parameters) =>
166-
{
167-
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<ClassWithInheritingRecordsAndAutoProperties>(instance =>
168-
{
169-
return Task.CompletedTask;
170-
},
171-
persistPrepareResultToFile: parameters[0], skipAutoProps: bool.Parse(parameters[1]));
172-
173-
return 0;
174-
}, [path, skipAutoProps.ToString()]);
175-
176-
if (skipAutoProps)
177-
{
178-
TestInstrumentationHelper.GetCoverageResult(path)
179-
.GenerateReport(show: true)
180-
.Document("Instrumentation.AutoProps.cs")
181-
.AssertNonInstrumentedLines(BuildConfiguration.Debug, 39, 39)
182-
.AssertNonInstrumentedLines(BuildConfiguration.Release, 39, 39)
183-
.AssertLinesCovered(BuildConfiguration.Debug, (41, 1), (44, 1), (45, 1), (46, 1))
184-
.AssertLinesCovered(BuildConfiguration.Release, (45, 1));
185-
186-
}
187-
else
188-
{
189-
TestInstrumentationHelper.GetCoverageResult(path)
190-
.GenerateReport(show: true)
191-
.Document("Instrumentation.AutoProps.cs")
192-
.AssertLinesCovered(BuildConfiguration.Debug, (39, 1), (41, 1), (44, 1), (45, 1), (46, 1))
193-
.AssertLinesCovered(BuildConfiguration.Release, (39, 1), (41, 1), (45, 1));
194-
}
195-
}
196-
finally
197-
{
198-
File.Delete(path);
199-
}
200-
}
20163
}
20264
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Copyright (c) Toni Solarin-Sodara
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using Coverlet.Core.CoverageSamples.Tests;
7+
using Coverlet.Core.Tests;
8+
using Coverlet.Core;
9+
using Coverlet.Tests.Utils;
10+
using Xunit;
11+
12+
namespace Coverlet.CoreCoverage.Tests
13+
{
14+
public partial class CoverageTests
15+
{
16+
[Theory]
17+
[InlineData(true)]
18+
[InlineData(false)]
19+
public void SkipAutoPropsInRecords(bool skipAutoProps)
20+
{
21+
string path = Path.GetTempFileName();
22+
try
23+
{
24+
FunctionExecutor.RunInProcess(async (string[] parameters) =>
25+
{
26+
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<RecordWithPropertyInit>(instance =>
27+
{
28+
instance.RecordAutoPropsNonInit = string.Empty;
29+
instance.RecordAutoPropsInit = string.Empty;
30+
string readValue = instance.RecordAutoPropsInit;
31+
readValue = instance.RecordAutoPropsNonInit;
32+
return Task.CompletedTask;
33+
},
34+
persistPrepareResultToFile: parameters[0], skipAutoProps: bool.Parse(parameters[1]));
35+
36+
return 0;
37+
}, [path, skipAutoProps.ToString()]);
38+
39+
if (skipAutoProps)
40+
{
41+
TestInstrumentationHelper.GetCoverageResult(path)
42+
.GenerateReport(show: true)
43+
.Document("Instrumentation.Records.cs")
44+
.AssertNonInstrumentedLines(BuildConfiguration.Debug, 23, 24)
45+
.AssertNonInstrumentedLines(BuildConfiguration.Release, 23, 24)
46+
.AssertLinesCovered(BuildConfiguration.Debug, (18, 1), (20, 1), (21, 1), (22, 1))
47+
.AssertLinesCovered(BuildConfiguration.Release, (21, 1));
48+
}
49+
else
50+
{
51+
TestInstrumentationHelper.GetCoverageResult(path)
52+
.GenerateReport(show: true)
53+
.Document("Instrumentation.Records.cs")
54+
.AssertLinesCoveredFromTo(BuildConfiguration.Debug, 18, 24)
55+
.AssertLinesCoveredFromTo(BuildConfiguration.Release, 21, 21)
56+
.AssertLinesCoveredFromTo(BuildConfiguration.Release, 23, 24);
57+
}
58+
}
59+
finally
60+
{
61+
File.Delete(path);
62+
}
63+
}
64+
65+
[Theory]
66+
[InlineData(true)]
67+
[InlineData(false)]
68+
public void SkipRecordWithProperties(bool skipAutoProps)
69+
{
70+
string path = Path.GetTempFileName();
71+
try
72+
{
73+
FunctionExecutor.RunInProcess(async (string[] parameters) =>
74+
{
75+
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<ClassWithRecordsAutoProperties>(instance =>
76+
{
77+
return Task.CompletedTask;
78+
},
79+
persistPrepareResultToFile: parameters[0], skipAutoProps: bool.Parse(parameters[1]));
80+
81+
return 0;
82+
}, [path, skipAutoProps.ToString()]);
83+
84+
if (skipAutoProps)
85+
{
86+
TestInstrumentationHelper.GetCoverageResult(path)
87+
.GenerateReport(show: true)
88+
.Document("Instrumentation.Records.cs")
89+
.AssertNonInstrumentedLines(BuildConfiguration.Debug, 29, 29)
90+
.AssertNonInstrumentedLines(BuildConfiguration.Release, 29, 29)
91+
.AssertLinesCovered(BuildConfiguration.Debug, (32, 1), (33, 1), (34, 1))
92+
.AssertLinesCovered(BuildConfiguration.Release, (33, 1));
93+
}
94+
else
95+
{
96+
TestInstrumentationHelper.GetCoverageResult(path)
97+
.GenerateReport(show: true)
98+
.Document("Instrumentation.Records.cs")
99+
.AssertLinesCovered(BuildConfiguration.Debug, (29, 1), (31, 1), (32, 1), (33, 1), (34, 1))
100+
.AssertLinesCovered(BuildConfiguration.Release, (29, 1), (31, 1), (33, 1));
101+
}
102+
}
103+
finally
104+
{
105+
File.Delete(path);
106+
}
107+
}
108+
109+
[Theory]
110+
[InlineData(true)]
111+
[InlineData(false)]
112+
public void SkipInheritingRecordsWithProperties(bool skipAutoProps)
113+
{
114+
string path = Path.GetTempFileName();
115+
try
116+
{
117+
FunctionExecutor.RunInProcess(async (string[] parameters) =>
118+
{
119+
CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run<ClassWithInheritingRecordsAndAutoProperties>(instance =>
120+
{
121+
return Task.CompletedTask;
122+
},
123+
persistPrepareResultToFile: parameters[0], skipAutoProps: bool.Parse(parameters[1]));
124+
125+
return 0;
126+
}, [path, skipAutoProps.ToString()]);
127+
128+
if (skipAutoProps)
129+
{
130+
TestInstrumentationHelper.GetCoverageResult(path)
131+
.GenerateReport(show: true)
132+
.Document("Instrumentation.Records.cs")
133+
.AssertNonInstrumentedLines(BuildConfiguration.Debug, 39, 39)
134+
.AssertNonInstrumentedLines(BuildConfiguration.Release, 39, 39)
135+
.AssertLinesCovered(BuildConfiguration.Debug, (41, 1), (44, 1), (45, 1), (46, 1))
136+
.AssertLinesCovered(BuildConfiguration.Release, (45, 1));
137+
138+
}
139+
else
140+
{
141+
TestInstrumentationHelper.GetCoverageResult(path)
142+
.GenerateReport(show: true)
143+
.Document("Instrumentation.Records.cs")
144+
.AssertLinesCovered(BuildConfiguration.Debug, (39, 1), (41, 1), (44, 1), (45, 1), (46, 1))
145+
.AssertLinesCovered(BuildConfiguration.Release, (39, 1), (41, 1), (45, 1));
146+
}
147+
}
148+
finally
149+
{
150+
File.Delete(path);
151+
}
152+
}
153+
}
154+
}

test/coverlet.core.coverage.tests/Samples/Instrumentation.AutoProps.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,38 @@ public AutoProps()
1313
public int AutoPropsInit { get; set; } = 10;
1414
}
1515

16-
public record RecordWithPropertyInit
17-
{
18-
private int _myRecordVal = 0;
19-
public RecordWithPropertyInit()
20-
{
21-
_myRecordVal = new Random().Next();
22-
}
23-
public string RecordAutoPropsNonInit { get; set; }
24-
public string RecordAutoPropsInit { get; set; } = string.Empty;
25-
}
26-
27-
public class ClassWithRecordsAutoProperties
28-
{
29-
record RecordWithPrimaryConstructor(string Prop1, string Prop2);
30-
31-
public ClassWithRecordsAutoProperties()
32-
{
33-
var record = new RecordWithPrimaryConstructor(string.Empty, string.Empty);
34-
}
35-
}
36-
37-
public class ClassWithInheritingRecordsAndAutoProperties
38-
{
39-
record BaseRecord(int A);
40-
41-
record InheritedRecord(int A) : BaseRecord(A);
42-
43-
public ClassWithInheritingRecordsAndAutoProperties()
44-
{
45-
var record = new InheritedRecord(1);
46-
}
47-
}
16+
//public record RecordWithPropertyInit
17+
//{
18+
// private int _myRecordVal = 0;
19+
// public RecordWithPropertyInit()
20+
// {
21+
// _myRecordVal = new Random().Next();
22+
// }
23+
// public string RecordAutoPropsNonInit { get; set; }
24+
// public string RecordAutoPropsInit { get; set; } = string.Empty;
25+
//}
26+
27+
//public class ClassWithRecordsAutoProperties
28+
//{
29+
// record RecordWithPrimaryConstructor(string Prop1, string Prop2);
30+
31+
// public ClassWithRecordsAutoProperties()
32+
// {
33+
// var record = new RecordWithPrimaryConstructor(string.Empty, string.Empty);
34+
// }
35+
//}
36+
37+
//public class ClassWithInheritingRecordsAndAutoProperties
38+
//{
39+
// record BaseRecord(int A);
40+
41+
// record InheritedRecord(int A) : BaseRecord(A);
42+
43+
// public ClassWithInheritingRecordsAndAutoProperties()
44+
// {
45+
// var record = new InheritedRecord(1);
46+
// }
47+
//}
4848

4949

5050
}

test/coverlet.core.coverage.tests/Samples/Instrumentation.Records.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

73
namespace Coverlet.Core.CoverageSamples.Tests
84
{
@@ -54,14 +50,14 @@ internal record Second()
5450

5551
public class ClassWithAbstractRecords
5652
{
57-
public abstract record AuditData()
53+
public abstract record FirstAuditData()
5854
{
5955
public abstract string GetAuditType();
6056
}
6157

62-
public abstract record AuditData
58+
public abstract record SecondAuditData
6359
{
64-
private protected AuditData()
60+
private protected SecondAuditData()
6561
{
6662

6763
}

0 commit comments

Comments
 (0)