Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Oct 20, 2020
2 parents 98d1e29 + 189d65d commit 7d53c94
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<PropertyGroup>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<Version>0.10.7</Version>
<Version>0.10.9</Version>
</PropertyGroup>
</Project>
46 changes: 42 additions & 4 deletions Synthesis.Bethesda.Execution/DotNetQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -44,14 +46,50 @@ public static class DotNetQueries
var ret = new List<(string Package, string Requested, string Resolved, string Latest)>();
foreach (var line in lines)
{
var startIndex = line.IndexOf("> ");
if (startIndex == -1) continue;
var split = line.Substring(startIndex + 2).Split(' ', StringSplitOptions.RemoveEmptyEntries);
ret.Add((split[0], split[1], split[2], split[3]));
if (!TryParseLibraryLine(
line,
out var package,
out var requested,
out var resolved,
out var latest))
{
continue;
}
ret.Add((package, requested, resolved, latest));
}
return ret;
}

public static bool TryParseLibraryLine(
string line,
[MaybeNullWhen(false)] out string package,
[MaybeNullWhen(false)] out string requested,
[MaybeNullWhen(false)] out string resolved,
[MaybeNullWhen(false)] out string latest)
{
var startIndex = line.IndexOf("> ");
if (startIndex == -1)
{
package = default;
requested = default;
resolved = default;
latest = default;
return false;
}
var split = line
.Substring(startIndex + 2)
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.WithIndex()
.Where(x => x.Index == 0 || Version.TryParse(x.Item, out _))
.Select(x => x.Item)
.ToArray();
package = split[0];
requested = split[1];
resolved = split[2];
latest = split[3];
return true;
}

public static async Task<(string? MutagenVersion, string? SynthesisVersion)> QuerySynthesisVersions(string projectPath, bool current)
{
string? mutagenVersion = null, synthesisVersion = null;
Expand Down
44 changes: 44 additions & 0 deletions Synthesis.Bethesda.UnitTests/NugetVersionQueriesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using FluentAssertions;
using Synthesis.Bethesda.Execution;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace Synthesis.Bethesda.UnitTests
{
public class NugetVersionQueriesTests
{
[Fact]
public void TypicalNugetParse()
{
DotNetQueries.TryParseLibraryLine(
" > Mutagen.Bethesda.Synthesis 0.10.7.0 0.10.7 0.10.8.1",
out var package,
out var requested,
out var resolved,
out var latest)
.Should().BeTrue();
package.Should().Be("Mutagen.Bethesda.Synthesis");
requested.Should().Be("0.10.7.0");
resolved.Should().Be("0.10.7");
latest.Should().Be("0.10.8.1");
}

[Fact]
public void DepreciatedNugetParse()
{
DotNetQueries.TryParseLibraryLine(
" > Mutagen.Bethesda.Synthesis 0.10.7.0 0.10.7 (D) 0.10.8.1",
out var package,
out var requested,
out var resolved,
out var latest)
.Should().BeTrue();
package.Should().Be("Mutagen.Bethesda.Synthesis");
requested.Should().Be("0.10.7.0");
resolved.Should().Be("0.10.7");
latest.Should().Be("0.10.8.1");
}
}
}

0 comments on commit 7d53c94

Please sign in to comment.