Skip to content

Commit

Permalink
Fixing unit tests and analyzer issues for every target
Browse files Browse the repository at this point in the history
  • Loading branch information
koszeggy committed Oct 22, 2023
1 parent 2c318f8 commit 6830e5c
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!--<TargetFrameworks>net35;net40;net45;net46;net47;net472;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>-->
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net35;net40;net45;net46;net47;net472;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<!--<TargetFrameworks>net7.0</TargetFrameworks>-->

<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>

Expand All @@ -28,10 +28,13 @@
<GenerateProgramFile>false</GenerateProgramFile>

<!--Suppressions:
MSB3568: Duplicate resources - intended, test data
NETSDK1138: The target framework 'netcoreapp2.0'/'netcoreapp2.1'/'netcoreapp3.0' is out of support - this is not an application but a library so targeting the lowest possible versions is intended
- MSB3568: Duplicate resources - intended, test data
- MSB3825: Resources serialized by BinaryFormatter - intended, test data (among others, for security checks)
- NETSDK1138: The target framework 'netcoreapp2.0'/'netcoreapp2.1'/'netcoreapp3.0' is out of support - this is not an application but a library so targeting the lowest possible versions is intended
- NETSDK1138: The target framework 'netcoreapp2.0'/'netcoreapp2.1'/'netcoreapp3.0' is out of support - this is not an application but a library so targeting the lowest possible versions is intended
- NU1902, NU1903: netcoreapp2.1 has known vulnerabilities - it's a targeted plartform and not a referenced package. A consumer of this library can also pick newer supported platforms.
-->
<NoWarn>$(NoWarn);MSB3568;NETSDK1138</NoWarn>
<NoWarn>$(NoWarn);MSB3568;MSB3825;NETSDK1138;NU1902;NU1903</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(IsWindows)'=='true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,7 @@ public void GetFlagsCountTest()
public void TestEnum_PartiallyTrusted()
{
var domain = CreateSandboxDomain(
#if NET35
new SecurityPermission(SecurityPermissionFlag.ControlEvidence),
#endif
new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.UnmanagedCode),
new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
var handle = Activator.CreateInstance(domain, Assembly.GetExecutingAssembly().FullName, typeof(Sandbox).FullName!);
var sandbox = (Sandbox)handle.Unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ public void ClassStaticComplexFunctionMethodInvoke()
parameters = (object[])args.Clone();
inv.Invoke(null, parameters.AsSpan());
Assert.AreEqual(args[0], result);
Assert.AreEqual(args[0], test.IntProp);
Assert.AreEqual(args[0], TestClass.StaticIntProp);
Assert.AreNotEqual(args[2], parameters[2]);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void SafeModeWithFileRefTest()
}

