Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullables on TRX logger #3754

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shared/NullableAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
public string[] Members { get; }
}

#endif

/// <summary>
/// Secret attribute that tells the CA1062 validate arguments rule that this method validates the argument is not null.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
internal sealed class ValidatedNotNullAttribute : Attribute
{
}

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

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;

internal interface ITestAggregation : ITestElement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;

internal interface ITestElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

using System;

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;

internal interface ITestResult
{
TestResultId Id { get; }
string ResultType { get; set; }
string? ResultType { get; set; }
string StdOut { get; set; }
string StdErr { get; set; }
string DebugTrace { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System.Collections.Generic;

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;

internal interface ITestResultAggregation : ITestResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System.Xml;

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;

/// <summary>
Expand All @@ -18,5 +16,5 @@ internal interface IXmlTestStore
/// </summary>
/// <param name="element"> XmlElement element </param>
/// <param name="parameters"> XmlTestStoreParameters parameters</param>
void Save(XmlElement element, XmlTestStoreParameters parameters);
void Save(XmlElement element, XmlTestStoreParameters? parameters);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.XML;

/// <summary>
Expand All @@ -18,5 +16,5 @@ internal interface IXmlTestStoreCustom
/// <summary>
/// Gets the xml namespace to use when creating the element
/// </summary>
string NamespaceUri { get; }
string? NamespaceUri { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

using System.Collections.Generic;

#nullable disable

namespace Microsoft.TestPlatform.Extensions.TrxLogger.ObjectModel;

/// <summary>
/// Optional parameters to the persistence process. A class implementing IPersistable can
/// Optional parameters to the persistence process. A class implementing IPersistable can
/// use the parameter values to alter its load/save behavior.
/// </summary>
/// <example>
/// Example: a class has a summary and details fields. Details are large, so they're only
/// Example: a class has a summary and details fields. Details are large, so they're only
/// saved when 'MyClass.SaveDetails' parameter is set to 'true'.
/// </example>
internal sealed class XmlTestStoreParameters : Dictionary<string, object>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
</PropertyGroup>
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<AssemblyName>Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger</AssemblyName>
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\TrxResource.resx" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
<Reference Include="System.Runtime" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(TestPlatformRoot)src\Microsoft.TestPlatform.TestHostProvider\Properties\TestExtensionTypesAttribute.cs" Link="Properties\TestExtensionTypesAttribute.cs" />
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestPlatformRoot)src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
<ProjectReference Include="$(TestPlatformRoot)src\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Security.Principal.Windows" Version="4.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="NullableHelpers.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>NullableHelpers.tt</DependentUpon>
</Compile>
<Compile Update="Resources\TrxResource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>TrxResource.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\TrxResource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>TrxResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup Label="Configuration">
<RootNamespace>Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger</RootNamespace>
</PropertyGroup>
<ItemGroup>
<!-- API that is common to all frameworks that we build for. -->
<AdditionalFiles Include="PublicAPI/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/PublicAPI.Unshipped.txt" />
<!-- Framework specific API -->
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
</ItemGroup>
<ItemGroup>
<None Update="NullableHelpers.tt">
<LastGenOutput>NullableHelpers.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<AssemblyName>Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger</AssemblyName>
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0;net451</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
Expand All @@ -21,6 +21,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="$(TestPlatformRoot)src\Microsoft.TestPlatform.TestHostProvider\Properties\TestExtensionTypesAttribute.cs" Link="Properties\TestExtensionTypesAttribute.cs" />
<Compile Include="..\..\shared\NullableAttributes.cs" Link="NullableAttributes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestPlatformRoot)src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
Expand All @@ -33,6 +34,11 @@
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="NullableHelpers.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>NullableHelpers.tt</DependentUpon>
</Compile>
<Compile Update="Resources\TrxResource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand All @@ -56,5 +62,14 @@
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
</ItemGroup>
<ItemGroup>
<None Update="NullableHelpers.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>NullableHelpers.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
</Project>
42 changes: 42 additions & 0 deletions src/Microsoft.TestPlatform.Extensions.TrxLogger/NullableHelpers.cs
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.
// <auto-generated>
// This code is auto-generated. Changes to this file will be lost!
// This T4 file is copied in various projects because inclusion as link or through shared project
// doesn't allow to generate the C# file locally. If some modification is required, please update
// all instances.
// </auto-generated>

#nullable enable

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger;

internal static class StringUtils
{
/// <inheritdoc cref="string.IsNullOrEmpty(string)"/>
[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")]
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)] this string? value)
=> string.IsNullOrEmpty(value);

/// <inheritdoc cref="string.IsNullOrWhiteSpace(string)"/>
[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")]
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)] this string? value)
=> string.IsNullOrWhiteSpace(value);
}

[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")]
internal static class TPDebug
{
/// <inheritdoc cref="TPDebug.Assert(bool)"/>
[Conditional("DEBUG")]
public static void Assert([DoesNotReturnIf(false)] bool b)
=> TPDebug.Assert(b);

/// <inheritdoc cref="TPDebug.Assert(bool, string)"/>
[Conditional("DEBUG")]
public static void Assert([DoesNotReturnIf(false)] bool b, string message)
=> TPDebug.Assert(b, message);
}
45 changes: 45 additions & 0 deletions src/Microsoft.TestPlatform.Extensions.TrxLogger/NullableHelpers.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// <auto-generated>
// This code is auto-generated. Changes to this file will be lost!
// This T4 file is copied in various projects because inclusion as link or through shared project
// doesn't allow to generate the C# file locally. If some modification is required, please update
// all instances.
// </auto-generated>

#nullable enable

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace <#= System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint") #>;

internal static class StringUtils
{
/// <inheritdoc cref="string.IsNullOrEmpty(string)"/>
[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")]
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)] this string? value)
=> string.IsNullOrEmpty(value);

/// <inheritdoc cref="string.IsNullOrWhiteSpace(string)"/>
[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")]
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)] this string? value)
=> string.IsNullOrWhiteSpace(value);
}

[SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "Replacement API to allow nullable hints for compiler")]
internal static class TPDebug
{
/// <inheritdoc cref="TPDebug.Assert(bool)"/>
[Conditional("DEBUG")]
public static void Assert([DoesNotReturnIf(false)] bool b)
=> TPDebug.Assert(b);

/// <inheritdoc cref="TPDebug.Assert(bool, string)"/>
[Conditional("DEBUG")]
public static void Assert([DoesNotReturnIf(false)] bool b, string message)
=> TPDebug.Assert(b, message);
}
Loading