Skip to content

Commit

Permalink
Apply modern code styles (#3264)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
Co-authored-by: nohwnd <me@jakubjares.com>
  • Loading branch information
3 people authored Jan 28, 2022
1 parent 065f4d0 commit 361bf62
Show file tree
Hide file tree
Showing 1,073 changed files with 246,554 additions and 248,842 deletions.
436 changes: 436 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions TestPlatform.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{EE49
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E344E0A2-7715-4C7F-BAF7-D64EA94CB19B}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Nuget.config = Nuget.config
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<MicrosoftNETCorePlatformsVersion>2.1.0</MicrosoftNETCorePlatformsVersion>
<MicrosoftNetCompilersToolsetVersion>4.1.0-1.21507.14</MicrosoftNetCompilersToolsetVersion>
<MicrosoftNetTestSdkVersion>15.7.2</MicrosoftNetTestSdkVersion>
<MoqVersion>4.8.3</MoqVersion>
<MoqVersion>4.16.1</MoqVersion>
<MonoOptionsVersion>5.3.0.1</MonoOptionsVersion>
<McMasterExtensionsCommandLineUtils>2.3.0</McMasterExtensionsCommandLineUtils>
<NewtonsoftJsonVersion>9.0.1</NewtonsoftJsonVersion>
Expand Down
18 changes: 10 additions & 8 deletions playground/MSTest1/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest1
namespace MSTest1;

[TestClass]
public class UnitTest1
{
[TestClass]
public class UnitTest1
[TestMethod]
public void TestMethod1()
{
[TestMethod]
public void TestMethod1()
{
}
}
}
}
201 changes: 99 additions & 102 deletions playground/TestPlatform.Playground/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.TestPlatform.VsTestConsole.TranslationLayer;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -11,123 +15,116 @@
using System.Reflection;
using System.Threading;

namespace TestPlatform.Playground
namespace TestPlatform.Playground;

internal class Program
{
internal class Program
static void Main(string[] args)
{
static void Main(string[] args)
// This project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure
// we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from
// their original build locations, to $(TargetDir)\vstest.console directory, and it's subfolders to create an executable
// copy of TestPlatform that is similar to what we ship.
//
// The copying might trigger only on re-build, if you see outdated dependencies, Rebuild this project instead of just Build.
//
// Use this as playground for your debugging of end-to-end scenarios, it will automatically attach vstest.console and teshost
// sub-processes. It won't stop at entry-point automatically, don't forget to set your breakpoints, or remove VSTEST_DEBUG_NOBP
// from the environment variables of this project.

var thisAssemblyPath = Assembly.GetEntryAssembly().Location;
var here = Path.GetDirectoryName(thisAssemblyPath);
var playground = Path.GetFullPath(Path.Combine(here, "..", "..", "..", ".."));

var console = Path.Combine(here, "vstest.console", "vstest.console.exe");
var consoleOptions = new ConsoleParameters
{
// This project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure
// we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from
// their original build locations, to $(TargetDir)\vstest.console directory, and it's subfolders to create an executable
// copy of TestPlatform that is similar to what we ship.
//
// The copying might trigger only on re-build, if you see outdated dependencies, Rebuild this project instead of just Build.
//
// Use this as playground for your debugging of end-to-end scenarios, it will automatically attach vstest.console and teshost
// sub-processes. It won't stop at entry-point automatically, don't forget to set your breakpoints, or remove VSTEST_DEBUG_NOBP
// from the environment variables of this project.

var thisAssemblyPath = Assembly.GetEntryAssembly().Location;
var here = Path.GetDirectoryName(thisAssemblyPath);
var playground = Path.GetFullPath(Path.Combine(here, "..", "..", "..", ".."));

var console = Path.Combine(here, "vstest.console", "vstest.console.exe");
var consoleOptions = new ConsoleParameters
{
LogFilePath = Path.Combine(here, "logs", "log.txt"),
TraceLevel = TraceLevel.Verbose,
};

var r = new VsTestConsoleWrapper(console, consoleOptions);

var sourceSettings = @"
LogFilePath = Path.Combine(here, "logs", "log.txt"),
TraceLevel = TraceLevel.Verbose,
};

var r = new VsTestConsoleWrapper(console, consoleOptions);

var sourceSettings = @"
<RunSettings>
<RunConfiguration>
<InIsolation>true</InIsolation>
</RunConfiguration>
</RunSettings>
";
var sources = new[] {
Path.Combine(playground, "MSTest1", "bin", "Debug", "net472", "MSTest1.dll")
};
var sources = new[] {
Path.Combine(playground, "MSTest1", "bin", "Debug", "net472", "MSTest1.dll")
};

var options = new TestPlatformOptions();
r.RunTestsWithCustomTestHost(sources, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher());
}

public class TestRunHandler : ITestRunEventsHandler
{

public TestRunHandler()
{
}

public void HandleLogMessage(TestMessageLevel level, string message)
{
Console.WriteLine($"[{level.ToString().ToUpper()}]: {message}");
}

var options = new TestPlatformOptions();
r.RunTestsWithCustomTestHost(sources, sourceSettings, options, new TestRunHandler(), new DebuggerTestHostLauncher());
public void HandleRawMessage(string rawMessage)
{
Console.WriteLine($"[MESSAGE]: { rawMessage}");
}

public class TestRunHandler : ITestRunEventsHandler
public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris)
{
Console.WriteLine($"[COMPLETE]: err: { testRunCompleteArgs.Error }, lastChunk: {WriteTests(lastChunkArgs?.NewTestResults)}");
}

public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs)
{
Console.WriteLine($"[PROGRESS - NEW RESULTS]: {WriteTests(testRunChangedArgs.NewTestResults)}");
}

