Skip to content

Commit db3fec8

Browse files
authored
Merge pull request #1450 from sillsdev/improve-test-reliability
Made a few changes to improve reliability of unit tests
2 parents 2f62f87 + b27e341 commit db3fec8

File tree

54 files changed

+259
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+259
-187
lines changed

AddSortKey/AddSortKey.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
<ItemGroup>
2323
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
24+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
2425
</ItemGroup>
2526

2627
<ItemGroup>

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
## [Unreleased]
1818

19+
### Added
20+
21+
- [SIL.TestUtilities] Added a Create method to TemporaryFolder that takes a TestContext
22+
1923
## [16.1.0] - 2025-07-18
2024

2125
### Added

ExtractCopyright.Tests/ExtractCopyright.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
1313
<PackageReference Include="NUnit" Version="3.13.3" />
1414
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
15+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
1516
</ItemGroup>
1617

1718
<ItemGroup>

ExtractCopyright/CopyrightFile.cs

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// Copyright (c) 2025 SIL Global
22
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
3+
34
using System;
4-
using System.IO;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Text;
8+
using System.Text.RegularExpressions;
9+
using SIL.Acknowledgements;
10+
using static System.String;
711

812
namespace SIL.ExtractCopyright
913
{
@@ -18,22 +22,20 @@ public enum ExitValue {
1822
NoDebianFolder,
1923
NoAssemblyFolder,
2024
NoPrefixFolder
21-
};
25+
}
2226

2327
public CopyrightFile()
2428
{
2529
}
2630

27-
public CopyrightFile(string filename)
28-
: base(filename)
31+
public CopyrightFile(string filename) : base(filename)
2932
{
3033
}
3134

