diff --git a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/DotNetHelper.cs b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/DotNetHelper.cs index 7c263e080..a9361453e 100644 --- a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/DotNetHelper.cs +++ b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/DotNetHelper.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics; using System.IO; -using Xunit; using Xunit.Abstractions; namespace Microsoft.DotNet.SourceBuild.SmokeTests; @@ -81,15 +80,6 @@ internal class DotNetHelper public void ExecuteCmd(string args, string? workingDirectory = null, Action? additionalProcessConfigCallback = null, int expectedExitCode = 0, int millisecondTimeout = -1) { - Action configureProcess = (Process process, string? workingDirectory) => { - ConfigureProcess(process, workingDirectory); - - if (additionalProcessConfigCallback != null) - { - additionalProcessConfigCallback(process); - } - }; - (Process Process, string StdOut, string StdErr) executeResult = ExecuteHelper.ExecuteProcess( DotNetPath, args, @@ -98,6 +88,13 @@ internal class DotNetHelper millisecondTimeout: millisecondTimeout); ExecuteHelper.ValidateExitCode(executeResult, expectedExitCode); + + void configureProcess(Process process, string? workingDirectory) + { + ConfigureProcess(process, workingDirectory); + + additionalProcessConfigCallback?.Invoke(process); + } } public static void ConfigureProcess(Process process, string? workingDirectory, bool setPath = false) diff --git a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs index 4a7b87750..62e1eb594 100644 --- a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs +++ b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs @@ -44,10 +44,24 @@ internal static class ExecuteHelper configure?.Invoke(process); StringBuilder stdOutput = new(); - process.OutputDataReceived += new DataReceivedEventHandler((sender, e) => stdOutput.AppendLine(e.Data)); + process.OutputDataReceived += new DataReceivedEventHandler( + (sender, e) => + { + lock (stdOutput) + { + stdOutput.AppendLine(e.Data); + } + }); StringBuilder stdError = new(); - process.ErrorDataReceived += new DataReceivedEventHandler((sender, e) => stdError.AppendLine(e.Data)); + process.ErrorDataReceived += new DataReceivedEventHandler( + (sender, e) => + { + lock (stdError) + { + stdError.AppendLine(e.Data); + } + }); process.Start(); process.BeginOutputReadLine(); diff --git a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableFactAttribute.cs b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableFactAttribute.cs index fbe57433f..867bb77a5 100644 --- a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableFactAttribute.cs +++ b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableFactAttribute.cs @@ -5,35 +5,34 @@ using System; using Xunit; -namespace Microsoft.DotNet.SourceBuild.SmokeTests +namespace Microsoft.DotNet.SourceBuild.SmokeTests; + +/// +/// A Fact that will be skipped based on the specified environment variable's value. +/// +internal class SkippableFactAttribute : FactAttribute { - /// - /// A Fact that will be skipped based on the specified environment variable's value. - /// - internal class SkippableFactAttribute : FactAttribute + public SkippableFactAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => + CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envName); + + public SkippableFactAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => + CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envNames); + + public static void CheckEnvs(bool skipOnNullOrWhiteSpace, bool skipOnTrue, Action setSkip, params string[] envNames) { - public SkippableFactAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => - CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envName); - - public SkippableFactAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => - CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envNames); - - public static void CheckEnvs(bool skipOnNullOrWhiteSpace, bool skipOnTrue, Action setSkip, params string[] envNames) + foreach (string envName in envNames) { - foreach (string envName in envNames) - { - string? envValue = Environment.GetEnvironmentVariable(envName); + string? envValue = Environment.GetEnvironmentVariable(envName); - if (skipOnNullOrWhiteSpace && string.IsNullOrWhiteSpace(envValue)) - { - setSkip($"Skipping because `{envName}` is null or whitespace"); - break; - } - else if (skipOnTrue && bool.TryParse(envValue, out bool boolValue) && boolValue) - { - setSkip($"Skipping because `{envName}` is set to True"); - break; - } + if (skipOnNullOrWhiteSpace && string.IsNullOrWhiteSpace(envValue)) + { + setSkip($"Skipping because `{envName}` is null or whitespace"); + break; + } + else if (skipOnTrue && bool.TryParse(envValue, out bool boolValue) && boolValue) + { + setSkip($"Skipping because `{envName}` is set to True"); + break; } } } diff --git a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableTheoryAttribute.cs b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableTheoryAttribute.cs index 8ce5a4881..32a7179a1 100644 --- a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableTheoryAttribute.cs +++ b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/SkippableTheoryAttribute.cs @@ -4,17 +4,16 @@ using Xunit; -namespace Microsoft.DotNet.SourceBuild.SmokeTests -{ - /// - /// A Theory that will be skipped based on the specified environment variable's value. - /// - internal class SkippableTheoryAttribute : TheoryAttribute - { - public SkippableTheoryAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => - SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envName); +namespace Microsoft.DotNet.SourceBuild.SmokeTests; - public SkippableTheoryAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => - SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envNames); - } +/// +/// A Theory that will be skipped based on the specified environment variable's value. +/// +internal class SkippableTheoryAttribute : TheoryAttribute +{ + public SkippableTheoryAttribute(string envName, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => + SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envName); + + public SkippableTheoryAttribute(string[] envNames, bool skipOnNullOrWhiteSpace = false, bool skipOnTrue = false) => + SkippableFactAttribute.CheckEnvs(skipOnNullOrWhiteSpace, skipOnTrue, (skip) => Skip = skip, envNames); } diff --git a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/TestScenario.cs b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/TestScenario.cs index 29f3259c1..f5a04de1e 100644 --- a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/TestScenario.cs +++ b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/TestScenario.cs @@ -2,66 +2,63 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; +namespace Microsoft.DotNet.SourceBuild.SmokeTests; -namespace Microsoft.DotNet.SourceBuild.SmokeTests +public class TestScenario { - public class TestScenario + public DotNetActions Commands { get; } + public DotNetLanguage Language { get; } + public bool NoHttps { get; set; } = Config.TargetRid.Contains("osx"); + public string ScenarioName { get; } + public DotNetTemplate Template { get; } + + public TestScenario(string scenarioName, DotNetLanguage language, DotNetTemplate template, DotNetActions commands = DotNetActions.None) { - public DotNetActions Commands { get; } - public DotNetLanguage Language { get; } - public bool NoHttps { get; set; } = Config.TargetRid.Contains("osx"); - public string ScenarioName { get; } - public DotNetTemplate Template { get; } + ScenarioName = scenarioName; + Template = template; + Language = language; + Commands = commands; + } - public TestScenario(string scenarioName, DotNetLanguage language, DotNetTemplate template, DotNetActions commands = DotNetActions.None) + internal void Execute(DotNetHelper dotNetHelper) + { + // Don't use the cli language name in the project name because it may contain '#': https://github.com/dotnet/roslyn/issues/51692 + string projectName = $"{ScenarioName}_{Template}_{Language}"; + string customNewArgs = Template.IsAspNetCore() && NoHttps ? "--no-https" : string.Empty; + dotNetHelper.ExecuteNew(Template.GetName(), projectName, Language.ToCliName(), customArgs: customNewArgs); + + if (Commands.HasFlag(DotNetActions.Build)) { - ScenarioName = scenarioName; - Template = template; - Language = language; - Commands = commands; + dotNetHelper.ExecuteBuild(projectName); } - - internal void Execute(DotNetHelper dotNetHelper) + if (Commands.HasFlag(DotNetActions.Run)) { - // Don't use the cli language name in the project name because it may contain '#': https://github.com/dotnet/roslyn/issues/51692 - string projectName = $"{ScenarioName}_{Template}_{Language}"; - string customNewArgs = Template.IsAspNetCore() && NoHttps ? "--no-https" : string.Empty; - dotNetHelper.ExecuteNew(Template.GetName(), projectName, Language.ToCliName(), customArgs: customNewArgs); - - if (Commands.HasFlag(DotNetActions.Build)) + if (Template.IsAspNetCore()) { - dotNetHelper.ExecuteBuild(projectName); + dotNetHelper.ExecuteRunWeb(projectName); } - if (Commands.HasFlag(DotNetActions.Run)) + else { - if (Template.IsAspNetCore()) - { - dotNetHelper.ExecuteRunWeb(projectName); - } - else - { - dotNetHelper.ExecuteRun(projectName); - } - } - if (Commands.HasFlag(DotNetActions.Publish)) - { - dotNetHelper.ExecutePublish(projectName); - } - if (Commands.HasFlag(DotNetActions.PublishComplex)) - { - dotNetHelper.ExecutePublish(projectName, selfContained: false); - dotNetHelper.ExecutePublish(projectName, selfContained: true, Config.TargetRid); - dotNetHelper.ExecutePublish(projectName, selfContained: true, "linux-x64"); - } - if (Commands.HasFlag(DotNetActions.PublishR2R)) - { - dotNetHelper.ExecutePublish(projectName, selfContained: true, "linux-x64", trimmed: true, readyToRun: true); - } - if (Commands.HasFlag(DotNetActions.Test)) - { - dotNetHelper.ExecuteTest(projectName); + dotNetHelper.ExecuteRun(projectName); } } + if (Commands.HasFlag(DotNetActions.Publish)) + { + dotNetHelper.ExecutePublish(projectName); + } + if (Commands.HasFlag(DotNetActions.PublishComplex)) + { + dotNetHelper.ExecutePublish(projectName, selfContained: false); + dotNetHelper.ExecutePublish(projectName, selfContained: true, Config.TargetRid); + dotNetHelper.ExecutePublish(projectName, selfContained: true, "linux-x64"); + } + if (Commands.HasFlag(DotNetActions.PublishR2R)) + { + dotNetHelper.ExecutePublish(projectName, selfContained: true, "linux-x64", trimmed: true, readyToRun: true); + } + if (Commands.HasFlag(DotNetActions.Test)) + { + dotNetHelper.ExecuteTest(projectName); + } } }