public TestRunHandler()
{
}

public void HandleLogMessage(TestMessageLevel level, string message)
{
Console.WriteLine($"[{level.ToString().ToUpper()}]: {message}");
}

public void HandleRawMessage(string rawMessage)
{
Console.WriteLine($"[MESSAGE]: { rawMessage}");
}

public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris)
{
Console.WriteLine($"[COMPLETE]: err: { testRunCompleteArgs.Error }, lastChunk: {WriteTests(lastChunkArgs?.NewTestResults)}");
}

public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs)
{
Console.WriteLine($"[PROGRESS - NEW RESULTS]: {WriteTests(testRunChangedArgs.NewTestResults)}");
}

public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo)
{
throw new NotImplementedException();
}

private string WriteTests(IEnumerable<TestResult> testResults)
{
return WriteTests(testResults?.Select(t => t.TestCase));
}

private string WriteTests(IEnumerable<TestCase> testCases)
{
if (testCases == null)
{
return null;
}

return "\t" + string.Join("\n\t", testCases.Select(r => r.DisplayName));

}
public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo)
{
throw new NotImplementedException();
}

private string WriteTests(IEnumerable<TestResult> testResults)
{
return WriteTests(testResults?.Select(t => t.TestCase));
}

private string WriteTests(IEnumerable<TestCase> testCases)
{
return testCases == null ? null : "\t" + string.Join("\n\t", testCases.Select(r => r.DisplayName));
}
}

internal class DebuggerTestHostLauncher : ITestHostLauncher2
{
public bool IsDebug => true;

public bool AttachDebuggerToProcess(int pid)
{
return true;
}

public bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken)
{
return true;
}

public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo)
{
return 1;
}

internal class DebuggerTestHostLauncher : ITestHostLauncher2
public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken)
{
public bool IsDebug => true;

public bool AttachDebuggerToProcess(int pid)
{
return true;
}

public bool AttachDebuggerToProcess(int pid, CancellationToken cancellationToken)
{
return true;
}

public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo)
{
return 1;
}

public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken)
{
return 1;
}
return 1;
}
}
}
}
22 changes: 12 additions & 10 deletions scripts/build/ExternalAssemblyVersions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
namespace Microsoft.VisualStudio.TestPlatform
// 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;

internal class ExternalAssemblyVersions
{
internal class ExternalAssemblyVersions
{
/// <summary>
/// Refers to the versions of the assemblies retrieved from the
/// Microsoft.QualityTools.Testing.Fakes.TestRunnerHarness package.
/// The Package version can be found in "scripts\build\TestPlatform.Dependencies.props"
/// </summary>
internal const string MicrosoftFakesAssemblyVersion = "17.0.0.0";
}
/// <summary>
/// Refers to the versions of the assemblies retrieved from the
/// Microsoft.QualityTools.Testing.Fakes.TestRunnerHarness package.
/// The Package version can be found in "scripts\build\TestPlatform.Dependencies.props"
/// </summary>
internal const string MicrosoftFakesAssemblyVersion = "17.0.0.0";
}
1 change: 0 additions & 1 deletion scripts/build/TestPlatform.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<NuGetFrameworksVersion>5.11.0</NuGetFrameworksVersion>
<ILAsmPackageVersion>5.0.0</ILAsmPackageVersion>
<JsonNetVersion>9.0.1</JsonNetVersion>
<MoqVersion>4.8.3</MoqVersion>

<TestPlatformExternalsVersion>17.1.0-preview-2-31925-026</TestPlatformExternalsVersion>
<!-- <TestPlatformMSDiaVersion>$(TestPlatformExternalsVersion)</TestPlatformMSDiaVersion> -->
Expand Down
10 changes: 3 additions & 7 deletions scripts/build/TestPlatform.Settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
readable when we read the file as xml, don't move it to a .props file, unless you change the build server process -->
<TPVersionPrefix>17.2.0</TPVersionPrefix>
<LangVersion>preview</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>preview</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<PropertyGroup>
<!-- Versioning is defined from the build script. Use a default dev build if it's not defined.
Expand Down Expand Up @@ -43,13 +46,6 @@
<!-- Package dependency versions -->
<Import Project="$(MSBuildThisFileDirectory)TestPlatform.Dependencies.props" Condition=" '$(DependencyVersionsImported)' != 'true' "/>

<!-- Common dependencies for all projects -->
<ItemGroup>
<AdditionalFiles Include="$(TestPlatformRoot)scripts\stylecop.json">
<Link>stylecop.json</Link>
</AdditionalFiles>
</ItemGroup>

<!-- Include PublicApi analyzers into all projects that are in our src directory, this can't use TestProject == true
because some projects in test and playground are not tests, but we don't want to analyze those for public apis, because
we don't ship them.
Expand Down
8 changes: 0 additions & 8 deletions scripts/build/TestPlatform.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@
<NoWarn>$(NoWarn);CA1416</NoWarn>
</PropertyGroup>

<!-- Static analysis dependencies -->
<ItemGroup Condition="$(EnableCodeAnalysis) == 'true' AND '$(DotNetBuildFromSource)' != 'true'" >
<PackageReference Include="StyleCop.Analyzers">
<Version>1.0.1</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)TestPlatform.Localization.targets" />
</Project>
Loading

0 comments on commit 361bf62

Please sign in to comment.