From 54464dda3655150b193071cf4141587d2e573eca Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Tue, 14 Feb 2017 10:30:28 -0800 Subject: [PATCH] Updating the version test to check that dotnet --version uses the .version file instead of using a regular expression to validate the printed version. --- test/dotnet.Tests/VersionTest.cs | 21 +++++++++++++++++---- test/dotnet.Tests/dotnet.Tests.csproj | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/test/dotnet.Tests/VersionTest.cs b/test/dotnet.Tests/VersionTest.cs index bff9afd10..0192f5fd8 100644 --- a/test/dotnet.Tests/VersionTest.cs +++ b/test/dotnet.Tests/VersionTest.cs @@ -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(); } } } diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 1819341b9..e80b28426 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -22,6 +22,10 @@ PreserveNewest PreserveNewest + + .version + PreserveNewest +