Skip to content

Commit

Permalink
Implement the post processing extension feature (#3324)
Browse files Browse the repository at this point in the history
Implement the post processing extension feature
  • Loading branch information
MarcoRossignoli authored Feb 10, 2022
1 parent fdca8e9 commit fd3c7e2
Show file tree
Hide file tree
Showing 63 changed files with 1,169 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Copyright (c) .NET Foundation. All rights reserved.
VSTestBlameHangDumpType="$(VSTestBlameHangDumpType)"
VSTestBlameHangTimeout="$(VSTestBlameHangTimeout)"
VSTestTraceDataCollectorDirectoryPath="$(TraceDataCollectorDirectoryPath)"
VSTestArtifactsProcessingMode="$(VSTestArtifactsProcessingMode)"
VSTestSessionCorrelationId="$(VSTestSessionCorrelationId)"
VSTestNoLogo="$(VSTestNoLogo)"
Condition="'$(IsTestProject)' == 'true'"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestLogger.get -> string[]
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestLogger.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestNoLogo.get -> string
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestNoLogo.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestArtifactsProcessingMode.get -> string
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestArtifactsProcessingMode.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestSessionCorrelationId.get -> string
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestSessionCorrelationId.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestPlatform.get -> string
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestPlatform.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestResultsDirectory.get -> string
Expand All @@ -63,4 +67,4 @@ override Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask.Execute() -> bool
override Microsoft.TestPlatform.Build.Tasks.VSTestTask.Execute() -> bool
static Microsoft.TestPlatform.Build.Trace.Tracing.Trace(string message) -> void
static Microsoft.TestPlatform.Build.Trace.Tracing.traceEnabled -> bool
static Microsoft.TestPlatform.Build.Utils.ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(string arg) -> string
static Microsoft.TestPlatform.Build.Utils.ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(string arg) -> string
22 changes: 22 additions & 0 deletions src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ public string VSTestNoLogo
set;
}

public string VSTestArtifactsProcessingMode
{
get;
set;
}

public string VSTestSessionCorrelationId
{
get;
set;
}

public override bool Execute()
{
var traceEnabledValue = Environment.GetEnvironmentVariable("VSTEST_BUILD_TRACE");
Expand Down Expand Up @@ -416,6 +428,16 @@ private List<string> AddArgs()
allArgs.Add("--nologo");
}

if (!string.IsNullOrEmpty(VSTestArtifactsProcessingMode) && VSTestArtifactsProcessingMode.Equals("collect", StringComparison.OrdinalIgnoreCase))
{
allArgs.Add("--artifactsProcessingMode-collect");
}

if (!string.IsNullOrEmpty(VSTestSessionCorrelationId))
{
allArgs.Add("--testSessionCorrelationId:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(VSTestSessionCorrelationId));
}

return allArgs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

internal interface IArtifactProcessingManager
{
void CollectArtifacts(TestRunCompleteEventArgs testRunCompleteEventArgs, string runSettingsXml);
Task PostProcessArtifactsAsync();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !NETSTANDARD1_0

using System;
using System.Collections.Generic;

namespace Microsoft.VisualStudio.TestPlatform.Utilities;

internal partial class FeatureFlag : IFeatureFlag
{
private static readonly Dictionary<string, bool> FeatureFlags = new();

private const string Prefix = "VSTEST_FEATURE_";

public static IFeatureFlag Instance => new FeatureFlag();

static FeatureFlag()
{
FeatureFlags.Add(ARTIFACTS_POSTPROCESSING, false);
FeatureFlags.Add(ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX, false);
}

// Added for artifact porst-processing, it enable/disable the post processing.
// Added in 17.2-preview 7.0-preview
public static string ARTIFACTS_POSTPROCESSING = Prefix + "ARTIFACTS_POSTPROCESSING";

// Added for artifact porst-processing, it will show old output for dotnet sdk scenario.
// It can be useful if we need to restore old UX in case users are parsing the console output.
// Added in 17.2-preview 7.0-preview
public static string ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX = Prefix + "ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX";

// For now we're checking env var.
// We could add it also to some section inside the runsettings.
public bool IsEnabled(string featureName) =>
int.TryParse(Environment.GetEnvironmentVariable(featureName), out int enabled) ?
enabled == 1 :
FeatureFlags.TryGetValue(featureName, out bool isEnabled) && isEnabled;
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.Utilities;

internal interface IFeatureFlag
{
bool IsEnabled(string featureName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public void Delete(string path)
{
File.Delete(path);
}

public void DeleteDirectory(string directoryPath, bool recursive)
{
Directory.Delete(directoryPath, recursive);
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ public interface IFileHelper
/// </param>
void DeleteEmptyDirectroy(string directoryPath);

/// <summary>
/// Helper for deleting a directory.
/// </summary>
/// <param name="directoryPath">
/// The directory path.
/// </param>
void DeleteDirectory(string directoryPath, bool recursive);

#if !NETSTANDARD1_0
/// <summary>
/// Gets all files in directory based on search pattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CrossPlatEngine.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.TestHostProvider.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CrossPlatEngine, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

#if !NETSTANDARD1_0
// The following GUID is for the ID of the typelib if this project is exposed to COM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper.CopyFile(string sourcePath, string destinationPath) -> void
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper.Delete(string path) -> void
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper.DeleteEmptyDirectroy(string directoryPath) -> void
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper.DeleteDirectory(string directoryPath, bool recursive) -> void
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper.DirectoryExists(string path) -> bool
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper.Exists(string path) -> bool
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper.GetCurrentDirectory() -> string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.CopyFile(string
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.CreateDirectory(string path) -> System.IO.DirectoryInfo
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.Delete(string path) -> void
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.DeleteEmptyDirectroy(string dirPath) -> void
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.DeleteDirectory(string directoryPath, bool recursive) -> void
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.DirectoryExists(string path) -> bool
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.EnumerateFiles(string directory, System.IO.SearchOption searchOption, params string[] endsWithSearchPatterns) -> System.Collections.Generic.IEnumerable<string>
Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.FileHelper.Exists(string path) -> bool
Expand Down
Loading

0 comments on commit fd3c7e2

Please sign in to comment.