Skip to content

Commit

Permalink
fix xunit warnings (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibel committed Apr 17, 2023
1 parent 24e3e8d commit aa6de27
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 44 deletions.
8 changes: 4 additions & 4 deletions test/Tmds.DBus.Protocol.Tests/Tmds.DBus.Protocol.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public SkippableFactDiscoverer(IMessageSink diagnosticMessageSink)

public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
yield return new SkippableFactTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod);
yield return new SkippableFactTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ public class SkippableFactTestCase : XunitTestCase
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public SkippableFactTestCase() { }

[Obsolete("Please call the constructor which takes TestMethodDisplayOptions")]
public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, ITestMethod testMethod, object[]? testMethodArguments = null)
: base(diagnosticMessageSink, defaultMethodDisplay, testMethod, testMethodArguments) { }
: base(diagnosticMessageSink, defaultMethodDisplay, TestMethodDisplayOptions.None, testMethod, testMethodArguments) { }

public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, object[]? testMethodArguments = null)
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) { }

public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink,
IMessageBus messageBus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ public SkippableTheoryDiscoverer(IMessageSink diagnosticMessageSink)
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
var defaultMethodDisplay = discoveryOptions.MethodDisplayOrDefault();
var defaultMethodDisplayOptions = discoveryOptions.MethodDisplayOptionsOrDefault();

// Unlike fact discovery, the underlying algorithm for theories is complex, so we let the theory discoverer
// do its work, and do a little on-the-fly conversion into our own test cases.
return theoryDiscoverer.Discover(discoveryOptions, testMethod, factAttribute)
.Select(testCase => testCase is XunitTheoryTestCase
? (IXunitTestCase)new SkippableTheoryTestCase(diagnosticMessageSink, defaultMethodDisplay, testCase.TestMethod)
: new SkippableFactTestCase(diagnosticMessageSink, defaultMethodDisplay, testCase.TestMethod, testCase.TestMethodArguments));
? (IXunitTestCase)new SkippableTheoryTestCase(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testCase.TestMethod)
: new SkippableFactTestCase(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testCase.TestMethod, testCase.TestMethodArguments));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ public class SkippableTheoryTestCase : XunitTheoryTestCase
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public SkippableTheoryTestCase() { }

[Obsolete("Please call the constructor which takes TestMethodDisplayOptions")]
public SkippableTheoryTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, ITestMethod testMethod)
: base(diagnosticMessageSink, defaultMethodDisplay, testMethod) { }
: base(diagnosticMessageSink, defaultMethodDisplay, TestMethodDisplayOptions.None, testMethod) { }

public SkippableTheoryTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod)
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod) { }

public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink,
IMessageBus messageBus,
Expand Down
6 changes: 3 additions & 3 deletions test/Tmds.DBus.Tests/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task SignalNoArg()
await conn2.RegisterObjectAsync(new PingPong());
await proxy.PingAsync("hello world");
var reply = await tcs.Task;
Assert.Equal(null, reply);
Assert.Null(reply);
}

[Fact]
Expand Down Expand Up @@ -90,10 +90,10 @@ public async Task Properties()
Assert.Equal("changed", val1Changed);

var changes = await tcs.Task;
Assert.Equal(1, changes.Changed.Length);
Assert.Single(changes.Changed);
Assert.Equal("key1", changes.Changed.First().Key);
Assert.Equal("changed", changes.Changed.First().Value);
Assert.Equal(0, changes.Invalidated.Length);
Assert.Empty(changes.Invalidated);
}

[InlineData("tcp:host=localhost,port=1")]
Expand Down
6 changes: 3 additions & 3 deletions test/Tmds.DBus.Tests/DaemonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public async Task Properties()
Assert.Equal("changed", val1Changed);

var changes = await tcs.Task;
Assert.Equal(1, changes.Changed.Length);
Assert.Single(changes.Changed);
Assert.Equal("key1", changes.Changed.First().Key);
Assert.Equal("changed", changes.Changed.First().Value);
Assert.Equal(0, changes.Invalidated.Length);
Assert.Empty(changes.Invalidated);
}
}

