Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ internal interface IArtifactProcessingManager
/// </summary>
/// <returns>
/// A warning to surface to the user when the artifacts directory could not be verified (so nothing was
/// collected), or when attachments were saved to the user-private fallback directory because
/// VSTEST_ARTIFACTS_DIRECTORY was missing or unusable; otherwise <see langword="null"/>.
/// collected), or <see langword="null"/> when there is nothing to report.
/// </returns>
string? CollectArtifacts(TestRunCompleteEventArgs testRunCompleteEventArgs, string runSettingsXml);
Task PostProcessArtifactsAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,10 @@ private static bool IsFullyQualified(string path)
return null;
}

// We need to save in case of attachements, we'll show these at the end on console.
// A null collection is treated the same as an empty one, there is nothing to persist either way.
if (testRunCompleteEventArgs.AttachmentSets is not { Count: > 0 })
{
return null;
}

// A correlation id means the .NET SDK wants artifacts produced here and consumed by itself later, so
// a silent fallback away from the directory it asked for is worth a warning the user actually sees,
// not just a trace that needs --diag. It is only reported when there are artifacts to persist,
// otherwise the directory is never used and the warning would be noise.
// not just a trace that needs --diag. Computed as soon as the id is known to be present, rather than
// only once there happens to be something to persist, so it is reported on every such run.
string? artifactsDirectoryFallbackWarning = null;
if (!_artifactsDirectoryWasProvided)
{
Expand All @@ -256,6 +249,13 @@ private static bool IsFullyQualified(string path)
: $"{ArtifactsDirectoryEnvironmentVariableName} environment variable was set but ignored because its value '{rawArtifactsDirectory}' is not a usable absolute path, falling back to a user-private temporary directory.";
}

// We need to save in case of attachements, we'll show these at the end on console.
// A null collection is treated the same as an empty one, there is nothing to persist either way.
if (testRunCompleteEventArgs.AttachmentSets is not { Count: > 0 })
{
return artifactsDirectoryFallbackWarning;
}

TPDebug.Assert(_testSessionProcessArtifactFolder is not null, "_testSessionProcessArtifactFolder is null");
TPDebug.Assert(_processArtifactFolder is not null, "_processArtifactFolder is null");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,23 +421,23 @@ public void CollectArtifacts_ShouldSerializeToDisk()
}

[TestMethod]
[DataRow(true)]
[DataRow(false)]
public void CollectArtifacts_ShouldNotWarnWhenTheArtifactsDirectoryVariableIsMissingAndThereAreNoAttachments(bool attachmentSetsIsNull)
public void CollectArtifacts_ShouldWarnWhenTheArtifactsDirectoryVariableIsMissing()
{
// With no attachments the artifacts directory is never used, so falling back from it is not worth a warning.
// A correlation id with no attachments still has nothing to persist, but the .NET SDK asked for
// artifacts handling by passing the id at all, so the warning must not depend on there being
// something to write this particular run.
var testRunCompleteEventArgs = new TestRunCompleteEventArgs(_testRunStatistics.Object,
false,
false,
null,
attachmentSetsIsNull ? null : new Collection<AttachmentSet>(),
new Collection<AttachmentSet>(),
TimeSpan.Zero);

var result = _artifactProcessingManager.CollectArtifacts(testRunCompleteEventArgs, string.Empty);

Assert.IsNull(result);
_fileHelperMock.Verify(x => x.CreateDirectory(It.IsAny<string>()), Times.Never);
_fileHelperMock.Verify(x => x.WriteAllTextToFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
Assert.IsNotNull(result);
Assert.Contains(ArtifactProcessingManager.ArtifactsDirectoryEnvironmentVariableName, result);
Assert.Contains("Microsoft.NET.Test.Sdk", result);
}

[TestMethod]
Expand Down
Loading