From bf43157b451cdea157da1462f4f3e5863c3f27db Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Tue, 20 Jun 2017 20:36:12 +0530 Subject: [PATCH] Add platform abstraction for OS name and architecture. (#851) * Add platform abstraction for OS name and architecture. Related #820 #679 * Fix build failures due to incorrect references. * Publish projects for net46 if mono is available. * Fix typo in build script. * Support for mono in multitargeted tests. Choose mono as launcher for net46 tests if the launcher for vstest.console is not mono (e.g. dotnet test). --- scripts/build.sh | 106 ++++++++++-------- .../Helpers/DotnetHostHelper.cs | 61 ++++++---- .../Helpers/Interfaces/IDotnetHostHelper.cs | 10 +- .../Resources/Resources.resx | 2 +- .../Resources/xlf/Resources.cs.xlf | 6 +- .../Resources/xlf/Resources.de.xlf | 6 +- .../Resources/xlf/Resources.es.xlf | 6 +- .../Resources/xlf/Resources.fr.xlf | 6 +- .../Resources/xlf/Resources.it.xlf | 6 +- .../Resources/xlf/Resources.ja.xlf | 6 +- .../Resources/xlf/Resources.ko.xlf | 6 +- .../Resources/xlf/Resources.pl.xlf | 6 +- .../Resources/xlf/Resources.pt-BR.xlf | 6 +- .../Resources/xlf/Resources.ru.xlf | 6 +- .../Resources/xlf/Resources.tr.xlf | 6 +- .../Resources/xlf/Resources.xlf | 2 +- .../Resources/xlf/Resources.zh-Hans.xlf | 6 +- .../Resources/xlf/Resources.zh-Hant.xlf | 6 +- .../Utilities/XmlRunSettingsUtilities.cs | 68 +---------- .../Interfaces/System/IEnvironment.cs | 23 ++++ .../{Process => System}/IProcessHelper.cs | 0 .../Interfaces/System/PlatformArchitecture.cs | 18 +++ .../System/PlatformOperationSystem.cs | 16 +++ ...t.TestPlatform.PlatformAbstractions.csproj | Bin 4256 -> 4578 bytes .../{Process => System}/ProcessHelper.cs | 0 .../net46/System/PlatformEnvironment.cs | 43 +++++++ .../netcore/System/PlatformEnvironment.cs | 48 ++++++++ .../System/PlatformEnvironment.cs | 30 +++++ .../{Process => System}/ProcessHelper.cs | 0 .../Hosting/DefaultTestHostManager.cs | 22 +++- .../Hosting/DotnetTestHostManager.cs | 2 +- .../Hosting/DefaultTestHostManagerTests.cs | 50 ++++++++- .../Hosting/DotnetTestHostManagerTests.cs | 4 +- ...Platform.TestHostProvider.UnitTests.csproj | 1 + 34 files changed, 403 insertions(+), 181 deletions(-) create mode 100644 src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IEnvironment.cs rename src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/{Process => System}/IProcessHelper.cs (100%) create mode 100644 src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformArchitecture.cs create mode 100644 src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformOperationSystem.cs rename src/Microsoft.TestPlatform.PlatformAbstractions/common/{Process => System}/ProcessHelper.cs (100%) create mode 100644 src/Microsoft.TestPlatform.PlatformAbstractions/net46/System/PlatformEnvironment.cs create mode 100644 src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/PlatformEnvironment.cs create mode 100644 src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/PlatformEnvironment.cs rename src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/{Process => System}/ProcessHelper.cs (100%) diff --git a/scripts/build.sh b/scripts/build.sh index b2534008c9..4c22bfa5a6 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -87,6 +87,7 @@ DOTNET_RUNTIME_VERSION="2.0.0-preview2-25331-01" # Build configuration # TPB_Solution="TestPlatform.sln" +TPB_TargetFramework="net46" TPB_TargetFrameworkCore="netcoreapp2.0" TPB_TargetFrameworkCore10="netcoreapp1.0" TPB_Configuration=$CONFIGURATION @@ -203,8 +204,6 @@ function invoke_build() log ".. .. Build: Source: $TPB_Solution" if $TPB_HasMono; then - # Workaround for https://github.com/dotnet/sdk/issues/335 - export FrameworkPathOverride=/usr/lib/mono/4.5/ if [ -z "$PROJECT_NAME_PATTERNS" ] then $dotnet build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild || failed=true @@ -259,57 +258,71 @@ function publish_package() log "publish_package: Started." local start=$SECONDS - coreCLRPackageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFrameworkCore - - PROJECTPACKAGEOUTPUTMAP=( \ - $TP_PACKAGE_PROJ_DIR/package.csproj:$coreCLRPackageDir \ - $TP_ROOT_DIR/src/vstest.console/vstest.console.csproj:$coreCLRPackageDir \ - $TP_ROOT_DIR/src/datacollector/datacollector.csproj:$coreCLRPackageDir + local packageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFramework/$TPB_TargetRuntime + local coreCLRPackageDir=$TP_OUT_DIR/$TPB_Configuration/$TPB_TargetFrameworkCore + local frameworkPackageDirMap=( \ + $TPB_TargetFrameworkCore:$coreCLRPackageDir \ + $TPB_TargetFramework:$packageDir ) - - for item in "${PROJECTPACKAGEOUTPUTMAP[@]}" ; + + for fxpkg in "${frameworkPackageDirMap[@]}" ; do - projectToPackage="${item%%:*}" - packageOutputPath="${item##*:}" - log "Package: Publish $projectToPackage" - $dotnet publish $projectToPackage --configuration $TPB_Configuration --framework $TPB_TargetFrameworkCore --output $packageOutputPath -v:minimal -p:LocalizedBuild=$TPB_LocalizedBuild + local framework="${fxpkg%%:*}" + local packageDir="${fxpkg##*:}" + local projects=( \ + $TP_PACKAGE_PROJ_DIR/package.csproj \ + $TP_ROOT_DIR/src/vstest.console/vstest.console.csproj \ + $TP_ROOT_DIR/src/datacollector/datacollector.csproj + ) + + if [ "$framework" == "net46" ] && ! $TPB_HasMono; then + # Skip publish if mono is not available + continue + fi + + log "Package: Publish projects for $framework" + for project in "${projects[@]}" ; + do + log ".. Package: Publish $project" + $dotnet publish $project --configuration $TPB_Configuration --framework $framework --output $packageDir -v:minimal -p:LocalizedBuild=$TPB_LocalizedBuild + done + + # Copy TestHost for desktop targets if we've built net46 + # packages with mono + if $TPB_HasMono; then + local testhost=$packageDir/TestHost + mkdir -p $testhost + cp -r src/testhost/bin/$TPB_Configuration/net46/win7-x64/* $testhost + cp -r src/testhost.x86/bin/$TPB_Configuration/net46/win7-x64/* $testhost + fi + + # Copy over the logger assemblies to the Extensions folder. + local extensionsDir="$packageDir/Extensions" + # Create an extensions directory. + mkdir -p $extensionsDir + + # Note Note: If there are some dependencies for the logger assemblies, those need to be moved too. + # Ideally we should just be publishing the loggers to the Extensions folder. + loggers=("Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll" "Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.pdb") + for i in ${loggers[@]}; do + mv $packageDir/${i} $extensionsDir + done + + # Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too. + runtimeproviders=("Microsoft.TestPlatform.TestHostRuntimeProvider.dll" "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb") + for i in ${runtimeproviders[@]}; do + mv $packageDir/${i} $extensionsDir + done + newtonsoft=$TP_PACKAGES_DIR/newtonsoft.json/9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll + cp $newtonsoft $packageDir done # Publish TestHost for netcoreapp1.0 target - log "Package: Publish testhost.csproj" + log ".. Package: Publish testhost.csproj" local projectToPackage=$TP_ROOT_DIR/src/testhost/testhost.csproj local packageOutputPath=$TP_OUT_DIR/$TPB_Configuration/Microsoft.TestPlatform.TestHost/$TPB_TargetFrameworkCore10 $dotnet publish $projectToPackage --configuration $TPB_Configuration --framework $TPB_TargetFrameworkCore10 --output $packageOutputPath -v:minimal -p:LocalizedBuild=$TPB_LocalizedBuild - # Copy TestHost for desktop targets if we've built net46 - # packages with mono - if $TPB_HasMono; then - local testhost=$coreCLRPackageDir/TestHost - mkdir -p $testhost - cp -r src/testhost/bin/$TPB_Configuration/net46/win7-x64/* $testhost - cp -r src/testhost.x86/bin/$TPB_Configuration/net46/win7-x64/* $testhost - fi - - # Copy over the logger assemblies to the Extensions folder. - coreCLRExtensionsDir="$coreCLRPackageDir/Extensions" - # Create an extensions directory. - mkdir -p $coreCLRExtensionsDir - - # Note Note: If there are some dependencies for the logger assemblies, those need to be moved too. - # Ideally we should just be publishing the loggers to the Extensions folder. - loggers=("Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll" "Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.pdb") - for i in ${loggers[@]}; do - mv $coreCLRPackageDir/${i} $coreCLRExtensionsDir - done - - # Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too. - runtimeproviders=("Microsoft.TestPlatform.TestHostRuntimeProvider.dll" "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb") - for i in ${runtimeproviders[@]}; do - mv $coreCLRPackageDir/${i} $coreCLRExtensionsDir - done - newtonsoft=$TP_PACKAGES_DIR/newtonsoft.json/9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll - cp $newtonsoft $coreCLRPackageDir - # For libraries that are externally published, copy the output into artifacts. These will be signed and packaged independently. packageName="Microsoft.TestPlatform.Build" binariesDirectory="src/$packageName/bin/$TPB_Configuration/**" @@ -397,6 +410,11 @@ log "Test platform environment variables: " log "Test platform build variables: " (set | grep ^TPB_) +if $TPB_HasMono; then + # Workaround for https://github.com/dotnet/sdk/issues/335 + export FrameworkPathOverride=/usr/lib/mono/4.5/ +fi + if [ -z "$PROJECT_NAME_PATTERNS" ] then install_cli && restore_package && invoke_build && publish_package && create_package diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs index 4bf0dfdd16..3d82aff821 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs @@ -10,17 +10,22 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Resources; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; public class DotnetHostHelper : IDotnetHostHelper { + public const string MONOEXENAME = "mono"; + private readonly IFileHelper fileHelper; + private readonly IEnvironment environment; /// /// Initializes a new instance of the class. /// - public DotnetHostHelper() : this(new FileHelper()) + public DotnetHostHelper() : this(new FileHelper(), new PlatformEnvironment()) { } @@ -28,41 +33,59 @@ public DotnetHostHelper() : this(new FileHelper()) /// Initializes a new instance of the class. /// /// File Helper - public DotnetHostHelper(IFileHelper fileHelper) + public DotnetHostHelper(IFileHelper fileHelper, IEnvironment environment) { this.fileHelper = fileHelper; + this.environment = environment; } /// - public string GetDotnetHostFullPath() + public string GetDotnetPath() { - char separator = ';'; - var dotnetExeName = "dotnet.exe"; + if (!TryGetExecutablePath("dotnet", out string dotnetPath)) + { + string errorMessage = string.Format(Resources.NoDotnetExeFound, "dotnet"); + + EqtTrace.Error(errorMessage); + throw new FileNotFoundException(errorMessage); + } -#if !NET46 - // Use semicolon(;) as path separator for windows - // colon(:) for Linux and OSX - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return dotnetPath; + } + + public string GetMonoPath() + { + if (!TryGetExecutablePath(MONOEXENAME, out string monoPath)) { - separator = ':'; - dotnetExeName = "dotnet"; + string errorMessage = string.Format(Resources.NoDotnetExeFound, MONOEXENAME); + + EqtTrace.Error(errorMessage); + throw new FileNotFoundException(errorMessage); } -#endif + return monoPath; + } + + private bool TryGetExecutablePath(string executableBaseName, out string executablePath) + { + if (this.environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows)) + { + executableBaseName = executableBaseName + ".exe"; + } + + executablePath = string.Empty; var pathString = Environment.GetEnvironmentVariable("PATH"); - foreach (string path in pathString.Split(separator)) + foreach (string path in pathString.Split(Path.PathSeparator)) { - string exeFullPath = Path.Combine(path.Trim(), dotnetExeName); + string exeFullPath = Path.Combine(path.Trim(), executableBaseName); if (this.fileHelper.Exists(exeFullPath)) { - return exeFullPath; + executablePath = exeFullPath; + return true; } } - string errorMessage = string.Format(Resources.NoDotnetExeFound, dotnetExeName); - - EqtTrace.Error(errorMessage); - throw new FileNotFoundException(errorMessage); + return false; } } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs index 05cb904c39..6793748a4b 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs @@ -9,10 +9,16 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces public interface IDotnetHostHelper { /// - /// Get full path for the .net host + /// Gets the full path for of .net core host. /// /// Full path to dotnet executable /// Debuggers require the full path of executable to launch it. - string GetDotnetHostFullPath(); + string GetDotnetPath(); + + /// + /// Gets the full path of mono host. + /// + /// Full path to mono executable + string GetMonoPath(); } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx b/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx index a57060159f..ba520ac0b1 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx @@ -154,7 +154,7 @@ Unhandled exception occurred while processing a job from the '{0}' queue: {1} - Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. The {0} queue has already been disposed. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf index 7418168e24..aaaff15cd5 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - Nejde najít {0}. Ujistěte se, že na počítači je nainstalovaný dotnet. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + Nejde najít {0}. Ujistěte se, že na počítači je nainstalovaný dotnet. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf index 4931f5d78a..b18a002776 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - {0} wurde nicht gefunden. Stellen Sie sicher, dass das dotnet auf dem Computer installiert ist. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + {0} wurde nicht gefunden. Stellen Sie sicher, dass das dotnet auf dem Computer installiert ist. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf index b56a766f13..64d9342414 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - No se pudo encontrar {0}. Asegúrese de que dotnet esté instalado en la máquina. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + No se pudo encontrar {0}. Asegúrese de que dotnet esté instalado en la máquina. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf index e1df021897..d30fddc460 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - {0} est introuvable. Vérifiez que le dotnet est installé sur la machine. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + {0} est introuvable. Vérifiez que le dotnet est installé sur la machine. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf index 9645849288..278d749da7 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - {0} non è stato trovato. Assicurarsi che dotnet sia installato nel computer. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + {0} non è stato trovato. Assicurarsi che dotnet sia installato nel computer. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf index 28006cf890..22b5d5d15d 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - {0} が見つかりませんでした。dotnet がマシンにインストールされていることを確認してください。 - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + {0} が見つかりませんでした。dotnet がマシンにインストールされていることを確認してください。 + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf index 6bf05fde36..6a5b0f4d53 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - {0}을(를) 찾을 수 없습니다. 컴퓨터에 dotnet이 설치되어 있는지 확인하세요. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + {0}을(를) 찾을 수 없습니다. 컴퓨터에 dotnet이 설치되어 있는지 확인하세요. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf index fe43be0020..f634cbefd0 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - Nie znaleziono elementu {0}. Upewnij się, że program dotnet jest zainstalowany na maszynie. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + Nie znaleziono elementu {0}. Upewnij się, że program dotnet jest zainstalowany na maszynie. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf index 9d3b50685a..e40572fb01 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - Não foi possível localizar {0}. Certifique-se de que o dotnet esteja instalado no computador. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + Não foi possível localizar {0}. Certifique-se de que o dotnet esteja instalado no computador. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf index c8e19772f3..c0452c6202 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - Не удалось найти {0}. Убедитесь, что dotnet установлен на компьютере. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + Не удалось найти {0}. Убедитесь, что dotnet установлен на компьютере. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf index 4edba2a280..21c46efaa8 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - {0} bulunamadı. Makinede dotnet’in yüklü olduğundan emin olun. - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + {0} bulunamadı. Makinede dotnet’in yüklü olduğundan emin olun. + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf index 0c91d32024..615147279b 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf @@ -63,7 +63,7 @@ - Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. Could not find {0}. Make sure that the dotnet is installed on the machine. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf index 565dce8b19..0e13989fa7 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - 找不到 {0}。请确保计算机上安装了 dotnet。 - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + 找不到 {0}。请确保计算机上安装了 dotnet。 + diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf index 717a1cc12a..c5220fc8de 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf @@ -156,9 +156,9 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" - Could not find {0}. Make sure that the dotnet is installed on the machine. - 找不到 {0}。請確定電腦上安裝了 .NET。 - + Could not find '{0}' host. Make sure that '{0}' is installed on the machine and is available in PATH environment variable. + 找不到 {0}。請確定電腦上安裝了 .NET。 + diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs index 8bb8f8bbf9..e190159891 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs @@ -12,6 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities using System.Xml; using System.Xml.XPath; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using ObjectModelResources = Microsoft.VisualStudio.TestPlatform.ObjectModel.Resources.Resources; /// @@ -26,22 +27,17 @@ public static ObjectModel.Architecture OSArchitecture { get { -#if NET46 - // This is a workaround for https://github.com/dotnet/corefx/issues/13566 - return WindowsSystemInformation.GetArchitecture(); -#else - var arch = RuntimeInformation.OSArchitecture; + var arch = new PlatformEnvironment().Architecture; switch (arch) { - case Architecture.X64: + case PlatformArchitecture.X64: return ObjectModel.Architecture.X64; - case Architecture.X86: + case PlatformArchitecture.X86: return ObjectModel.Architecture.X86; default: return ObjectModel.Architecture.ARM; } -#endif } } @@ -390,60 +386,4 @@ public static DataCollectionRunSettings GetInProcDataCollectionRunSettings(strin return null; } } - -#if NET46 - internal static class WindowsSystemInformation - { - internal const ushort PROCESSOR_ARCHITECTURE_INTEL = 0; - internal const ushort PROCESSOR_ARCHITECTURE_ARM = 5; - internal const ushort PROCESSOR_ARCHITECTURE_IA64 = 6; - internal const ushort PROCESSOR_ARCHITECTURE_AMD64 = 9; - internal const ushort PROCESSOR_ARCHITECTURE_UNKNOWN = 0xFFFF; - - [StructLayout(LayoutKind.Sequential)] - internal struct SYSTEM_INFO - { - public ushort wProcessorArchitecture; - public ushort wReserved; - public uint dwPageSize; - public IntPtr lpMinimumApplicationAddress; - public IntPtr lpMaximumApplicationAddress; - public UIntPtr dwActiveProcessorMask; - public uint dwNumberOfProcessors; - public uint dwProcessorType; - public uint dwAllocationGranularity; - public ushort wProcessorLevel; - public ushort wProcessorRevision; - }; - - [DllImport("kernel32.dll")] - internal static extern void GetNativeSystemInfo(ref SYSTEM_INFO lpSystemInfo); - - public static ObjectModel.Architecture GetArchitecture() - { - SYSTEM_INFO sysInfo = new SYSTEM_INFO(); - - // GetNativeSystemInfo is supported from Windows XP onwards. Since test platform - // requires Windows 7 OS at the minimum, we don't require a fallback. - GetNativeSystemInfo(ref sysInfo); - - switch (sysInfo.wProcessorArchitecture) - { - case PROCESSOR_ARCHITECTURE_INTEL: - return ObjectModel.Architecture.X86; - case PROCESSOR_ARCHITECTURE_ARM: - return ObjectModel.Architecture.ARM; - case PROCESSOR_ARCHITECTURE_IA64: - return ObjectModel.Architecture.X64; - case PROCESSOR_ARCHITECTURE_AMD64: - return ObjectModel.Architecture.X64; - case PROCESSOR_ARCHITECTURE_UNKNOWN: - EqtTrace.Error("WindowsSystemInformation.GetArchitecture: Unknown architecture found, will use default."); - break; - } - - return ObjectModel.Architecture.Default; - } - } -#endif } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IEnvironment.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IEnvironment.cs new file mode 100644 index 0000000000..9e45663ae2 --- /dev/null +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IEnvironment.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces +{ + using System; + + /// + /// Operating system environment abstractions. + /// + public interface IEnvironment + { + /// + /// Operating System architecture. + /// + PlatformArchitecture Architecture { get; } + + /// + /// Operating System name. + /// + PlatformOperatingSystem OperatingSystem { get; } + } +} diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/Process/IProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs similarity index 100% rename from src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/Process/IProcessHelper.cs rename to src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformArchitecture.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformArchitecture.cs new file mode 100644 index 0000000000..315ce99c15 --- /dev/null +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformArchitecture.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions +{ + using System; + + /// + /// Available architectures for test platform. + /// + public enum PlatformArchitecture + { + X86, + X64, + ARM, + ARM64 + } +} diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformOperationSystem.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformOperationSystem.cs new file mode 100644 index 0000000000..34b93b7309 --- /dev/null +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/PlatformOperationSystem.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions +{ + using System; + + /// + /// Available operating systems. + /// + public enum PlatformOperatingSystem + { + Windows, + Unix + } +} diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Microsoft.TestPlatform.PlatformAbstractions.csproj b/src/Microsoft.TestPlatform.PlatformAbstractions/Microsoft.TestPlatform.PlatformAbstractions.csproj index 59eb92501f09a8f8b2b4820a2ea86306d03d715a..9ca3c3477c387bad89a699756e1e96cf14f4feeb 100644 GIT binary patch delta 214 zcmZ3W_(*w!0}HzX0~l_0WYK4yoWRO5IgXEQG9Rnb_FllKw?Wx{=hY9@*W;5kiOs`hEj$+h7yKMhFpeJ20aE(FfWy%h#{Y$ zfFT$tR>V*SluZV*ih=T|>Ord0fGUfCx)Z^sG9KaDWxsLk{vRgM#;1OV9 J;bq`r000lLIn4k7 delta 90 zcmaE)yg+e-0}C@JgU#e_7SqjjEI*hSIVTIUs!l$~n>M+DpJ%cN#~h%@MRwQ8e>fJv bSrU`DRv + public class PlatformEnvironment : IEnvironment + { + /// + public PlatformArchitecture Architecture + { + get + { + // On Mono System.Runtime.InteropServices.RuntimeInformation breaks + // See https://github.com/dotnet/corefx/issues/15112 + // Support just x86 and x64 for now, likely our solution for ARM is going to be + // netcore based. + return Environment.Is64BitOperatingSystem ? PlatformArchitecture.X64 : PlatformArchitecture.X86; + } + } + + /// + public PlatformOperatingSystem OperatingSystem + { + get + { + // Ensure the value is detected appropriately for Desktop CLR, Mono CLR 1.x and Mono + // CLR 2.x. See below link for more information: + // http://www.mono-project.com/docs/faq/technical/#how-to-detect-the-execution-platform + int p = (int) System.Environment.OSVersion.Platform; + if ((p == 4) || (p == 6) || (p == 128)) + { + return PlatformOperatingSystem.Unix; + } + + return PlatformOperatingSystem.Windows; + } + } + } +} diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/PlatformEnvironment.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/PlatformEnvironment.cs new file mode 100644 index 0000000000..ebf56db7fc --- /dev/null +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/PlatformEnvironment.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions +{ + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; + using System; + using System.Runtime.InteropServices; + + /// + public class PlatformEnvironment : IEnvironment + { + /// + public PlatformArchitecture Architecture + { + get + { + switch (RuntimeInformation.OSArchitecture) + { + case System.Runtime.InteropServices.Architecture.X86: + return PlatformArchitecture.X86; + case System.Runtime.InteropServices.Architecture.X64: + return PlatformArchitecture.X64; + case System.Runtime.InteropServices.Architecture.Arm: + return PlatformArchitecture.ARM; + case System.Runtime.InteropServices.Architecture.Arm64: + return PlatformArchitecture.ARM64; + default: + throw new NotSupportedException(); + } + } + } + + /// + public PlatformOperatingSystem OperatingSystem + { + get + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return PlatformOperatingSystem.Windows; + } + + return PlatformOperatingSystem.Unix; + } + } + } +} diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/PlatformEnvironment.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/PlatformEnvironment.cs new file mode 100644 index 0000000000..53f986529f --- /dev/null +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/PlatformEnvironment.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions +{ + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; + using System; + + /// + public class PlatformEnvironment : IEnvironment + { + /// + public PlatformArchitecture Architecture + { + get + { + throw new NotImplementedException(); + } + } + + /// + public PlatformOperatingSystem OperatingSystem + { + get + { + throw new NotImplementedException(); + } + } + } +} diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/Process/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs similarity index 100% rename from src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/Process/ProcessHelper.cs rename to src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 25ade4bbc5..de6a8aeab0 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -14,6 +14,8 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting using System.Threading.Tasks; using Microsoft.TestPlatform.TestHostProvider.Hosting; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; @@ -40,6 +42,8 @@ public class DefaultTestHostManager : ITestRuntimeProvider private Architecture architecture; private IProcessHelper processHelper; + private IEnvironment environment; + private IDotnetHostHelper dotnetHostHelper; private ITestHostLauncher customTestHostLauncher; private Process testHostProcess; @@ -52,7 +56,7 @@ public class DefaultTestHostManager : ITestRuntimeProvider /// Initializes a new instance of the class. /// public DefaultTestHostManager() - : this(new ProcessHelper()) + : this(new ProcessHelper(), new PlatformEnvironment(), new DotnetHostHelper()) { } @@ -60,9 +64,13 @@ public DefaultTestHostManager() /// Initializes a new instance of the class. /// /// Process helper instance. - internal DefaultTestHostManager(IProcessHelper processHelper) + /// Instance of platform environment. + /// Instance of dotnet host helper. + internal DefaultTestHostManager(IProcessHelper processHelper, IEnvironment environment, IDotnetHostHelper dotnetHostHelper) { this.processHelper = processHelper; + this.environment = environment; + this.dotnetHostHelper = dotnetHostHelper; } /// @@ -141,6 +149,14 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( var testhostProcessPath = Path.Combine(currentWorkingDirectory, testHostProcessName); EqtTrace.Verbose("DefaultTestHostmanager: Full path of {0} is {1}", testHostProcessName, testhostProcessPath); + var launcherPath = testhostProcessPath; + if (!this.environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows) && + !this.processHelper.GetCurrentProcessFileName().EndsWith(DotnetHostHelper.MONOEXENAME, StringComparison.OrdinalIgnoreCase)) + { + launcherPath = this.dotnetHostHelper.GetMonoPath(); + argumentsString = testhostProcessPath + " " + argumentsString; + } + // For IDEs and other scenario, current directory should be the // working directory (not the vstest.console.exe location). // For VS - this becomes the solution directory for example @@ -149,7 +165,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( return new TestProcessStartInfo { - FileName = testhostProcessPath, + FileName = launcherPath, Arguments = argumentsString, EnvironmentVariables = environmentVariables ?? new Dictionary(), WorkingDirectory = processWorkingDirectory diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 3f3fe6d011..15a2cf9c86 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -175,7 +175,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( } else { - startInfo.FileName = this.dotnetHostHelper.GetDotnetHostFullPath(); + startInfo.FileName = this.dotnetHostHelper.GetDotnetPath(); } EqtTrace.Verbose("DotnetTestHostmanager: Full path of dotnet.exe is {0}", startInfo.FileName); diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index a0454bb54c..7aff728331 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -10,11 +10,14 @@ namespace TestPlatform.TestHostProvider.UnitTests.Hosting using System.Linq; using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -27,6 +30,8 @@ public class DefaultTestHostManagerTests private readonly TestProcessStartInfo startInfo; private readonly Mock mockMessageLogger; private readonly Mock mockProcessHelper; + private readonly Mock mockDotnetHostHelper; + private readonly Mock mockEnvironment; private DefaultTestHostManager testHostManager; private TestableTestHostManager testableTestHostManager; @@ -38,10 +43,12 @@ public DefaultTestHostManagerTests() { this.mockProcessHelper = new Mock(); this.mockProcessHelper.Setup(ph => ph.GetCurrentProcessFileName()).Returns("vstest.console.exe"); + this.mockDotnetHostHelper = new Mock(); + this.mockEnvironment = new Mock(); this.mockMessageLogger = new Mock(); - this.testHostManager = new DefaultTestHostManager(this.mockProcessHelper.Object); + this.testHostManager = new DefaultTestHostManager(this.mockProcessHelper.Object, this.mockEnvironment.Object, this.mockDotnetHostHelper.Object); this.testHostManager.Initialize(this.mockMessageLogger.Object, $" {Architecture.X64} {Framework.DefaultFramework} {false} "); this.startInfo = this.testHostManager.GetTestHostProcessStartInfo(Enumerable.Empty(), null, default(TestRunnerConnectionInfo)); } @@ -49,7 +56,6 @@ public DefaultTestHostManagerTests() [TestMethod] public void ConstructorShouldSetX86ProcessForX86Architecture() { - this.testHostManager = new DefaultTestHostManager(this.mockProcessHelper.Object); this.testHostManager.Initialize(this.mockMessageLogger.Object, $" {Architecture.X86} {Framework.DefaultFramework} {false} "); var info = this.testHostManager.GetTestHostProcessStartInfo(Enumerable.Empty(), null, default(TestRunnerConnectionInfo)); @@ -110,11 +116,10 @@ public void GetTestHostProcessStartInfoShouldIncludeCurrentWorkingDirectory() [TestMethod] public void GetTestHostProcessStartInfoShouldIncludeTestSourcePathInArgumentsIfNonShared() { - this.testHostManager = new DefaultTestHostManager(this.mockProcessHelper.Object); this.testHostManager.Initialize(this.mockMessageLogger.Object, $" {Architecture.X86} {Framework.DefaultFramework} {true} "); var connectionInfo = new TestRunnerConnectionInfo { Port = 123, RunnerProcessId = 101 }; - var source = "C:\temp\a.dll"; + var info = this.testHostManager.GetTestHostProcessStartInfo( new List() { source }, null, @@ -123,6 +128,40 @@ public void GetTestHostProcessStartInfoShouldIncludeTestSourcePathInArgumentsIfN Assert.AreEqual(" --port 123 --parentprocessid 101 --testsourcepath " + source.AddDoubleQuote(), info.Arguments); } + [TestMethod] + public void GetTestHostProcessStartInfoShouldUseMonoAsHostOnNonWindowsIfNotStartedWithMono() + { + this.mockProcessHelper.Setup(p => p.GetCurrentProcessFileName()).Returns("/usr/bin/dotnet"); + this.mockEnvironment.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Unix); + this.mockDotnetHostHelper.Setup(d => d.GetMonoPath()).Returns("/usr/bin/mono"); + var source = "C:\temp\a.dll"; + + var info = this.testHostManager.GetTestHostProcessStartInfo( + new List() { source }, + null, + default(TestRunnerConnectionInfo)); + + Assert.AreEqual("/usr/bin/mono", info.FileName); + StringAssert.Contains(info.Arguments, "TestHost" + Path.DirectorySeparatorChar + "testhost.exe"); + } + + [TestMethod] + public void GetTestHostProcessStartInfoShouldNotUseMonoAsHostOnNonWindowsIfStartedWithMono() + { + this.mockProcessHelper.Setup(p => p.GetCurrentProcessFileName()).Returns("/usr/bin/mono"); + this.mockEnvironment.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Unix); + this.mockDotnetHostHelper.Setup(d => d.GetMonoPath()).Returns("/usr/bin/mono"); + var source = "C:\temp\a.dll"; + + var info = this.testHostManager.GetTestHostProcessStartInfo( + new List() { source }, + null, + default(TestRunnerConnectionInfo)); + + StringAssert.Contains(info.FileName, "TestHost" + Path.DirectorySeparatorChar + "testhost.exe"); + Assert.IsFalse(info.Arguments.Contains("TestHost" + Path.DirectorySeparatorChar + "testhost.exe")); + } + [TestMethod] public void LaunchTestHostShouldReturnTestHostProcessId() { @@ -136,7 +175,6 @@ public void LaunchTestHostShouldReturnTestHostProcessId() It.IsAny>(), It.IsAny>())).Returns(Process.GetCurrentProcess()); - this.testHostManager = new DefaultTestHostManager(this.mockProcessHelper.Object); this.testHostManager.Initialize(this.mockMessageLogger.Object, $" {Architecture.X64} {Framework.DefaultFramework} {false} "); var startInfo = this.testHostManager.GetTestHostProcessStartInfo(Enumerable.Empty(), null, default(TestRunnerConnectionInfo)); @@ -325,7 +363,7 @@ public TestableTestHostManager( bool shared, int errorLength, IMessageLogger logger) - : base(processHelper) + : base(processHelper, new PlatformEnvironment(), new DotnetHostHelper()) { this.TimeOut = 30000; this.ErrorLength = errorLength; diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index bf1f431aea..074fd2ec69 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -19,6 +19,7 @@ namespace TestPlatform.TestHostProvider.UnitTests.Hosting using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -60,13 +61,14 @@ public DotnetTestHostManagerTests() this.mockProcessHelper = new Mock(); this.mockFileHelper = new Mock(); this.mockMessageLogger = new Mock(); + var mockEnvironment = new Mock(); this.defaultConnectionInfo = default(TestRunnerConnectionInfo); string defaultSourcePath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "test.dll"); this.defaultTestHostPath = @"\tmp\testhost.dll"; this.dotnetHostManager = new TestableDotnetTestHostManager( this.mockProcessHelper.Object, this.mockFileHelper.Object, - new DotnetHostHelper(this.mockFileHelper.Object), + new DotnetHostHelper(this.mockFileHelper.Object, mockEnvironment.Object), this.maxStdErrStringLength); this.dotnetHostManager.Initialize(this.mockMessageLogger.Object, string.Empty); diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj index e207ac2a0c..e8d078d252 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj @@ -24,6 +24,7 @@ true +