Expand All @@ -124,7 +124,7 @@ public async Task BusOperations()
Assert.Equal("org.freedesktop.DBus.Error.ServiceUnknown", exception.ErrorName);

var isRunning = await conn1.IsServiceActiveAsync("com.some.service");
Assert.Equal(false, isRunning);
Assert.False(isRunning);
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/Tmds.DBus.Tests/ReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ public void Invalid(Type type)
byte[] littleEndianData,
IEqualityComparer<object> returnComparer)
{
// ignore
_ = alignment;
_ = littleEndianData;

// via Delegate
{
MessageReader reader = CreateMessageReader(EndianFlag.Big, bigEndianData);
Expand Down Expand Up @@ -216,6 +220,10 @@ public void Invalid(Type type)
byte[] littleEndianData,
IEqualityComparer<object> returnComparer)
{
// ignore
_ = alignment;
_ = bigEndianData;

// via Delegate
{
MessageReader reader = CreateMessageReader(EndianFlag.Little, littleEndianData);
Expand Down Expand Up @@ -306,6 +314,11 @@ public override bool Equals(object rhs)
}
return (f_d == other.f_d);
}

public override int GetHashCode()
{
return f_d.GetHashCode();
}
}

[Dictionary]
Expand Down
12 changes: 6 additions & 6 deletions test/Tmds.DBus.Tests/ServiceNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task Register()
await conn1.RegisterServiceAsync(serviceName);

bool released = await conn1.UnregisterServiceAsync(serviceName);
Assert.Equal(true, released);
Assert.True(released);
}
}

Expand Down Expand Up @@ -155,15 +155,15 @@ public async Task ResolveService()
await conn2.ConnectAsync();

var owner = await conn2.ResolveServiceOwnerAsync(serviceName);
Assert.Equal(null, owner);
Assert.Null(owner);

await conn1.RegisterServiceAsync(serviceName);
owner = await conn2.ResolveServiceOwnerAsync(serviceName);
Assert.Equal(conn1Info.LocalName, owner);

await conn1.UnregisterServiceAsync(serviceName);
owner = await conn2.ResolveServiceOwnerAsync(serviceName);
Assert.Equal(null, owner);
Assert.Null(owner);
}
}

Expand Down Expand Up @@ -199,22 +199,22 @@ public async Task WatchResolveService(string resolvedService, bool filterEvents)
await conn1.RegisterServiceAsync(serviceName);
var e = await changeEvents.TakeAsync();
Assert.Equal(serviceName, e.ServiceName);
Assert.Equal(null, e.OldOwner);
Assert.Null(e.OldOwner);
Assert.Equal(conn1Info.LocalName, e.NewOwner);

await conn1.UnregisterServiceAsync(serviceName);
e = await changeEvents.TakeAsync();
Assert.Equal(serviceName, e.ServiceName);
Assert.Equal(conn1Info.LocalName, e.OldOwner);
Assert.Equal(null, e.NewOwner);
Assert.Null(e.NewOwner);

resolver.Dispose();
await conn1.RegisterServiceAsync(serviceName);
resolver = await conn2.ResolveServiceOwnerAsync(resolvedService, onChange);

e = await changeEvents.TakeAsync();
Assert.Equal(serviceName, e.ServiceName);
Assert.Equal(null, e.OldOwner);
Assert.Null(e.OldOwner);
Assert.Equal(conn1Info.LocalName, e.NewOwner);
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/Tmds.DBus.Tests/Tmds.DBus.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<Content Include="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
4 changes: 2 additions & 2 deletions test/Tmds.DBus.Tests/TransportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task Transport(DBusDaemonProtocol protocol)
var connectionInfo = await connection.ConnectAsync();

