Merge pull request #5700 from livarcocc/update_version_test
Updating the version test to use .version file instead of regex
This commit is contained in:
commit
4d9e7f959a
2 changed files with 21 additions and 4 deletions
|
@ -4,7 +4,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Cli;
|
using Microsoft.DotNet.Cli;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
@ -18,14 +17,28 @@ namespace Microsoft.DotNet.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void VersionCommandDisplaysCorrectVersion()
|
public void VersionCommandDisplaysCorrectVersion()
|
||||||
{
|
{
|
||||||
|
var versionFilePath = Path.Combine(AppContext.BaseDirectory, ".version");
|
||||||
|
var version = GetVersionFromFile(versionFilePath);
|
||||||
|
|
||||||
CommandResult result = new DotnetCommand()
|
CommandResult result = new DotnetCommand()
|
||||||
.ExecuteWithCapturedOutput("--version");
|
.ExecuteWithCapturedOutput("--version");
|
||||||
|
|
||||||
result.Should().Pass();
|
result.Should().Pass();
|
||||||
|
result.StdOut.Trim().Should().Be(version);
|
||||||
Regex.IsMatch(result.StdOut.Trim(), @"[0-9]{1}\.[0-9]{1}\.[0-9]{1}-[a-zA-Z0-9]+-[0-9]{6}$").Should()
|
}
|
||||||
.BeTrue($"Unexpected dotnet sdk version - {result.StdOut}");
|
|
||||||
|
|
||||||
|
private string GetVersionFromFile(string versionFilePath)
|
||||||
|
{
|
||||||
|
using (var reader = new StreamReader(File.OpenRead(versionFilePath)))
|
||||||
|
{
|
||||||
|
SkipCommit(reader);
|
||||||
|
return reader.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SkipCommit(StreamReader reader)
|
||||||
|
{
|
||||||
|
reader.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,10 @@
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="..\..\artifacts\*\stage2\sdk\*\.version">
|
||||||
|
<Link>.version</Link>
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in a new issue