Skip to content

Commit a0c9bb5

Browse files
authored
ModuleLoadTests had lots of warnings to do with using Read and not checking the return value. Fixed by using ReadExactly instead. (#335)
1 parent ca0066c commit a0c9bb5

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/ModuleLoadTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Reflection;
33
using FluentAssertions;
4-
using Wasmtime;
54
using Xunit;
65

76
namespace Wasmtime.Tests
@@ -11,7 +10,7 @@ public class ModuleLoadTests
1110
[Fact]
1211
public void ItLoadsModuleFromEmbeddedResource()
1312
{
14-
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wasm");
13+
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wasm")!;
1514
stream.Should().NotBeNull();
1615

1716
using var engine = new Engine();
@@ -20,18 +19,18 @@ public void ItLoadsModuleFromEmbeddedResource()
2019
// `LoadModule` is not supposed to close the supplied stream,
2120
// so the following statement should complete without throwing
2221
// `ObjectDisposedException`
23-
stream.Read(new byte[0], 0, 0);
22+
stream.ReadExactly(Array.Empty<byte>(), 0, 0);
2423
}
2524

2625
[Fact]
2726
public void ItValidatesModuleFromEmbeddedResource()
2827
{
29-
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wasm");
28+
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wasm")!;
3029
stream.Should().NotBeNull();
3130

3231
byte[] buffer = new byte[stream.Length];
3332

34-
stream.Read(buffer, 0, buffer.Length);
33+
stream.ReadExactly(buffer, 0, buffer.Length);
3534

3635
using var engine = new Engine();
3736
Module.Validate(engine, buffer).Should().BeNull();
@@ -40,7 +39,7 @@ public void ItValidatesModuleFromEmbeddedResource()
4039
[Fact]
4140
public void ItLoadsModuleTextFromEmbeddedResource()
4241
{
43-
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wat");
42+
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wat")!;
4443
stream.Should().NotBeNull();
4544

4645
using var engine = new Engine();
@@ -49,13 +48,13 @@ public void ItLoadsModuleTextFromEmbeddedResource()
4948
// `LoadModuleText` is not supposed to close the supplied stream,
5049
// so the following statement should complete without throwing
5150
// `ObjectDisposedException`
52-
stream.Read(new byte[0], 0, 0);
51+
stream.ReadExactly(new byte[0], 0, 0);
5352
}
5453

5554
[Fact]
5655
public void ItCannotBeAccessedOnceDisposed()
5756
{
58-
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wasm");
57+
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("hello.wasm")!;
5958
stream.Should().NotBeNull();
6059

6160
using var engine = new Engine();

0 commit comments

Comments
 (0)