Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Aug 3, 2022
1 parent edb059a commit 057e974
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
10 changes: 4 additions & 6 deletions test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class IntegrationTestBase
private readonly string _xUnitTestAdapterRelativePath = @"xunit.runner.visualstudio\{0}\build\_common".Replace('\\', Path.DirectorySeparatorChar);
private readonly string _chutzpahTestAdapterRelativePath = @"chutzpah\{0}\tools".Replace('\\', Path.DirectorySeparatorChar);

protected static readonly bool IsWindows = Environment.OSVersion.Platform.ToString().StartsWith("Win");

public enum UnitTestFramework
{
NUnit, XUnit, MSTest, CPP, Chutzpah
Expand Down Expand Up @@ -626,7 +624,7 @@ public virtual string GetConsoleRunnerPath()
}
else if (IsNetCoreRunner())
{
var executablePath = IsWindows ? @"dotnet\dotnet.exe" : @"dotnet-linux/dotnet";
var executablePath = TestUtils.IsWindows ? @"dotnet\dotnet.exe" : @"dotnet-linux/dotnet";
consoleRunnerPath = Path.Combine(_testEnvironment.ToolsDirectory, executablePath);
}
else
Expand Down Expand Up @@ -678,7 +676,7 @@ public IVsTestConsoleWrapper GetVsTestConsoleWrapper(Dictionary<string, string?>
var consoleRunnerPath = IsNetCoreRunner()
? GetDotnetRunnerPath()
: GetConsoleRunnerPath();
var executablePath = IsWindows ? @"dotnet\dotnet.exe" : @"dotnet-linux/dotnet";
var executablePath = TestUtils.IsWindows ? @"dotnet\dotnet.exe" : @"dotnet-linux/dotnet";
var dotnetPath = Path.Combine(_testEnvironment.ToolsDirectory, executablePath);

if (!File.Exists(dotnetPath))
Expand Down Expand Up @@ -770,7 +768,7 @@ private void ExecutePatchedDotnet(string command, string args, out string stdOut

environmentVariables["DOTNET_MULTILEVEL_LOOKUP"] = "0";

var executablePath = IsWindows ? @"dotnet\dotnet.exe" : @"dotnet-linux/dotnet";
var executablePath = TestUtils.IsWindows ? @"dotnet\dotnet.exe" : @"dotnet-linux/dotnet";
var patchedDotnetPath = Path.Combine(_testEnvironment.TestArtifactsDirectory, executablePath);
ExecuteApplication(patchedDotnetPath, string.Join(" ", command, args), out stdOut, out stdError, out exitCode, environmentVariables);
}
Expand Down Expand Up @@ -954,7 +952,7 @@ protected static string GetDownloadedDotnetMuxerFromTools(string architecture)
architecture == "X86" ?
"dotnet_x86" :
$"dotnet",
$"dotnet{(IsWindows ? ".exe" : "")}");
$"dotnet{(TestUtils.IsWindows ? ".exe" : "")}");

Assert.IsTrue(File.Exists(path));

Expand Down
11 changes: 11 additions & 0 deletions test/Microsoft.TestPlatform.TestUtilities/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Microsoft.TestPlatform.TestUtilities;

public static class TestUtils
{
public static bool IsWindows { get; } = Environment.OSVersion.Platform.ToString().StartsWith("Win");
}
7 changes: 5 additions & 2 deletions test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.TestPlatform.TestUtilities;

using Moq;

Expand Down Expand Up @@ -855,8 +856,10 @@ public void TestRunCompleteHandlerCorrectlySplitPathsForSourceName()
// Assert
_mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework, "MyApp1.Tests.dll", ""), OutputLevel.Information), Times.Once());
_mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework, "MyApp2.Tests.dll", ""), OutputLevel.Information), Times.Once());
_mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework, "MyApp3.Tests.dll", ""), OutputLevel.Information), Times.Once());
_mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework, "MyApp4.Tests.dll", ""), OutputLevel.Information), Times.Once());
// On Linux and MAC we don't support backslash for path so source name will contain backslashes.
_mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework, TestUtils.IsWindows ? "MyApp3.Tests.dll" : "MyApp3.Tests\\MyApp3.Tests.dll", ""), OutputLevel.Information), Times.Once());
// On Linux and MAC we don't support backslash for path so source name will contain backslashes.
_mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework, TestUtils.IsWindows ? "MyApp4.Tests.dll" : "C:\\MyApp4\\Tests\\MyApp4.Tests\\MyApp4.Tests.dll", ""), OutputLevel.Information), Times.Once());
_mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryAssemblyAndFramework, "MyApp5.Tests.dll", ""), OutputLevel.Information), Times.Once());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.PlatformAbstractions\Microsoft.TestPlatform.PlatformAbstractions.csproj">
<FromP2P>true</FromP2P>
</ProjectReference>
<ProjectReference Include="..\Microsoft.TestPlatform.TestUtilities\Microsoft.TestPlatform.TestUtilities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
Expand Down

0 comments on commit 057e974

Please sign in to comment.