From d65b7239a68eff63dd175a0ca1d37ccc956a798a Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 6 Jan 2020 11:40:44 -0800 Subject: [PATCH] Preserve functional test logs on CI (dotnet/extensions#2819) * Add option to preserve function test logs * Upload test logs as artifacts * Preserve binlogs * Add target to ensure all functional test logs preserved \n\nCommit migrated from https://github.com/dotnet/extensions/commit/08aa4560e589002f8f2444e4b27b8f0930cfbb46 --- src/Testing/ref/Microsoft.AspNetCore.Testing.net46.cs | 4 +++- .../ref/Microsoft.AspNetCore.Testing.netstandard2.0.cs | 4 +++- src/Testing/src/TestFileOutputContext.cs | 6 ++++++ src/Testing/src/TestOutputDirectoryAttribute.cs | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Testing/ref/Microsoft.AspNetCore.Testing.net46.cs b/src/Testing/ref/Microsoft.AspNetCore.Testing.net46.cs index af28ec60e0..e737371a8c 100644 --- a/src/Testing/ref/Microsoft.AspNetCore.Testing.net46.cs +++ b/src/Testing/ref/Microsoft.AspNetCore.Testing.net46.cs @@ -295,6 +295,7 @@ namespace Microsoft.AspNetCore.Testing public string TestName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public static string GetAssemblyBaseDirectory(System.Reflection.Assembly assembly, string baseDirectory = null) { throw null; } public static string GetOutputDirectory(System.Reflection.Assembly assembly) { throw null; } + public static bool GetPreserveExistingLogsInOutput(System.Reflection.Assembly assembly) { throw null; } public static string GetTestClassName(System.Type type) { throw null; } public static string GetTestMethodName(System.Reflection.MethodInfo method, object[] arguments) { throw null; } public string GetUniqueFileName(string prefix, string extension) { throw null; } @@ -307,8 +308,9 @@ namespace Microsoft.AspNetCore.Testing [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=true)] public partial class TestOutputDirectoryAttribute : System.Attribute { - public TestOutputDirectoryAttribute(string targetFramework, string baseDirectory = null) { } + public TestOutputDirectoryAttribute(string preserveExistingLogsInOutput, string targetFramework, string baseDirectory = null) { } public string BaseDirectory { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public bool PreserveExistingLogsInOutput { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public string TargetFramework { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } } [System.ObsoleteAttribute("This API is obsolete and the pattern its usage encouraged should not be used anymore. See https://github.com/aspnet/Extensions/issues/1697 for details.")] diff --git a/src/Testing/ref/Microsoft.AspNetCore.Testing.netstandard2.0.cs b/src/Testing/ref/Microsoft.AspNetCore.Testing.netstandard2.0.cs index af28ec60e0..e737371a8c 100644 --- a/src/Testing/ref/Microsoft.AspNetCore.Testing.netstandard2.0.cs +++ b/src/Testing/ref/Microsoft.AspNetCore.Testing.netstandard2.0.cs @@ -295,6 +295,7 @@ namespace Microsoft.AspNetCore.Testing public string TestName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public static string GetAssemblyBaseDirectory(System.Reflection.Assembly assembly, string baseDirectory = null) { throw null; } public static string GetOutputDirectory(System.Reflection.Assembly assembly) { throw null; } + public static bool GetPreserveExistingLogsInOutput(System.Reflection.Assembly assembly) { throw null; } public static string GetTestClassName(System.Type type) { throw null; } public static string GetTestMethodName(System.Reflection.MethodInfo method, object[] arguments) { throw null; } public string GetUniqueFileName(string prefix, string extension) { throw null; } @@ -307,8 +308,9 @@ namespace Microsoft.AspNetCore.Testing [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=true)] public partial class TestOutputDirectoryAttribute : System.Attribute { - public TestOutputDirectoryAttribute(string targetFramework, string baseDirectory = null) { } + public TestOutputDirectoryAttribute(string preserveExistingLogsInOutput, string targetFramework, string baseDirectory = null) { } public string BaseDirectory { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public bool PreserveExistingLogsInOutput { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public string TargetFramework { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } } [System.ObsoleteAttribute("This API is obsolete and the pattern its usage encouraged should not be used anymore. See https://github.com/aspnet/Extensions/issues/1697 for details.")] diff --git a/src/Testing/src/TestFileOutputContext.cs b/src/Testing/src/TestFileOutputContext.cs index 496a1379fb..fb79fd7bf7 100644 --- a/src/Testing/src/TestFileOutputContext.cs +++ b/src/Testing/src/TestFileOutputContext.cs @@ -93,6 +93,12 @@ namespace Microsoft.AspNetCore.Testing return Path.Combine(baseDirectory, assembly.GetName().Name, attribute.TargetFramework); } + public static bool GetPreserveExistingLogsInOutput(Assembly assembly) + { + var attribute = assembly.GetCustomAttributes().OfType().FirstOrDefault(); + return attribute.PreserveExistingLogsInOutput; + } + public static string GetTestClassName(Type type) { var shortNameAttribute = diff --git a/src/Testing/src/TestOutputDirectoryAttribute.cs b/src/Testing/src/TestOutputDirectoryAttribute.cs index 4ae8cea054..b1895c1d92 100644 --- a/src/Testing/src/TestOutputDirectoryAttribute.cs +++ b/src/Testing/src/TestOutputDirectoryAttribute.cs @@ -8,13 +8,15 @@ namespace Microsoft.AspNetCore.Testing [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = true)] public class TestOutputDirectoryAttribute : Attribute { - public TestOutputDirectoryAttribute(string targetFramework, string baseDirectory = null) + public TestOutputDirectoryAttribute(string preserveExistingLogsInOutput, string targetFramework, string baseDirectory = null) { TargetFramework = targetFramework; BaseDirectory = baseDirectory; + PreserveExistingLogsInOutput = bool.Parse(preserveExistingLogsInOutput); } public string BaseDirectory { get; } public string TargetFramework { get; } + public bool PreserveExistingLogsInOutput { get; } } }