From 937997ddca4a039ebe5e7eb173acf27a67c230a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 30 Aug 2022 13:41:11 +0200 Subject: [PATCH 1/5] Comment out console mode, add non-detailed output mode. --- playground/TestPlatform.Playground/Program.cs | 108 +++++++++++------- 1 file changed, 69 insertions(+), 39 deletions(-) diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index 4026e65d0e..25dad37c9d 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -69,31 +69,34 @@ static void Main() Path.Combine(playground, "MSTest1", "bin", "Debug", "net5.0", "MSTest1.dll"), }; - // console mode - var settingsFile = Path.GetTempFileName(); - try - { - File.WriteAllText(settingsFile, sourceSettings); - var processStartInfo = new ProcessStartInfo - { - FileName = console, - Arguments = $"{string.Join(" ", sources)} --settings:{settingsFile} --listtests", - UseShellExecute = false, - }; - EnvironmentVariables.Variables.ToList().ForEach(processStartInfo.Environment.Add); - var process = Process.Start(processStartInfo); - process.WaitForExit(); - if (process.ExitCode != 0) - { - throw new Exception($"Process failed with {process.ExitCode}"); - } - } - finally - { - try { File.Delete(settingsFile); } catch { } - } + // Uncomment when providing command line parameters is easier for you + // than converting them to settings, or when you debug command line scenario specifically. + //// console mode + //var settingsFile = Path.GetTempFileName(); + //try + //{ + // File.WriteAllText(settingsFile, sourceSettings); + // var processStartInfo = new ProcessStartInfo + // { + // FileName = console, + // Arguments = $"{string.Join(" ", sources)} --settings:{settingsFile} --listtests", + // UseShellExecute = false, + // }; + // EnvironmentVariables.Variables.ToList().ForEach(processStartInfo.Environment.Add); + // var process = Process.Start(processStartInfo); + // process.WaitForExit(); + // if (process.ExitCode != 0) + // { + // throw new Exception($"Process failed with {process.ExitCode}"); + // } + //} + //finally + //{ + // try { File.Delete(settingsFile); } catch { } + //} // design mode + var detailedOutput = true; var consoleOptions = new ConsoleParameters { EnvironmentVariables = EnvironmentVariables.Variables, @@ -110,7 +113,7 @@ static void Main() //// TestSessions // r.StartTestSession(sources, sourceSettings, sessionHandler); #pragma warning restore CS0618 // Type or member is obsolete - var discoveryHandler = new PlaygroundTestDiscoveryHandler(); + var discoveryHandler = new PlaygroundTestDiscoveryHandler(detailedOutput); var sw = Stopwatch.StartNew(); // Discovery r.DiscoverTests(sources, sourceSettings, options, sessionHandler.TestSessionInfo, discoveryHandler); @@ -118,13 +121,13 @@ static void Main() Console.WriteLine($"Discovery done in {discoveryDuration} ms"); sw.Restart(); // Run with test cases and custom testhost launcher - r.RunTestsWithCustomTestHost(discoveryHandler.TestCases, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(), new DebuggerTestHostLauncher()); + r.RunTestsWithCustomTestHost(discoveryHandler.TestCases, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput), new DebuggerTestHostLauncher()); //// Run with test cases and without custom testhost launcher - //r.RunTests(discoveryHandler.TestCases, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler()); + //r.RunTests(discoveryHandler.TestCases, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput)); //// Run with sources and custom testhost launcher - //r.RunTestsWithCustomTestHost(sources, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(), new DebuggerTestHostLauncher()); + //r.RunTestsWithCustomTestHost(sources, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput), new DebuggerTestHostLauncher()); //// Run with sources - //r.RunTests(sources, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler()); + //r.RunTests(sources, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput)); var rd = sw.ElapsedMilliseconds; Console.WriteLine($"Discovery: {discoveryDuration} ms, Run: {rd} ms, Total: {discoveryDuration + rd} ms"); Console.WriteLine($"Settings:\n{sourceSettings}"); @@ -133,13 +136,22 @@ static void Main() public class PlaygroundTestDiscoveryHandler : ITestDiscoveryEventsHandler, ITestDiscoveryEventsHandler2 { private int _testCasesCount; + private readonly bool _detailedOutput; + + public PlaygroundTestDiscoveryHandler(bool detailedOutput) + { + _detailedOutput = detailedOutput; + } public List TestCases { get; internal set; } = new List(); public void HandleDiscoveredTests(IEnumerable? discoveredTestCases) { - Console.WriteLine($"[DISCOVERY.PROGRESS]"); - Console.WriteLine(WriteTests(discoveredTestCases)); + if (_detailedOutput) + { + Console.WriteLine($"[DISCOVERY.PROGRESS]"); + Console.WriteLine(WriteTests(discoveredTestCases)); + } _testCasesCount += discoveredTestCases.Count(); if (discoveredTestCases != null) { TestCases.AddRange(discoveredTestCases); } } @@ -147,16 +159,22 @@ public void HandleDiscoveredTests(IEnumerable? discoveredTestCases) public void HandleDiscoveryComplete(long totalTests, IEnumerable? lastChunk, bool isAborted) { Console.WriteLine($"[DISCOVERY.COMPLETE] aborted? {isAborted}, tests count: {totalTests}"); - Console.WriteLine("Last chunk:"); - Console.WriteLine(WriteTests(lastChunk)); + if (_detailedOutput) + { + Console.WriteLine("Last chunk:"); + Console.WriteLine(WriteTests(lastChunk)); + } if (lastChunk != null) { TestCases.AddRange(lastChunk); } } public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable? lastChunk) { Console.WriteLine($"[DISCOVERY.COMPLETE] aborted? {discoveryCompleteEventArgs.IsAborted}, tests count: {discoveryCompleteEventArgs.TotalCount}, discovered count: {_testCasesCount}"); - Console.WriteLine("Last chunk:"); - Console.WriteLine(WriteTests(lastChunk)); + if (_detailedOutput) + { + Console.WriteLine("Last chunk:"); + Console.WriteLine(WriteTests(lastChunk)); + } Console.WriteLine("Fully discovered:"); Console.WriteLine(WriteSources(discoveryCompleteEventArgs.FullyDiscoveredSources)); Console.WriteLine("Partially discovered:"); @@ -191,9 +209,11 @@ private static string WriteSources(IEnumerable? sources) public class TestRunHandler : ITestRunEventsHandler { + private readonly bool _detailedOutput; - public TestRunHandler() + public TestRunHandler(bool detailedOutput) { + _detailedOutput = detailedOutput; } public void HandleLogMessage(TestMessageLevel level, string? message) @@ -203,19 +223,28 @@ public void HandleLogMessage(TestMessageLevel level, string? message) public void HandleRawMessage(string rawMessage) { - Console.WriteLine($"[RUN.MESSAGE]: {rawMessage}"); + if (_detailedOutput) + { + Console.WriteLine($"[RUN.MESSAGE]: {rawMessage}"); + } } public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteArgs, TestRunChangedEventArgs? lastChunkArgs, ICollection? runContextAttachments, ICollection? executorUris) { Console.WriteLine($"[RUN.COMPLETE]: err: {testRunCompleteArgs.Error}, lastChunk:"); - Console.WriteLine(WriteTests(lastChunkArgs?.NewTestResults)); + if (_detailedOutput) + { + Console.WriteLine(WriteTests(lastChunkArgs?.NewTestResults)); + } } public void HandleTestRunStatsChange(TestRunChangedEventArgs? testRunChangedArgs) { - Console.WriteLine($"[RUN.PROGRESS]"); - Console.WriteLine(WriteTests(testRunChangedArgs?.NewTestResults)); + if (_detailedOutput) + { + Console.WriteLine($"[RUN.PROGRESS]"); + Console.WriteLine(WriteTests(testRunChangedArgs?.NewTestResults)); + } } public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo) @@ -260,6 +289,7 @@ public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, Cancell internal class TestSessionHandler : ITestSessionEventsHandler { + public TestSessionHandler() { } public TestSessionInfo? TestSessionInfo { get; private set; } public void HandleLogMessage(TestMessageLevel level, string? message) From ae448a2b13f73ee40487a8ce7f806c98df118d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 30 Aug 2022 14:04:51 +0200 Subject: [PATCH 2/5] Comment out console mode, add non-detailed output mode. --- playground/TestPlatform.Playground/Program.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index 25dad37c9d..329a916cab 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -60,7 +60,23 @@ static void Main() - + + + + """; From d2f232cdfa07e252cda8b73af4df4e578ed3b757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 30 Aug 2022 14:05:14 +0200 Subject: [PATCH 3/5] Fix usage of datacollector. --- .../TestPlatform.Playground/TestPlatform.Playground.csproj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/playground/TestPlatform.Playground/TestPlatform.Playground.csproj b/playground/TestPlatform.Playground/TestPlatform.Playground.csproj index b187eeec85..a469c7fa96 100644 --- a/playground/TestPlatform.Playground/TestPlatform.Playground.csproj +++ b/playground/TestPlatform.Playground/TestPlatform.Playground.csproj @@ -18,7 +18,12 @@ + + + + + @@ -35,7 +40,7 @@ - + From e47caee813242a96df991e6964b02e107626cac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 6 Sep 2022 15:29:26 +0200 Subject: [PATCH 4/5] Remove maxCpuCount --- playground/TestPlatform.Playground/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index 329a916cab..37f807815b 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -39,7 +39,6 @@ static void Main() var console = Path.Combine(here, "vstest.console", "vstest.console.exe"); - var maxCpuCount = Environment.GetEnvironmentVariable("VSTEST_MAX_CPU_COUNT") ?? "0"; var sourceSettings = $$$""" From b971bae4da339d704cd9e28a7abbe70e8878569b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 7 Sep 2022 10:10:37 +0200 Subject: [PATCH 5/5] Update playground/TestPlatform.Playground/Program.cs Co-authored-by: Medeni Baykal <433724+Haplois@users.noreply.github.com> --- playground/TestPlatform.Playground/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/TestPlatform.Playground/Program.cs b/playground/TestPlatform.Playground/Program.cs index 37f807815b..396d8a8910 100644 --- a/playground/TestPlatform.Playground/Program.cs +++ b/playground/TestPlatform.Playground/Program.cs @@ -84,7 +84,7 @@ static void Main() Path.Combine(playground, "MSTest1", "bin", "Debug", "net5.0", "MSTest1.dll"), }; - // Uncomment when providing command line parameters is easier for you + // Uncomment if providing command line parameters is easier for you // than converting them to settings, or when you debug command line scenario specifically. //// console mode //var settingsFile = Path.GetTempFileName();