Skip to content

Commit

Permalink
Updates for .NET 5.0 (#80)
Browse files Browse the repository at this point in the history
* Update references

* CI to use .NET 5.0

* Fix CI

* Nullability fixes

* Fix CI Pt. II
  • Loading branch information
gfoidl authored Nov 11, 2020
1 parent 24a9300 commit 55b6028
Show file tree
Hide file tree
Showing 28 changed files with 125 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .azure/pipelines/jobs/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
release-build:
BUILD_CONFIG: Release
steps:
- template: steps/dotnet-install.yml

- bash: |
echo 'installed sdks:'
dotnet --list-sdks
Expand Down
2 changes: 2 additions & 0 deletions .azure/pipelines/jobs/e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ jobs:
pool:
vmImage: 'ubuntu-18.04'
steps:
- template: steps/dotnet-install.yml

- bash: |
sudo apt update
sudo apt install -y libxml2-utils
Expand Down
18 changes: 18 additions & 0 deletions .azure/pipelines/jobs/steps/dotnet-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
steps:
- task: UseDotNet@2
displayName: 'Use dotnet sdk 5.0'
inputs:
version: 5.x
includePreviewVersions: true

- task: UseDotNet@2
displayName: 'Use dotnet sdk 3.1'
inputs:
version: 3.1.x
includePreviewVersions: true

- task: UseDotNet@2
displayName: 'Use dotnet sdk 2.1'
inputs:
version: 2.1.x
includePreviewVersions: true
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>

<PropertyGroup>
<VersionMajor Condition="'$(VersionMajor)' == ''">1</VersionMajor>
Expand All @@ -15,7 +15,7 @@
</PropertyGroup>

<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project>
<Project>

<Import Project="../Directory.Build.props" />

<PropertyGroup>
<SampleTfm>netcoreapp3.0</SampleTfm>
<SampleTfm>net5.0</SampleTfm>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions samples/MsTestSample/MsTestSample.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(SampleTfm)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions samples/NUnitSample/NUnitSample.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(SampleTfm)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>

</Project>
9 changes: 6 additions & 3 deletions samples/XUnitSample/XUnitSample.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(SampleTfm)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions source/trx2junit/Abstractions/IFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;

namespace trx2junit
{
public interface IFileSystem
{
Stream OpenRead(string? path);
void CreateDirectory(string? directory);
IEnumerable<string> EnumerateFiles(string? path, string? pattern);
Stream OpenRead(string path);
void CreateDirectory(string directory);
IEnumerable<string> EnumerateFiles(string path, string pattern);
}
}
4 changes: 2 additions & 2 deletions source/trx2junit/Abstractions/IGlobHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace trx2junit
namespace trx2junit
{
public interface IGlobHandler
{
void ExpandWildcards(WorkerOptions? options);
void ExpandWildcards(WorkerOptions options);
}
}
6 changes: 3 additions & 3 deletions source/trx2junit/Abstractions/ITestResultXmlConverter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.IO;
using System.IO;
using System.Threading.Tasks;

namespace trx2junit
{
public interface ITestResultXmlConverter
{
Task ConvertAsync(Stream? input, TextWriter? output);
string GetOutputFile(string? inputFile, string? outputPath = null);
Task ConvertAsync(Stream input, TextWriter output);
string GetOutputFile(string inputFile, string? outputPath = null);
}
}
12 changes: 6 additions & 6 deletions source/trx2junit/Extensions/XElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static class XElementExtensions
{
public static DateTime? ReadDateTime(this XElement element, string attributeName)
{
string value = (string)element.Attribute(attributeName);
string? value = (string?)element.Attribute(attributeName);

if (!DateTime.TryParse(value, out DateTime dt))
return null;
Expand All @@ -18,7 +18,7 @@ internal static class XElementExtensions
//---------------------------------------------------------------------
public static TimeSpan? ReadTimeSpan(this XElement element, string attributeName)
{
string value = (string)element.Attribute(attributeName);
string? value = (string?)element.Attribute(attributeName);

if (!TimeSpan.TryParse(value, out TimeSpan ts))
return null;
Expand All @@ -28,7 +28,7 @@ internal static class XElementExtensions
//---------------------------------------------------------------------
public static int? ReadInt(this XElement element, string attributeName)
{
string value = (string)element.Attribute(attributeName);
string? value = (string?)element.Attribute(attributeName);

if (!int.TryParse(value, out int res))
return null;
Expand All @@ -38,7 +38,7 @@ internal static class XElementExtensions
//---------------------------------------------------------------------
public static double ReadDouble(this XElement element, string attributeName)
{
string value = (string)element.Attribute(attributeName);
string? value = (string?)element.Attribute(attributeName);

if (!double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out double res))
throw new Exception($"The required attribute '{attributeName}' does not exists");
Expand All @@ -48,7 +48,7 @@ public static double ReadDouble(this XElement element, string attributeName)
//---------------------------------------------------------------------
public static Guid ReadGuid(this XElement element, string attributeName)
{
string? value = (string)element.Attribute(attributeName);
string? value = (string?)element.Attribute(attributeName);

return Guid.TryParse(value, out Guid guid)
? guid
Expand All @@ -65,7 +65,7 @@ public static bool Write<T>(this XElement element, string attributeName, T? null

if (!nullable.HasValue) return false;

element.Add(new XAttribute(attributeName, nullable.Value.ToString()));
element.Add(new XAttribute(attributeName, nullable.Value.ToString()!));

return true;
}
Expand Down
8 changes: 4 additions & 4 deletions source/trx2junit/Internal/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;

namespace trx2junit
{
public class FileSystem : IFileSystem
{
public Stream OpenRead(string? path)
public Stream OpenRead(string path)
=> File.OpenRead(path);
//---------------------------------------------------------------------
public void CreateDirectory(string? directory)
public void CreateDirectory(string directory)
=> Directory.CreateDirectory(directory);
//---------------------------------------------------------------------
public IEnumerable<string> EnumerateFiles(string? path, string? pattern)
public IEnumerable<string> EnumerateFiles(string path, string pattern)
=> Directory.EnumerateFiles(path, pattern, SearchOption.TopDirectoryOnly);
}
}
8 changes: 4 additions & 4 deletions source/trx2junit/Internal/GlobHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace trx2junit
{
Expand All @@ -15,7 +14,7 @@ public GlobHandler(IFileSystem fileSystem)
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
}
//---------------------------------------------------------------------
public void ExpandWildcards(WorkerOptions? options)
public void ExpandWildcards(WorkerOptions options)
{
if (options == null) throw new ArgumentNullException(nameof(options));

Expand All @@ -38,8 +37,9 @@ public void ExpandWildcards(WorkerOptions? options)
private void Expand(string input, List<string> expandedFiles)
{
string? path = Path.GetDirectoryName(input);
Debug.Assert(path != null);
Debug.Assert(path is not null);
string pattern = Path.GetFileName(input);
Debug.Assert(pattern is not null);

IEnumerable<string> files = _fileSystem.EnumerateFiles(path, pattern);

Expand Down
6 changes: 3 additions & 3 deletions source/trx2junit/Internal/TestResultXmlConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -15,7 +15,7 @@ public abstract class TestResultXmlConverter<TIn, TOut> : ITestResultXmlConverte
protected abstract Func<TOut, ITestResultXmlBuilder<TOut>> BuilderFactory { get; }
protected abstract string Extension { get; }
//---------------------------------------------------------------------
public virtual async Task ConvertAsync(Stream? input, TextWriter? output)
public virtual async Task ConvertAsync(Stream input, TextWriter output)
{
XElement testXml = await XElement.LoadAsync(input, LoadOptions.None, CancellationToken.None);

Expand All @@ -33,7 +33,7 @@ public virtual async Task ConvertAsync(Stream? input, TextWriter? output)
await builder.Result.SaveAsync(output, SaveOptions.None, CancellationToken.None);
}
//---------------------------------------------------------------------
public string GetOutputFile(string? inputFile, string? outputPath = null)
public string GetOutputFile(string inputFile, string? outputPath = null)
{
if (inputFile == null) throw new ArgumentNullException(nameof(inputFile));

Expand Down
4 changes: 2 additions & 2 deletions source/trx2junit/Internal/junit2trx/JUnit2TrxTestConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
Expand All @@ -11,7 +11,7 @@ public class JUnit2TrxTestConverter : ITestConverter<JUnitTest, TrxTest>
public JUnitTest SourceTest { get; }
public TrxTest Result { get; } = new TrxTest();
//---------------------------------------------------------------------
public JUnit2TrxTestConverter(JUnitTest? junitTest)
public JUnit2TrxTestConverter(JUnitTest junitTest)
{
this.SourceTest = junitTest ?? throw new ArgumentNullException(nameof(junitTest));
}
Expand Down
19 changes: 10 additions & 9 deletions source/trx2junit/Internal/junit2trx/JUnitTestResultXmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using trx2junit.Resources;
using System.Diagnostics;

namespace trx2junit
{
Expand All @@ -13,7 +14,7 @@ public class JUnitTestResultXmlParser : ITestResultXmlParser<JUnitTest>
private readonly XElement _junit;
private readonly JUnitTest _test = new JUnitTest();
//---------------------------------------------------------------------
public JUnitTestResultXmlParser(XElement? junit) => _junit = junit ?? throw new ArgumentNullException(nameof(junit));
public JUnitTestResultXmlParser(XElement junit) => _junit = junit ?? throw new ArgumentNullException(nameof(junit));
//---------------------------------------------------------------------
public JUnitTest Result => _test;
//---------------------------------------------------------------------
Expand Down Expand Up @@ -44,8 +45,8 @@ private static JUnitTestSuite ParseTestSuite(XElement xTestSuite)
{
var testSuite = new JUnitTestSuite
{
Name = xTestSuite.Attribute("name").Value,
HostName = xTestSuite.Attribute("hostname").Value,
Name = xTestSuite.Attribute("name")!.Value,
HostName = xTestSuite.Attribute("hostname")!.Value,
Id = xTestSuite.ReadInt("id"),
ErrorCount = xTestSuite.ReadInt("errors"),
FailureCount = xTestSuite.ReadInt("failures"),
Expand Down Expand Up @@ -103,8 +104,8 @@ private static bool TryParseProperty(XElement xProperty, [NotNullWhen(true)] out

property = new JUnitProperty
{
Name = xProperty.Attribute("name").Value,
Value = xProperty.Attribute("value").Value
Name = xProperty.Attribute("name")!.Value,
Value = xProperty.Attribute("value")!.Value
};

return true;
Expand All @@ -114,8 +115,8 @@ private static JUnitTestCase ParseTestCase(XElement xTestCase)
{
var testCase = new JUnitTestCase
{
Name = xTestCase.Attribute("name").Value,
ClassName = xTestCase.Attribute("classname").Value,
Name = xTestCase.Attribute("name")!.Value,
ClassName = xTestCase.Attribute("classname")!.Value,
TimeInSeconds = xTestCase.ReadDouble("time"),
};

Expand All @@ -130,8 +131,8 @@ private static JUnitTestCase ParseTestCase(XElement xTestCase)
{
testCase.Error = new JUnitError
{
Type = xFailure.Attribute("type").Value,
Message = xFailure.Attribute("message").Value
Type = xFailure.Attribute("type")!.Value,
Message = xFailure.Attribute("message")!.Value
};
}

Expand Down
Loading

0 comments on commit 55b6028

Please sign in to comment.