Assert.StartsWith(":", connectionInfo.LocalName);
Assert.Equal(true, connectionInfo.RemoteIsBus);
Assert.True(connectionInfo.RemoteIsBus);
}
}

Expand All @@ -42,7 +42,7 @@ public async Task TryMultipleAddresses()
var connectionInfo = await connection.ConnectAsync();

Assert.StartsWith(":", connectionInfo.LocalName);
Assert.Equal(true, connectionInfo.RemoteIsBus);
Assert.True(connectionInfo.RemoteIsBus);
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions test/Tmds.DBus.Tests/TypeDescriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public void SignalDescription()
var description = TypeDescription.DescribeInterface(typeof(IValidSignal1));
var signalDescription = description.Interfaces[0].Signals[0];
Assert.Equal("Something", signalDescription.Name);
Assert.Equal(false, signalDescription.HasOnError);
Assert.Equal(null, signalDescription.SignalType);
Assert.False(signalDescription.HasOnError);
Assert.Null(signalDescription.SignalType);
Assert.Equal(typeof(Action), signalDescription.ActionType);
Assert.Equal((Signature?)null, signalDescription.SignalSignature);
Assert.Equal(0, signalDescription.SignalArguments.Count);
Expand All @@ -127,7 +127,7 @@ public void SignalDescription()
description = TypeDescription.DescribeInterface(typeof(IValidSignal2));
signalDescription = description.Interfaces[0].Signals[0];
Assert.Equal("Something", signalDescription.Name);
Assert.Equal(false, signalDescription.HasOnError);
Assert.False(signalDescription.HasOnError);
Assert.Equal(typeof(int), signalDescription.SignalType);
Assert.Equal(typeof(Action<int>), signalDescription.ActionType);
Assert.Equal("i", signalDescription.SignalSignature);
Expand Down Expand Up @@ -230,8 +230,8 @@ public void SignalDescription()
description = TypeDescription.DescribeInterface(typeof(IValidSignal8));
signalDescription = description.Interfaces[0].Signals[0];
Assert.Equal("Something", signalDescription.Name);
Assert.Equal(true, signalDescription.HasOnError);
Assert.Equal(null, signalDescription.SignalType);
Assert.True(signalDescription.HasOnError);
Assert.Null(signalDescription.SignalType);
Assert.Equal(typeof(Action), signalDescription.ActionType);
Assert.Equal((Signature?)null, signalDescription.SignalSignature);
Assert.Equal(0, signalDescription.SignalArguments.Count);
Expand All @@ -241,7 +241,7 @@ public void SignalDescription()
description = TypeDescription.DescribeInterface(typeof(IValidSignal9));
signalDescription = description.Interfaces[0].Signals[0];
Assert.Equal("Something", signalDescription.Name);
Assert.Equal(true, signalDescription.HasOnError);
Assert.True(signalDescription.HasOnError);
Assert.Equal(typeof(int), signalDescription.SignalType);
Assert.Equal(typeof(Action<int>), signalDescription.ActionType);
Assert.Equal("i", signalDescription.SignalSignature);
Expand All @@ -261,7 +261,7 @@ public void MethodDescription()
var description = TypeDescription.DescribeInterface(typeof(IValidDBusMethod1));
var methodDescription = description.Interfaces[0].Methods[0];
Assert.Equal("Foo", methodDescription.Name);
Assert.Equal(null, methodDescription.OutType);
Assert.Null(methodDescription.OutType);
Assert.Equal((Signature?)null, methodDescription.InSignature);
Assert.Equal((Signature?)null, methodDescription.OutSignature);
Assert.Equal(0, methodDescription.InArguments.Count);
Expand All @@ -272,7 +272,7 @@ public void MethodDescription()
description = TypeDescription.DescribeInterface(typeof(IValidDBusMethod2));
methodDescription = description.Interfaces[0].Methods[0];
Assert.Equal("Foo", methodDescription.Name);
Assert.Equal(null, methodDescription.OutType);
Assert.Null(methodDescription.OutType);
Assert.Equal("i", methodDescription.InSignature);
Assert.Equal((Signature?)null, methodDescription.OutSignature);
Assert.Equal(0, methodDescription.OutArguments.Count);
Expand All @@ -288,7 +288,7 @@ public void MethodDescription()
description = TypeDescription.DescribeInterface(typeof(IValidDBusMethod3));
methodDescription = description.Interfaces[0].Methods[0];
Assert.Equal("Foo", methodDescription.Name);
Assert.Equal(null, methodDescription.OutType);
Assert.Null(methodDescription.OutType);
Assert.Equal("ii", methodDescription.InSignature);
Assert.Equal((Signature?)null, methodDescription.OutSignature);
Assert.Equal(0, methodDescription.OutArguments.Count);
Expand All @@ -308,7 +308,7 @@ public void MethodDescription()
description = TypeDescription.DescribeInterface(typeof(IValidDBusMethod4));
methodDescription = description.Interfaces[0].Methods[0];
Assert.Equal("Foo", methodDescription.Name);
Assert.Equal(null, methodDescription.OutType);
Assert.Null(methodDescription.OutType);
Assert.Equal("(ii)", methodDescription.InSignature);
Assert.Equal((Signature?)null, methodDescription.OutSignature);
Assert.Equal(0, methodDescription.OutArguments.Count);
Expand All @@ -324,7 +324,7 @@ public void MethodDescription()
description = TypeDescription.DescribeInterface(typeof(IValidDBusMethod5));
methodDescription = description.Interfaces[0].Methods[0];
Assert.Equal("Foo", methodDescription.Name);
Assert.Equal(null, methodDescription.OutType);
Assert.Null(methodDescription.OutType);
Assert.Equal("(ii)", methodDescription.InSignature);
Assert.Equal((Signature?)null, methodDescription.OutSignature);
Assert.Equal(0, methodDescription.OutArguments.Count);
Expand Down Expand Up @@ -450,7 +450,7 @@ public void MethodDescription()
description = TypeDescription.DescribeInterface(typeof(IValidDBusMethod12));
methodDescription = description.Interfaces[0].Methods[0];
Assert.Equal("Foo", methodDescription.Name);
Assert.Equal(null, methodDescription.OutType);
Assert.Null(methodDescription.OutType);
Assert.Equal("(is)", methodDescription.InSignature);
Assert.Equal((Signature?)null, methodDescription.OutSignature);
Assert.Equal(0, methodDescription.OutArguments.Count);
Expand All @@ -466,7 +466,7 @@ public void MethodDescription()
description = TypeDescription.DescribeInterface(typeof(IValidDBusMethod13));
methodDescription = description.Interfaces[0].Methods[0];
Assert.Equal("Foo", methodDescription.Name);
Assert.Equal(null, methodDescription.OutType);
Assert.Null(methodDescription.OutType);
Assert.Equal("(is)", methodDescription.InSignature);
Assert.Equal((Signature?)null, methodDescription.OutSignature);
Assert.Equal(0, methodDescription.OutArguments.Count);
Expand Down
8 changes: 8 additions & 0 deletions test/Tmds.DBus.Tests/WriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public void Invalid(Type type)
byte[] bigEndianData,
byte[] littleEndianData)
{
// ignore
_ = alignment;
_ = littleEndianData;

// via Delegate
{
MessageWriter writer = new MessageWriter(EndianFlag.Big);
Expand Down Expand Up @@ -99,6 +103,10 @@ public void Invalid(Type type)
byte[] bigEndianData,
byte[] littleEndianData)
{
// ignore
_ = alignment;
_ = bigEndianData;

// via Delegate
{
MessageWriter writer = new MessageWriter(EndianFlag.Little);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public SkippableFactDiscoverer(IMessageSink diagnosticMessageSink)

public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
yield return new SkippableFactTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod);
yield return new SkippableFactTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod);
}
}
}

0 comments on commit aa6de27

Please sign in to comment.