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.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
|
@ -18,14 +17,28 @@ namespace Microsoft.DotNet.Tests
|
|||
[Fact]
|
||||
public void VersionCommandDisplaysCorrectVersion()
|
||||
{
|
||||
var versionFilePath = Path.Combine(AppContext.BaseDirectory, ".version");
|
||||
var version = GetVersionFromFile(versionFilePath);
|
||||
|
||||
CommandResult result = new DotnetCommand()
|
||||
.ExecuteWithCapturedOutput("--version");
|
||||
|
||||
result.Should().Pass();
|
||||
|
||||
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}");
|
||||
result.StdOut.Trim().Should().Be(version);
|
||||
}
|
||||
|
||||
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>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\artifacts\*\stage2\sdk\*\.version">
|
||||
<Link>.version</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in a new issue