-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for architecture switch feature (#3253)
Add tests for architecture switch feature
- Loading branch information
1 parent
582397c
commit 909b176
Showing
11 changed files
with
649 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if !NET451 | ||
|
||
namespace Microsoft.TestPlatform.AcceptanceTests | ||
{ | ||
using Microsoft.TestPlatform.TestUtilities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
[TestClass] | ||
[TestCategory("Windows-Review")] | ||
public class DotnetArchitectureSwitchTestsWindowsOnly : AcceptanceTestBase | ||
{ | ||
[TestMethod] | ||
[DataRow("X64", "X86")] | ||
[DataRow("X86", "X64")] | ||
public void Use_EnvironmentVariables(string architectureFrom, string architectureTo) | ||
{ | ||
using (Workspace workSpace = new Workspace(GetResultsDirectory())) | ||
{ | ||
string dotnetPath = GetDownloadedDotnetMuxerFromTools(architectureFrom); | ||
string dotnetPathTo = GetDownloadedDotnetMuxerFromTools(architectureTo); | ||
var vstestConsolePath = GetDotnetRunnerPath(); | ||
var dotnetRunnerPath = workSpace.CreateDirectory("dotnetrunner"); | ||
workSpace.CopyAll(new DirectoryInfo(Path.GetDirectoryName(vstestConsolePath)), dotnetRunnerPath); | ||
|
||
// Patch the runner | ||
string sdkVersion = GetLatestSdkVersion(dotnetPath); | ||
string runtimeConfigFile = Path.Combine(dotnetRunnerPath.FullName, "vstest.console.runtimeconfig.json"); | ||
JObject patchRuntimeConfig = JObject.Parse(File.ReadAllText(runtimeConfigFile)); | ||
patchRuntimeConfig["runtimeOptions"]["framework"]["version"] = sdkVersion; | ||
File.WriteAllText(runtimeConfigFile, patchRuntimeConfig.ToString()); | ||
|
||
var environmentVariables = new Dictionary<string, string> | ||
{ | ||
["DOTNET_MULTILEVEL_LOOKUP"] = "0", | ||
[$"DOTNET_ROOT_{architectureTo}"] = Path.GetDirectoryName(dotnetPathTo), | ||
["ExpectedArchitecture"] = architectureTo | ||
}; | ||
this.ExecuteApplication(dotnetPath, "new mstest", out string stdOut, out string stdError, out int exitCode, environmentVariables, workSpace.Path); | ||
|
||
// Patch test file | ||
File.WriteAllText(Path.Combine(workSpace.Path, "UnitTest1.cs"), | ||
@" | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
namespace cfebbc5339cf4c22854e79824e938c74; | ||
[TestClass] | ||
public class UnitTest1 | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
Assert.AreEqual(Environment.GetEnvironmentVariable(""ExpectedArchitecture""), System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString()); | ||
} | ||
}"); | ||
|
||
this.ExecuteApplication(dotnetPath, $"test -p:VsTestConsolePath=\"{Path.Combine(dotnetRunnerPath.FullName, Path.GetFileName(vstestConsolePath))}\" --arch {architectureTo.ToLower()} --diag:log.txt", out stdOut, out stdError, out exitCode, environmentVariables, workSpace.Path); | ||
Assert.AreEqual(0, exitCode, stdOut); | ||
|
||
environmentVariables = new Dictionary<string, string> | ||
{ | ||
["DOTNET_MULTILEVEL_LOOKUP"] = "0", | ||
["DOTNET_ROOT"] = Path.GetDirectoryName(dotnetPathTo), | ||
["ExpectedArchitecture"] = architectureTo | ||
}; | ||
this.ExecuteApplication(dotnetPath, $"test -p:VsTestConsolePath=\"{Path.Combine(dotnetRunnerPath.FullName, Path.GetFileName(vstestConsolePath))}\" --arch {architectureTo.ToLower()} --diag:log.txt", out stdOut, out stdError, out exitCode, environmentVariables, workSpace.Path); | ||
Assert.AreEqual(0, exitCode, stdOut); | ||
|
||
environmentVariables = new Dictionary<string, string> | ||
{ | ||
["DOTNET_MULTILEVEL_LOOKUP"] = "0", | ||
[$"DOTNET_ROOT_{architectureTo}"] = Path.GetDirectoryName(dotnetPathTo), | ||
["DOTNET_ROOT"] = "WE SHOULD PICK THE ABOVE ONE BEFORE FALLBACK TO DOTNET_ROOT", | ||
["ExpectedArchitecture"] = architectureTo | ||
}; | ||
this.ExecuteApplication(dotnetPath, $"test -p:VsTestConsolePath=\"{Path.Combine(dotnetRunnerPath.FullName, Path.GetFileName(vstestConsolePath))}\" --arch {architectureTo.ToLower()} --diag:log.txt", out stdOut, out stdError, out exitCode, environmentVariables, workSpace.Path); | ||
Assert.AreEqual(0, exitCode, stdOut); | ||
} | ||
} | ||
|
||
private string GetLatestSdkVersion(string dotnetPath) | ||
=> Path.GetFileName(Directory.GetDirectories(Path.Combine(Path.GetDirectoryName(dotnetPath), @"shared/Microsoft.NETCore.App")).OrderByDescending(x => x).First()); | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.