[Test]
[Obsolete]
public void SafeModeWithFileRefTestWithResolver()
{
var fileRef = new ResXFileRef("fileName", "MyNamespace.DangerousType, DangerousAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1782,11 +1782,13 @@ private sealed record ClassRecord(string StringProp, int IntProp)
#region Methods

#if NET35 // Compiler bug: CS0656: Missing compiler required member 'System.Type.op_Equality'
#pragma warning disable CS8851 // Record defines 'Equals' but not 'GetHashCode'.
public bool Equals(ClassRecord other) => ReferenceEquals(this, other)
|| (other is not null
&& EqualityContract == other.EqualityContract
&& StringProp == other.StringProp
&& IntProp == other.IntProp);
#pragma warning restore CS8851 // Record defines 'Equals' but not 'GetHashCode'.
#endif

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@

#region Suppressions

#if NET5_0_OR_GREATER
#pragma warning disable SYSLIB0011 // Type or member is obsolete - this class uses BinaryFormatter for comparisons. It's safe because both serialization and deserialization is in the same process.
#pragma warning disable CS0618 // Use of obsolete symbol - as above, as well as indicating some obsolete types as expected ones when deserializing a Hashtable or other non-generic collections
#endif

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,13 @@ public ClassRecord() : this(default, default)
#region Methods

#if NET35 // Compiler bug: CS0656: Missing compiler required member 'System.Type.op_Equality'
#pragma warning disable CS8851 // Record defines 'Equals' but not 'GetHashCode'.
public bool Equals(ClassRecord other) => ReferenceEquals(this, other)
|| (other is not null
&& EqualityContract == other.EqualityContract
&& StringProp == other.StringProp
&& IntProp == other.IntProp);
#pragma warning restore CS8851 // Record defines 'Equals' but not 'GetHashCode'.
#endif

#endregion
Expand Down
8 changes: 4 additions & 4 deletions KGySoft.CoreLibraries/KGySoft.CoreLibraries.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<!--.NET Core 2.0 is needed because .NET Standard 2.0 lacks many features.-->
<!--.NET Core 3.0 is needed because if .NET Core 2.0 version exists, then a .NET Core 3.0 consumer references that instead of the .NET Standard 2.1 version.-->
<!--<TargetFrameworks>net35;net40;net45;net46;net47;net472;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>-->
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<TargetFrameworks>net35;net40;net45;net46;net47;net472;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<!--<TargetFrameworks>net7.0</TargetFrameworks>-->

<!--For UnitTesting the .NET Standard versions-->
<!--<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>-->
Expand All @@ -29,13 +29,13 @@

<!--Suppressions
- NETSDK1138: The target framework 'netcoreapp2.0'/'netcoreapp2.1'/'netcoreapp3.0' is out of support - this is not an application but a library so targeting the lowest possible versions is intended
- NU1902, NU1903: netcoreapp2.1 has known vulnerabilities - it's a targeted plartform and not a referenced package. A consumer of this library can also pick newer supported platforms as well.
- NU1902, NU1903: netcoreapp2.1 has known vulnerabilities - it's a targeted plartform and not a referenced package. A consumer of this library can also pick newer supported platforms.
-->
<NoWarn>$(NoWarn);NETSDK1138;NU1902;NU1903</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview1.23165.1">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview.23472.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
9 changes: 6 additions & 3 deletions KGySoft.CoreLibraries/Reflection/CreateInstanceAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
using System.Runtime.ExceptionServices;

using KGySoft.Annotations;

using KGySoft.CoreLibraries;

#if !NET6_0_OR_GREATER
using KGySoft.CoreLibraries;
#endregion

#region Suppressions

#if !(NETCOREAPP3_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER)
#pragma warning disable CS8763 // A method marked [DoesNotReturn] should not return - false alarm, ExceptionDispatchInfo.Throw() does not return either.
#endif

#endregion
Expand Down
2 changes: 0 additions & 2 deletions KGySoft.CoreLibraries/Reflection/FieldAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
#if NET471_OR_GREATER || NETSTANDARD || NETCOREAPP
using System.Linq;
#endif
using System.Linq.Expressions;
using System.Reflection;
#if !NETSTANDARD2_0
Expand Down
6 changes: 3 additions & 3 deletions KGySoft.CoreLibraries/Reflection/IndexerAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal IndexerAccessor(PropertyInfo pi)
if (Property.PropertyType.IsPointer)
Throw.NotSupportedException(Res.ReflectionPointerTypeNotSupported(Property.PropertyType));

if (!CanWrite)
if (!Property.CanWrite)
{
if (Property.PropertyType.IsByRef)
{
Expand Down Expand Up @@ -161,7 +161,7 @@ private protected override Delegate CreateNonGenericSetter()
if (ParameterTypes.Length > 1)
Throw.NotSupportedException(); // Will be handled in PostValidate

if (!CanWrite)
if (!Property.CanWrite)
{
if (Property.PropertyType.IsByRef)
{
Expand Down Expand Up @@ -272,7 +272,7 @@ private protected override Delegate CreateGenericSetter()
Type delegateType = (isValueType ? typeof(ValueTypeAction<,,>) : typeof(ReferenceTypeAction<,,>))
.GetGenericType(declaringType, Property.PropertyType.IsByRef ? Property.PropertyType.GetElementType()! : Property.PropertyType, ParameterTypes[0]);

if (!CanWrite)
if (!Property.CanWrite)
{
if (Property.PropertyType.IsByRef)
{
Expand Down
6 changes: 3 additions & 3 deletions KGySoft.CoreLibraries/Reflection/SimplePropertyAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal SimplePropertyAccessor(PropertyInfo pi)
if (Property.PropertyType.IsPointer)
Throw.NotSupportedException(Res.ReflectionPointerTypeNotSupported(Property.PropertyType));

if (!CanWrite)
if (!Property.CanWrite)
{
if (Property.PropertyType.IsByRef)
{
Expand Down Expand Up @@ -146,7 +146,7 @@ private protected override Delegate CreateNonGenericSetter()
if (Property.PropertyType.IsPointer)
Throw.NotSupportedException(Res.ReflectionPointerTypeNotSupported(Property.PropertyType));

if (!CanWrite)
if (!Property.CanWrite)
{
if (Property.PropertyType.IsByRef)
{
Expand Down Expand Up @@ -245,7 +245,7 @@ private protected override Delegate CreateGenericSetter()
: declaringType!.IsValueType ? typeof(ValueTypeAction<,>).GetGenericType(declaringType, propertyType)
: typeof(ReferenceTypeAction<,>).GetGenericType(declaringType, propertyType);

if (!CanWrite)
if (!Property.CanWrite)
{
if (isByRef)
{
Expand Down
2 changes: 1 addition & 1 deletion KGySoft.CoreLibraries/Res.cs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ internal static void Initialize()
internal static string PerformanceTestCallingGcCollect(bool value) => Get("PerformanceTest_CallingGcCollectFormat", FormatBool(value));

/// <summary>Forced CPU Affinity: {0}</summary>
internal static string PerformanceTestCpuAffinity(int? affinity) => Get("PerformanceTest_CpuAffinityFormat", affinity == null ? No : affinity.ToString());
internal static string PerformanceTestCpuAffinity(int? affinity) => Get("PerformanceTest_CpuAffinityFormat", affinity == null ? No : affinity);

/// <summary>Cases are sorted by {0}</summary>
internal static string PerformanceTestSortOfCases(string sort) => Get("PerformanceTest_SortOfCasesFormat", sort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

#region Suppressions

#if !NET7_0_OR_GREATER
#if !NET8_0_OR_GREATER
#pragma warning disable CS1574 // the documentation contains types that are not available in every target
#endif
#if NET5_0_OR_GREATER
Expand Down Expand Up @@ -317,6 +317,10 @@ namespace KGySoft.Serialization.Binary
/// <item><see cref="ImmutableDictionary{TKey,TValue}.Builder"/> (in .NET Core 2.0 and above)</item>
/// <item><see cref="ImmutableSortedDictionary{TKey,TValue}"/> (in .NET Core 2.0 and above)</item>
/// <item><see cref="ImmutableSortedDictionary{TKey,TValue}.Builder"/> (in .NET Core 2.0 and above)</item>
/// <item><see cref="Vector64{T}"/> (in .NET Core 3.0 and above)</item>
/// <item><see cref="Vector128{T}"/> (in .NET Core 3.0 and above)</item>
/// <item><see cref="Vector256{T}"/> (in .NET Core 3.0 and above)</item>
/// <item><see cref="Vector512{T}"/> (in .NET 8.0 and above)</item>
/// </list>
/// <note>
/// <list type="bullet">
Expand Down
8 changes: 8 additions & 0 deletions KGySoft.CoreLibraries/Serialization/Xml/XmlSerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@

#endregion

#region Suppressions

#if !(NETSTANDARD2_1_OR_GREATER && NETCOREAPP3_0_OR_GREATER)
#pragma warning disable CS8602 // Dereference of a possibly null reference
#endif

#endregion

namespace KGySoft.Serialization.Xml
{
internal abstract class XmlSerializerBase
Expand Down

0 comments on commit 6830e5c

Please sign in to comment.