3235
/// <summary>
3336
/// Create or update the copyright file in the given debian folder.
3437
/// </summary>
3538
/// <param name="debianFolder">Debian folder.</param>
36-
/// <param name="assemblyFolder">Assembly folder.</param>
3739
/// <param name="prefixFolder">Prefix folder.</param>
3840
public static int CreateOrUpdateCopyrightFile(string debianFolder, string prefixFolder)
3941
{
@@ -47,17 +49,17 @@ public static int CreateOrUpdateCopyrightFile(string debianFolder, string prefix
4749
var controlFile = new DebianControl(Path.Combine(debianFolder, "control"));
4850
ParseControlContentForValues(controlFile, ref programName, ref contactEmail, ref sourceUrl);
4951
// If necessary, try to read some primary information from the changelog file.
50-
if (String.IsNullOrEmpty(programName) || String.IsNullOrEmpty(contactEmail))
52+
if (IsNullOrEmpty(programName) || IsNullOrEmpty(contactEmail))
5153
{
5254
var lines = File.ReadAllLines(Path.Combine(debianFolder, "changelog"), Encoding.UTF8);
5355
ParseChangelogContentForValues(lines, ref programName, ref contactEmail);
5456
}
5557
// If we can't derive any information, flag it as unknown.
56-
if (String.IsNullOrEmpty(programName))
58+
if (IsNullOrEmpty(programName))
5759
programName = "UNKNOWN";
58-
if (String.IsNullOrEmpty(contactEmail))
60+
if (IsNullOrEmpty(contactEmail))
5961
contactEmail = "UNKNOWN";
60-
if (String.IsNullOrEmpty(sourceUrl))
62+
if (IsNullOrEmpty(sourceUrl))
6163
sourceUrl = "UNKNOWN";
6264
copyrights = CreateNewCopyrightFile(programName, contactEmail, sourceUrl);
6365
copyrights._filepath = Path.Combine(debianFolder, "copyright");
@@ -70,7 +72,7 @@ public static int CreateOrUpdateCopyrightFile(string debianFolder, string prefix
7072
Console.WriteLine("ExtractCopyright: updating existing file at \"{0}\"", copyrights._filepath);
7173
}
7274

73-
var ackDict = SIL.Acknowledgements.AcknowledgementsProvider.CollectAcknowledgements();
75+
var ackDict = AcknowledgementsProvider.CollectAcknowledgements();
7476
foreach (var key in ackDict.Keys)
7577
copyrights.AddOrUpdateParagraphFromAcknowledgement(ackDict[key], prefixFolder);
7678

@@ -101,11 +103,9 @@ internal static void ParseControlContentForValues(DebianControl controlFile, ref
101103
// 1) Vcs-Browser (url to see source code repository in the browser), or if that isn't provided
102104
// 2) HomePage (url to see some sort of project home page in the browser), or if that isn't provided
103105
// 3) Vcs-Git (url to clone git repository on local machine)
104-
var urlField = sourcePara.FindField("Vcs-Browser");
105-
if (urlField == null)
106-
urlField = sourcePara.FindField("HomePage");
107-
if (urlField == null)
108-
urlField = sourcePara.FindField("Vcs-Git");
106+
var urlField = sourcePara.FindField("Vcs-Browser") ??
107+
sourcePara.FindField("HomePage") ??
108+
sourcePara.FindField("Vcs-Git");
109109
if (urlField != null)
110110
sourceUrl = urlField.Value;
111111
}
@@ -118,22 +118,22 @@ internal static void ParseChangelogContentForValues(string[] lines, ref string p
118118
{
119119
// The first line of an entry in the changelog looks like this:
120120
// "bloom-desktop-alpha (3.9.0) stable; urgency=medium"
121-
if (String.IsNullOrEmpty(programName) && lines[i].Contains(" urgency=") && lines[i].Contains(";"))
121+
if (IsNullOrEmpty(programName) && lines[i].Contains(" urgency=") && lines[i].Contains(";"))
122122
{
123-
var headerPieces = lines[i].Trim().Split(new char[]{' '});
123+
var headerPieces = lines[i].Trim().Split(' ');
124124
programName = headerPieces[i];
125125
}
126126
// The closing line of an entry in the changelog looks like this:
127127
// " -- Stephen McConnel <stephen_mcconnel@sil.org> Wed, 18 Jan 2017 11:38:31 -0600"
128128
// the two spaces following the <email@address> are significant
129-
else if (String.IsNullOrEmpty(contactEmail) && lines[i].StartsWith(" -- ") && lines[i].Contains("@"))
129+
else if (IsNullOrEmpty(contactEmail) && lines[i].StartsWith(" -- ") && lines[i].Contains("@"))
130130
{
131131
var line = lines[i].Substring(4).Trim();
132-
var idx = line.IndexOf(" ");
132+
var idx = line.IndexOf(" ", StringComparison.Ordinal);
133133
if (idx > 0)
134134
contactEmail = line.Substring(0, idx);
135135
}
136-
if (!String.IsNullOrEmpty(programName) && !String.IsNullOrEmpty(contactEmail))
136+
if (!IsNullOrEmpty(programName) && !IsNullOrEmpty(contactEmail))
137137
return;
138138
}
139139
}
@@ -156,7 +156,7 @@ public static CopyrightFile CreateNewCopyrightFile(string programName, string co
156156
para.Fields.Add(new DebianField("Source", sourceUrl));
157157

158158
// REVIEW: can we assume these values?
159-
var programCopyright = String.Format("{0} SIL Global", DateTime.Now.Year);
159+
var programCopyright = Format("{0} SIL Global", DateTime.Now.Year);
160160
var programLicense = "MIT";
161161

162162
para = new DebianParagraph();
@@ -170,10 +170,10 @@ public static CopyrightFile CreateNewCopyrightFile(string programName, string co
170170
return copyrights;
171171
}
172172

173-
internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.AcknowledgementAttribute ack, string prefix)
173+
internal void AddOrUpdateParagraphFromAcknowledgement(AcknowledgementAttribute ack, string prefix)
174174
{
175-
string fileSpec = null;
176-
if (!string.IsNullOrEmpty(ack.Location))
175+
string fileSpec;
176+
if (!IsNullOrEmpty(ack.Location))
177177
{
178178
fileSpec = ack.Location;
179179
if (!fileSpec.StartsWith("/"))
@@ -183,7 +183,7 @@ internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.Acknowled
183183
{
184184
fileSpec = ack.Key;
185185
}
186-
if (!String.IsNullOrEmpty(prefix))
186+
if (!IsNullOrEmpty(prefix))
187187
fileSpec = Path.Combine(prefix, fileSpec);
188188

189189
if (IsWindowsSpecific(Path.GetFileName(fileSpec)))
@@ -207,18 +207,14 @@ internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.Acknowled
207207
Paragraphs.Add(para);
208208
para.Fields.Add(new DebianField("Files", fileSpec));
209209

210-
string person;
211-
string year;
212-
ExtractCopyrightInformation(ack.Copyright, out person, out year);
210+
ExtractCopyrightInformation(ack.Copyright, out var person, out var year);
213211
var copyright = year + " " + person;
214212
para.Fields.Add(new DebianField("Copyright", copyright));
215213

216-
string shortLicense;
217-
List<string> longLicense;
218-
ExtractLicenseInformation(ack.LicenseUrl, out shortLicense, out longLicense);
214+
ExtractLicenseInformation(ack.LicenseUrl, out var shortLicense, out var longLicense);
219215
para.Fields.Add(new DebianField("License", shortLicense));
220216

221-
if (!string.IsNullOrEmpty(ack.Url))
217+
if (!IsNullOrEmpty(ack.Url))
222218
para.Fields.Add(new DebianField("Comment", "URL = " + ack.Url));
223219

224220
if (shortLicense != "????" && longLicense.Count > 0)
@@ -227,7 +223,7 @@ internal void AddOrUpdateParagraphFromAcknowledgement(Acknowledgements.Acknowled
227223
}
228224
}
229225

230-
private bool IsWindowsSpecific(string name)
226+
private static bool IsWindowsSpecific(string name)
231227
{
232228
switch (name)
233229
{
@@ -261,19 +257,15 @@ internal void AddLicenseParagraphIfNeeded(string license, IEnumerable<string> de
261257
}
262258

263259
private void UpdateParagraphFromAcknowledgement(DebianParagraph para,
264-
Acknowledgements.AcknowledgementAttribute ack)
260+
AcknowledgementAttribute ack)
265261
{
266-
string person;
267-
string year;
268-
ExtractCopyrightInformation(ack.Copyright, out person, out year);
262+
ExtractCopyrightInformation(ack.Copyright, out var person, out var year);
269263
if (year == "????")
270264
return; // we don't know if this information is newer or not
271265
var copyrightField = para.FindField("Copyright");
272266
if (copyrightField != null)
273267
{
274-
string prevYear;
275-
string prevPerson;
276-
ExtractCopyrightInformation(copyrightField.Value, out prevYear, out prevPerson);
268+
ExtractCopyrightInformation(copyrightField.Value, out var prevYear, out _);
277269
if (prevYear == "????" || prevYear.CompareTo(year) < 0)
278270
{
279271
copyrightField.Value = year + " " + person;
@@ -284,9 +276,7 @@ private void UpdateParagraphFromAcknowledgement(DebianParagraph para,
284276
}
285277
}
286278

287-
string shortLicense;
288-
List<string> longLicense;
289-
ExtractLicenseInformation(ack.LicenseUrl, out shortLicense, out longLicense);
279+
ExtractLicenseInformation(ack.LicenseUrl, out var shortLicense, out var longLicense);
290280
if (shortLicense != "????")
291281
{
292282
var licenseField = para.FindField("License");
@@ -296,7 +286,7 @@ private void UpdateParagraphFromAcknowledgement(DebianParagraph para,
296286
AddLicenseParagraphIfNeeded(shortLicense, longLicense);
297287
}
298288

299-
if (!string.IsNullOrEmpty(ack.Url))
289+
if (!IsNullOrEmpty(ack.Url))
300290
{
301291
var commentField = para.FindField("Comment");
302292
if (commentField == null)
@@ -318,7 +308,7 @@ private void ExtractCopyrightInformation(string original, out string person, out
318308
copyright = copyright.Replace("(c)", "");
319309
copyright = copyright.Replace("©", "");
320310
// extract year and person if present
321-
var match = System.Text.RegularExpressions.Regex.Match(copyright, "([0-9][0-9][0-9][0-9][-0-9]*)");
311+
var match = Regex.Match(copyright, "([0-9][0-9][0-9][0-9][-0-9]*)");
322312
if (match.Success)
323313
{
324314
year = copyright.Substring(match.Index, match.Length);
@@ -329,15 +319,15 @@ private void ExtractCopyrightInformation(string original, out string person, out
329319
person = copyright;
330320
}
331321
person = person.Trim();
332-
if (string.IsNullOrEmpty(person))
322+
if (IsNullOrEmpty(person))
333323
person = "????";
334324
}
335325

336326
private void ExtractLicenseInformation(string original, out string shortLicense, out List<string> longLicense)
337327
{
338328
shortLicense = "????";
339329
longLicense = new List<string>();
340-
if (!string.IsNullOrEmpty(original))
330+
if (!IsNullOrEmpty(original))
341331
{
342332
shortLicense = original;
343333
var idx = shortLicense.LastIndexOf('/');
@@ -362,7 +352,7 @@ private void ExtractLicenseInformation(string original, out string shortLicense,
362352
/// <summary>
363353
/// The standard MIT license used for SIL software.
364354
/// </summary>
365-
public static string[] StandardMITLicense = new string[] {
355+
public static string[] StandardMITLicense = {
366356
"Permission is hereby granted, free of charge, to any person obtaining a",
367357
"copy of this software and associated documentation files (the \"Software\"),",
368358
"to deal in the Software without restriction, including without limitation",

ExtractCopyright/ExtractCopyright.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
16+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
1617
</ItemGroup>
1718

1819
<ItemGroup>

SIL.Archiving.Tests/SIL.Archiving.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
1919
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
2020
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
21+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
2122
</ItemGroup>
2223

2324
<ItemGroup>

SIL.Archiving/SIL.Archiving.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
<PackageReference Include="SIL.ReleaseTasks" Version="3.1.1" PrivateAssets="All" />
2929
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
3030
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
31-
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
3231
<PackageReference Include="System.Memory" Version="4.5.5" />
32+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
3333
</ItemGroup>
3434
<ItemGroup>
3535
<ProjectReference Include="..\SIL.Core.Desktop\SIL.Core.Desktop.csproj" />

SIL.Core.Desktop.Tests/SIL.Core.Desktop.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<PackageReference Include="NDesk.DBus" Version="0.15.0" />
1616
<PackageReference Include="NUnit" Version="3.13.3" />
1717
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
18+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
1819
</ItemGroup>
1920

2021
<ItemGroup>

SIL.Core.Desktop/SIL.Core.Desktop.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
2121
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
2222
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
23+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
2324
</ItemGroup>
2425
<ItemGroup>
2526
<ProjectReference Include="..\SIL.Core\SIL.Core.csproj" />

SIL.Core.Tests/SIL.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageReference Include="NUnit" Version="3.13.3" />
1717
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
1818
<PackageReference Include="SIL.ReleaseTasks" Version="3.1.1" PrivateAssets="All" />
19+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
1920
</ItemGroup>
2021

2122
<ItemGroup>

0 commit comments

Comments
 (0)