diff --git a/src/Extensions.cs b/src/Extensions.cs index e0318e8..55d844a 100644 --- a/src/Extensions.cs +++ b/src/Extensions.cs @@ -20,6 +20,7 @@ public static unsafe string GetString(this Encoding encoding, Span bytes) { fixed (byte* bytesPtr = bytes) { + if(bytesPtr == null) return string.Empty; return encoding.GetString(bytesPtr, bytes.Length); } } @@ -29,6 +30,7 @@ public static unsafe string GetString(this Encoding encoding, ReadOnlySpan { fixed (byte* bytesPtr = bytes) { + if(bytesPtr == null) return string.Empty; return encoding.GetString(bytesPtr, bytes.Length); } } @@ -39,6 +41,7 @@ public static unsafe int GetBytes(this Encoding encoding, Span chars, Span fixed (char* charsPtr = chars) fixed (byte* bytesPtr = bytes) { + if(bytesPtr == null) return 0; return encoding.GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length); } } @@ -49,6 +52,7 @@ public static unsafe int GetBytes(this Encoding encoding, ReadOnlySpan cha fixed (char* charsPtr = chars) fixed (byte* bytesPtr = bytes) { + if(bytesPtr == null) return 0; return encoding.GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length); } } @@ -59,6 +63,7 @@ public static unsafe int GetBytes(this Encoding encoding, string chars, Span() - .WithMessage("Value cannot be null. (Parameter 'store')"); +#if NETFRAMEWORK + .WithMessage("Value cannot be null.\r\nParameter name: store"); +#else + .WithMessage("Value cannot be null. (Parameter 'store')"); +#endif } [Fact] @@ -67,7 +71,11 @@ public void ItFailsToInstantiateWithNegativeMinimum() action .Should() .Throw() +#if NETFRAMEWORK + .WithMessage("Specified argument was out of the range of valid values.\r\nParameter name: minimum"); +#else .WithMessage("Specified argument was out of the range of valid values. (Parameter 'minimum')"); +#endif } [Fact] @@ -78,7 +86,11 @@ public void ItFailsToInstantiateWithNegativeMaximum() action .Should() .Throw() +#if NETFRAMEWORK + .WithMessage("Specified argument was out of the range of valid values.\r\nParameter name: maximum"); +#else .WithMessage("Specified argument was out of the range of valid values. (Parameter 'maximum')"); +#endif } [Fact] @@ -89,7 +101,12 @@ public void ItFailsToInstantiateWithMaximumLessThanMinimum() action .Should() .Throw() +#if NETFRAMEWORK + .WithMessage("The maximum cannot be less than the minimum.\r\nParameter name: maximum"); +#else .WithMessage("The maximum cannot be less than the minimum. (Parameter 'maximum')"); +#endif + } [Fact] diff --git a/tests/StoreDataTests.cs b/tests/StoreDataTests.cs index 855a166..a986620 100644 --- a/tests/StoreDataTests.cs +++ b/tests/StoreDataTests.cs @@ -1,8 +1,6 @@ using System; -using System.Diagnostics.Metrics; using System.Linq; using FluentAssertions; -using Newtonsoft.Json.Linq; using Xunit; namespace Wasmtime.Tests diff --git a/tests/WasiTests.cs b/tests/WasiTests.cs index 6f69f31..75055c1 100644 --- a/tests/WasiTests.cs +++ b/tests/WasiTests.cs @@ -7,6 +7,54 @@ namespace Wasmtime.Tests { +#if NETFRAMEWORK // the following code is a polyfill as it already exists in .Net + using System.Runtime.CompilerServices; + using System.Collections; + + sealed class ReferenceEqualityComparer : IEqualityComparer, IEqualityComparer + { + private ReferenceEqualityComparer() { } + + /// + /// Gets the singleton instance. + /// + public static ReferenceEqualityComparer Instance { get; } = new ReferenceEqualityComparer(); + + /// + /// Determines whether two object references refer to the same object instance. + /// + /// The first object to compare. + /// The second object to compare. + /// + /// if both and refer to the same object instance + /// or if both are ; otherwise, . + /// + /// + /// This API is a wrapper around . + /// It is not necessarily equivalent to calling . + /// + public new bool Equals(object? x, object? y) => ReferenceEquals(x, y); + + /// + /// Returns a hash code for the specified object. The returned hash code is based on the object + /// identity, not on the contents of the object. + /// + /// The object for which to retrieve the hash code. + /// A hash code for the identity of . + /// + /// This API is a wrapper around . + /// It is not necessarily equivalent to calling . + /// + public int GetHashCode(object? obj) + { + // Depending on target framework, RuntimeHelpers.GetHashCode might not be annotated + // with the proper nullability attribute. We'll suppress any warning that might + // result. + return RuntimeHelpers.GetHashCode(obj!); + } + } +#endif + public class WasiTests { [Theory] @@ -70,7 +118,7 @@ public void ItHasSpecifiedEnvironment(string path) for (int i = 0; i < env.Count; ++i) { - var kvp = memory.ReadNullTerminatedString(memory.ReadInt32(i * 4)).Split("="); + var kvp = memory.ReadNullTerminatedString(memory.ReadInt32(i * 4)).Split('='); Assert.Equal(env[kvp[0]], kvp[1]); } } diff --git a/tests/Wasmtime.Tests.csproj b/tests/Wasmtime.Tests.csproj index ee330e2..a81158e 100644 --- a/tests/Wasmtime.Tests.csproj +++ b/tests/Wasmtime.Tests.csproj @@ -1,7 +1,14 @@ - + + + + net8.0;net472 + + + net8.0 + - net8.0 + Latest false