Skip to content

Commit

Permalink
Issue914 (#922)
Browse files Browse the repository at this point in the history
* Fix issue #914

* Adding Linux safety belt

* SA error fixed
  • Loading branch information
OsirisTerje authored Nov 28, 2021
1 parent 597fe01 commit 3be32d6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////

var version = "4.2.0";
var modifier = "-alpha.1";
var modifier = "-alpha.201";

var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
Expand Down
7 changes: 6 additions & 1 deletion src/NUnitTestAdapter/AdapterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public interface IAdapterSettings
void Load(string settingsXml);
void SaveRandomSeed(string dirname);
void RestoreRandomSeed(string dirname);

bool EnsureAttachmentFileScheme { get; }
}

public enum VsTestCategoryType
Expand Down Expand Up @@ -325,6 +327,7 @@ public void Load(string settingsXml)
StopOnError = GetInnerTextAsBool(nunitNode, nameof(StopOnError), false);
UseNUnitFilter = GetInnerTextAsBool(nunitNode, nameof(UseNUnitFilter), true);
IncludeStackTraceForSuites = GetInnerTextAsBool(nunitNode, nameof(IncludeStackTraceForSuites), true);
EnsureAttachmentFileScheme = GetInnerTextAsBool(nunitNode, nameof(IncludeStackTraceForSuites), false);

// Engine settings
DiscoveryMethod = MapEnum(GetInnerText(nunitNode, nameof(DiscoveryMethod), Verbosity > 0), DiscoveryMethod.Current);
Expand Down Expand Up @@ -472,6 +475,8 @@ public void RestoreRandomSeed(string dirname)
}
}

public bool EnsureAttachmentFileScheme { get; private set; }

#endregion

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

if (validValues != null && validValues.Length > 0)
if (validValues is { Length: > 0 })
{
foreach (string valid in validValues)
{
Expand Down
15 changes: 11 additions & 4 deletions src/NUnitTestAdapter/TestConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,21 @@ private AttachmentSet ParseAttachments(INUnitTestEvent resultNode)

foreach (var attachment in resultNode.NUnitAttachments)
{
var path = attachment.FilePath;
var description = attachment.Description;

if (!(string.IsNullOrEmpty(path) || path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase)))
var path = attachment.FilePath;
if (adapterSettings.EnsureAttachmentFileScheme)
{
if (!(string.IsNullOrEmpty(path) ||
path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase)))
{
path = fileUriScheme + path;
}
}
// For Linux paths
if (!(string.IsNullOrEmpty(path) || path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase)) && !path.Contains(':'))
{
path = fileUriScheme + path;
}

try
{
// We only support absolute paths since we dont lookup working directory here
Expand Down
4 changes: 4 additions & 0 deletions src/NUnitTestAdapterTests/Fakes/FakeTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ private static void FakeTestCase() { } // LineNumber should be this line
<filePath>file:///home/results/att.log</filePath>
<description>lin, with scheme</description>
</attachment>
<attachment>
<filePath>C:\Windows\WindowsUpdate.log</filePath>
<description>win, Issue914</description>
</attachment>
<attachment>
<filePath></filePath>
<description>empty path</description>
Expand Down
34 changes: 10 additions & 24 deletions src/NUnitTestAdapterTests/TestConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,40 +211,26 @@ public void Attachments_CorrectAmountOfConvertedAttachments()
var fakeAttachments = fakeResultNode.NUnitAttachments
.Where(n => !string.IsNullOrEmpty(n.FilePath))
.ToArray();

TestContext.Out.WriteLine("Incoming attachments");
foreach (var attachment in fakeAttachments)
{
TestContext.Out.WriteLine($"{attachment.FilePath}");
}
var convertedAttachments = testResults.TestResults
.SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
.ToArray();

TestContext.Out.WriteLine("\nConverted attachments (Uri, path)");
foreach (var attachment in convertedAttachments)
{
TestContext.Out.WriteLine($"{attachment.Uri.AbsoluteUri} : {attachment.Uri.LocalPath}");
}
Assert.Multiple(() =>
{
Assert.That(convertedAttachments.Length, Is.GreaterThan(0), "Some converted attachments were expected");
Assert.That(convertedAttachments.Length, Is.EqualTo(fakeAttachments.Length), "Attachments are not converted");
});
}

[Test]
public void Attachments_AllFilePathesStartWithFileScheme()
{
const string fileUriScheme = "file://";
const string errorMessage = "Path must start with file:// uri scheme";

var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode().AsString());

var testResults = testConverter.GetVsTestResults(fakeResultNode, Enumerable.Empty<INUnitTestEventTestOutput>().ToList());

var convertedAttachments = testResults.TestResults
.SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
.ToArray();

foreach (var attachment in convertedAttachments)
{
var originalPath = attachment.Uri.OriginalString;
Assert.That(originalPath.LastIndexOf(fileUriScheme), Is.EqualTo(0), errorMessage);
}
}

#endregion Attachment tests

private void CheckTestCase(TestCase testCase)
Expand Down

0 comments on commit 3be32d6

Please sign in to comment.