Skip to content

Commit 3be32d6

Browse files
authored
Issue914 (#922)
* Fix issue #914 * Adding Linux safety belt * SA error fixed
1 parent 597fe01 commit 3be32d6

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

build.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var configuration = Argument("configuration", "Release");
1313
//////////////////////////////////////////////////////////////////////
1414

1515
var version = "4.2.0";
16-
var modifier = "-alpha.1";
16+
var modifier = "-alpha.201";
1717

1818
var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
1919
var packageVersion = version + modifier + dbgSuffix;

src/NUnitTestAdapter/AdapterSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public interface IAdapterSettings
118118
void Load(string settingsXml);
119119
void SaveRandomSeed(string dirname);
120120
void RestoreRandomSeed(string dirname);
121+
122+
bool EnsureAttachmentFileScheme { get; }
121123
}
122124

123125
public enum VsTestCategoryType
@@ -325,6 +327,7 @@ public void Load(string settingsXml)
325327
StopOnError = GetInnerTextAsBool(nunitNode, nameof(StopOnError), false);
326328
UseNUnitFilter = GetInnerTextAsBool(nunitNode, nameof(UseNUnitFilter), true);
327329
IncludeStackTraceForSuites = GetInnerTextAsBool(nunitNode, nameof(IncludeStackTraceForSuites), true);
330+
EnsureAttachmentFileScheme = GetInnerTextAsBool(nunitNode, nameof(IncludeStackTraceForSuites), false);
328331

329332
// Engine settings
330333
DiscoveryMethod = MapEnum(GetInnerText(nunitNode, nameof(DiscoveryMethod), Verbosity > 0), DiscoveryMethod.Current);
@@ -472,6 +475,8 @@ public void RestoreRandomSeed(string dirname)
472475
}
473476
}
474477

478+
public bool EnsureAttachmentFileScheme { get; private set; }
479+
475480
#endregion
476481

477482
#region Helper Methods
@@ -508,7 +513,7 @@ private string GetInnerText(XmlNode startNode, string xpath, bool log, params st
508513
{
509514
val = targetNode.InnerText;
510515

511-
if (validValues != null && validValues.Length > 0)
516+
if (validValues is { Length: > 0 })
512517
{
513518
foreach (string valid in validValues)
514519
{

src/NUnitTestAdapter/TestConverter.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,21 @@ private AttachmentSet ParseAttachments(INUnitTestEvent resultNode)
350350

351351
foreach (var attachment in resultNode.NUnitAttachments)
352352
{
353-
var path = attachment.FilePath;
354353
var description = attachment.Description;
355-
356-
if (!(string.IsNullOrEmpty(path) || path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase)))
354+
var path = attachment.FilePath;
355+
if (adapterSettings.EnsureAttachmentFileScheme)
356+
{
357+
if (!(string.IsNullOrEmpty(path) ||
358+
path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase)))
359+
{
360+
path = fileUriScheme + path;
361+
}
362+
}
363+
// For Linux paths
364+
if (!(string.IsNullOrEmpty(path) || path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase)) && !path.Contains(':'))
357365
{
358366
path = fileUriScheme + path;
359367
}
360-
361368
try
362369
{
363370
// We only support absolute paths since we dont lookup working directory here

src/NUnitTestAdapterTests/Fakes/FakeTestData.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ private static void FakeTestCase() { } // LineNumber should be this line
160160
<filePath>file:///home/results/att.log</filePath>
161161
<description>lin, with scheme</description>
162162
</attachment>
163+
<attachment>
164+
<filePath>C:\Windows\WindowsUpdate.log</filePath>
165+
<description>win, Issue914</description>
166+
</attachment>
163167
<attachment>
164168
<filePath></filePath>
165169
<description>empty path</description>

src/NUnitTestAdapterTests/TestConverterTests.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,40 +211,26 @@ public void Attachments_CorrectAmountOfConvertedAttachments()
211211
var fakeAttachments = fakeResultNode.NUnitAttachments
212212
.Where(n => !string.IsNullOrEmpty(n.FilePath))
213213
.ToArray();
214-
214+
TestContext.Out.WriteLine("Incoming attachments");
215+
foreach (var attachment in fakeAttachments)
216+
{
217+
TestContext.Out.WriteLine($"{attachment.FilePath}");
218+
}
215219
var convertedAttachments = testResults.TestResults
216220
.SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
217221
.ToArray();
218-
222+
TestContext.Out.WriteLine("\nConverted attachments (Uri, path)");
223+
foreach (var attachment in convertedAttachments)
224+
{
225+
TestContext.Out.WriteLine($"{attachment.Uri.AbsoluteUri} : {attachment.Uri.LocalPath}");
226+
}
219227
Assert.Multiple(() =>
220228
{
221229
Assert.That(convertedAttachments.Length, Is.GreaterThan(0), "Some converted attachments were expected");
222230
Assert.That(convertedAttachments.Length, Is.EqualTo(fakeAttachments.Length), "Attachments are not converted");
223231
});
224232
}
225233

226-
[Test]
227-
public void Attachments_AllFilePathesStartWithFileScheme()
228-
{
229-
const string fileUriScheme = "file://";
230-
const string errorMessage = "Path must start with file:// uri scheme";
231-
232-
var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
233-
var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode().AsString());
234-
235-
var testResults = testConverter.GetVsTestResults(fakeResultNode, Enumerable.Empty<INUnitTestEventTestOutput>().ToList());
236-
237-
var convertedAttachments = testResults.TestResults
238-
.SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
239-
.ToArray();
240-
241-
foreach (var attachment in convertedAttachments)
242-
{
243-
var originalPath = attachment.Uri.OriginalString;
244-
Assert.That(originalPath.LastIndexOf(fileUriScheme), Is.EqualTo(0), errorMessage);
245-
}
246-
}
247-
248234
#endregion Attachment tests
249235

250236
private void CheckTestCase(TestCase testCase)

0 commit comments

Comments
 (0)