Migrate tests to Arcade
authorDavis Goodin <dagood@microsoft.com>
Fri, 21 Jun 2019 18:50:08 +0000 (13:50 -0500)
committerDavis Goodin <dagood@microsoft.com>
Fri, 21 Jun 2019 21:39:50 +0000 (16:39 -0500)
Commit migrated from https://github.com/dotnet/core-setup/commit/dd3d9f4141c7a244be29a1827e034f614b9cd2fb

18 files changed:
src/installer/TestProjects.targets [new file with mode: 0644]
src/installer/test/Assets/TestProjects/Directory.Build.props
src/installer/test/Assets/TestProjects/Directory.Build.targets [new file with mode: 0644]
src/installer/test/Assets/TestProjects/MNADeprecationWorkaround.props
src/installer/test/Assets/TestProjects/PortableApp/PortableApp.csproj
src/installer/test/Assets/TestProjects/PortableTestApp/PortableTestApp.csproj
src/installer/test/Assets/TestProjects/StandaloneTestApp/StandaloneTestApp.csproj
src/installer/test/BundleTests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj
src/installer/test/BundleTests/Helpers/BundleHelper.csproj
src/installer/test/BundleTests/Microsoft.NET.HostModel.Bundle.Tests/Microsoft.NET.HostModel.Bundle.Tests.csproj
src/installer/test/Directory.Build.props
src/installer/test/Directory.Build.targets [new file with mode: 0644]
src/installer/test/HostActivation.Tests/HostActivation.Tests.csproj
src/installer/test/Microsoft.Extensions.DependencyModel.Tests/Microsoft.Extensions.DependencyModel.Tests.csproj
src/installer/test/PrepareTestAssets/PrepareTestAssets.proj [new file with mode: 0644]
src/installer/test/TestUtils/RepoDirectoriesProvider.cs
src/installer/test/TestUtils/TestProjectFixture.cs
src/installer/test/dir.proj [deleted file]

diff --git a/src/installer/TestProjects.targets b/src/installer/TestProjects.targets
new file mode 100644 (file)
index 0000000..55f221e
--- /dev/null
@@ -0,0 +1,6 @@
+<Project>
+  <!--
+    This file is imported by the test projects from the artifacts dir or the src/tests dir. It
+    provides basic info needed for restore and build with the vanilla SDK.
+  -->
+</Project>
index da5bb19..d501b37 100644 (file)
@@ -1,4 +1,16 @@
 <Project>
-  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
-  <Import Project="$(MSBuildThisFileDirectory)MNADeprecationWorkaround.props" />
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), TestProjects.props))\TestProjects.props" />
+
+  <ItemGroup>
+    <RestoreTestFallbackSource Include="$(ArtifactsShippingPackagesDir)" />
+    <RestoreTestSource Include="$(RestoreSources)" />
+    <RestoreTestSource Include="https://api.nuget.org/v3/index.json" />
+  </ItemGroup>
+
+  <PropertyGroup>
+    <RestoreSources>@(RestoreTestSource);@(RestoreTestFallbackSource)</RestoreSources>
+    <RestorePackagesPath>$(TestRestorePackagesPath)</RestorePackagesPath>
+    <RestoreNoCache>true</RestoreNoCache>
+  </PropertyGroup>
+
 </Project>
diff --git a/src/installer/test/Assets/TestProjects/Directory.Build.targets b/src/installer/test/Assets/TestProjects/Directory.Build.targets
new file mode 100644 (file)
index 0000000..103be55
--- /dev/null
@@ -0,0 +1,15 @@
+<Project>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), TestProjects.targets))\TestProjects.targets" />
+
+  <!--
+    Some known framework references are downstream of Core-Setup and don't exist with the build's
+    versions. Remove them before the SDK tries to download them.
+  -->
+  <Target Name="RemoveUpstackKnownFrameworkReferences"
+          BeforeTargets="ResolveFrameworkReferences">
+    <ItemGroup>
+      <KnownFrameworkReference Remove="Microsoft.AspNetCore.App" />
+    </ItemGroup>
+  </Target>
+
+</Project>
index 4ed66ef..14d9577 100644 (file)
@@ -15,4 +15,8 @@
     <PackageReference Include="Microsoft.NETCore.App.Internal" Version="$(MNAVersion)" />
   </ItemGroup>
 
+  <PropertyGroup>
+    <DisableImplicitNETCorePlatformsReference>true</DisableImplicitNETCorePlatformsReference>
+  </PropertyGroup>
+
 </Project>
index b4ea72e..369a294 100644 (file)
 
   <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
 
-  <!--
-    Work around "dotnet store" relying on Microsoft.NETCore.App. See MNADeprecationWorkaround.props.
-
-    Explicit Sdk.targets import is required to override this.
-  -->
-
-  <!-- BEGIN copy: Taken and modified from 'Tools\dotnetcli\sdk\2.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets' -->
-
-  <Target Name="_RestoreCrossgen"
-          DependsOnTargets="PrepforRestoreForComposeStore;
-                           _SetupStageForCrossgen;"
-          Condition="$(SkipOptimization) != 'true' ">
-    <!-- Was:
-    <MSBuild Projects="$(MSBuildProjectFullPath)"
-                 Targets="Restore"
-                 Properties="RestoreGraphProjectInput=$(MSBuildProjectFullPath);
-                             DisableImplicitFrameworkReferences=true;
-                             RestoreOutputPath=$(_CrossProjFileDir);
-                             StorePackageName=$(MicrosoftNETPlatformLibrary);
-                             StorePackageVersion=$(RuntimeFrameworkVersion);"/>
-    -->
-    <MSBuild Projects="$(MSBuildProjectFullPath)"
-                 Targets="Restore"
-                 Properties="RestoreGraphProjectInput=$(MSBuildProjectFullPath);
-                             DisableImplicitFrameworkReferences=true;
-                             RestoreOutputPath=$(_CrossProjFileDir);
-                             StorePackageName=Microsoft.NETCore.App.Internal;
-                             StorePackageVersion=$(RuntimeFrameworkVersion);"/>
-
-    <ResolvePublishAssemblies ProjectPath="$(MSBuildProjectFullPath)"
-                              AssetsFilePath="$(_CrossProjAssetsFile)"
-                              TargetFramework="$(_TFM)"
-                              RuntimeIdentifier="$(RuntimeIdentifier)"
-                              PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
-                              ExcludeFromPublishPackageReferences="@(_ExcludeFromPublishPackageReference)"
-                              IsSelfContained="$(SelfContained)"
-                              PreserveStoreLayout="false">
-
-      <Output TaskParameter="AssembliesToPublish" ItemName="CrossgenResolvedAssembliesToPublish" />
-    </ResolvePublishAssemblies>
-
-    <!-- Copy managed files to  a flat temp directory for passing it as ref for crossgen -->
-    <Copy SourceFiles = "@(CrossgenResolvedAssembliesToPublish)"
-          DestinationFolder="$(_NetCoreRefDir)"
-          OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
-          Retries="$(CopyRetryCount)"
-          RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
-          UseHardlinksIfPossible="$(CreateHardLinksForPublishFilesIfPossible)"
-          UseSymboliclinksIfPossible="$(CreateSymbolicLinksForPublishFilesIfPossible)">
-
-      <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
-    </Copy>
-  </Target>
-
-  <!-- END copy -->
-
 </Project>
index d5f0f6c..fbd0b54 100644 (file)
@@ -10,8 +10,6 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
-    <PackageReference Include="xunit" Version="2.1.0" />
     <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
     <PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
     <PackageReference Include="dotnet-test-xunit" Version="1.0.0-rc2-192208-24" />
index 613a84e..dbc7efa 100644 (file)
@@ -13,7 +13,6 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
-    <PackageReference Include="xunit" Version="2.1.0" />
     <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
     <PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
     <PackageReference Include="dotnet-test-xunit" Version="1.0.0-rc2-192208-24" />
index f88caf5..335c034 100644 (file)
@@ -2,10 +2,13 @@
 
   <PropertyGroup>
     <Description>Apphost Bundle Tests</Description>
-    <TargetFramework>netcoreapp2.0</TargetFramework>
+    <TargetFramework>$(NETCoreAppFramework)</TargetFramework>
     <AssemblyName>AppHost.Bundle.Tests</AssemblyName>
     <PackageId>AppHost.Bundle.Tests</PackageId>
     <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
+    <!-- Reduce the length of the test output dir to make it more reliable on Windows. -->
+    <TestsOutputName>ahb</TestsOutputName>
+    <UsesTestAssets>true</UsesTestAssets>
   </PropertyGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\Helpers\BundleHelper.csproj" />
   </ItemGroup>
 
-  <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
-    <PackageReference Include="xunit" Version="2.2.0" />
-    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
-  </ItemGroup>
-
 </Project>
index c1b5ea0..02c9fab 100644 (file)
@@ -12,8 +12,4 @@
     <ProjectReference Include="..\..\..\managed\Microsoft.NET.HostModel\Microsoft.NET.HostModel.csproj" />
   </ItemGroup>
 
-  <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
-  </ItemGroup>
-
 </Project>
index 277091b..1a0e81c 100644 (file)
@@ -2,10 +2,13 @@
 
   <PropertyGroup>
     <Description>Microsoft.NET.HostModel.Bundle Tests</Description>
-    <TargetFramework>netcoreapp2.0</TargetFramework>
+    <TargetFramework>$(NETCoreAppFramework)</TargetFramework>
     <AssemblyName>Microsoft.NET.HostModel.Bundle.Tests</AssemblyName>
     <PackageId>Microsoft.NET.HostModel.Bundle.Tests</PackageId>
     <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
+    <!-- Reduce the length of the test output dir to make it more reliable on Windows. -->
+    <TestsOutputName>hmb</TestsOutputName>
+    <UsesTestAssets>true</UsesTestAssets>
   </PropertyGroup>
 
   <ItemGroup>
     <ProjectReference Include="..\Helpers\BundleHelper.csproj" />
   </ItemGroup>
 
-  <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
-    <PackageReference Include="xunit" Version="2.2.0" />
-    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
-  </ItemGroup>
-
 </Project>
index 1b57cd9..43109fd 100644 (file)
@@ -1,21 +1,10 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="..\Directory.Build.props" />
+<Project>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
 
   <PropertyGroup>
-    <TestDir>$(ProjectDir)/src/test</TestDir>
-    <TestAssetsDir>$(TestDir)/Assets</TestAssetsDir>
+    <TestDir>$(ProjectDir)src\test\</TestDir>
+    <TestAssetsDir>$(TestDir)Assets\</TestAssetsDir>
+    <TestRestorePackagesPath>$(ObjDir)TestPackageCache\</TestRestorePackagesPath>
   </PropertyGroup>
 
-  <ItemGroup>
-    <TestProjects Include="$(TestDir)/HostActivation.Tests/HostActivation.Tests.csproj" />
-    <TestProjects Include="$(TestDir)/Microsoft.Extensions.DependencyModel.Tests/Microsoft.Extensions.DependencyModel.Tests.csproj" />
-    <TestProjects Include="$(TestDir)/BundleTests/Microsoft.NET.HostModel.Bundle.Tests/Microsoft.NET.HostModel.Bundle.Tests.csproj" />
-    <TestProjects Include="$(TestDir)/BundleTests/AppHost.Bundle.Tests/AppHost.Bundle.Tests.csproj" />
-  </ItemGroup>
-  <ItemGroup>
-    <RestoreTestFallbackSource Include="$(CoreHostOutputDir.TrimEnd('/').TrimEnd('\'))" />
-    <RestoreTestFallbackSource Include="$(PackagesBasePath)packages" />
-    <RestoreTestSource Include="@(DotnetSourceList)" />
-  </ItemGroup>
 </Project>
diff --git a/src/installer/test/Directory.Build.targets b/src/installer/test/Directory.Build.targets
new file mode 100644 (file)
index 0000000..1506f15
--- /dev/null
@@ -0,0 +1,188 @@
+<Project>
+
+  <Target Name="RefreshProjectTestAssets"
+          Condition="'$(UsesTestAssets)' == 'true'"
+          DependsOnTargets="DetermineTestOutputDirectory"
+          BeforeTargets="RunTests">
+    <!-- Build PrepareTestAssets once for all tests. -->
+    <MSBuild
+      Projects="$(TestDir)PrepareTestAssets\PrepareTestAssets.proj"
+      Targets="PrepareTestAssets" />
+
+    <!--
+      Set up the shared framework copy this set of tests should use. There's no known reason to have
+      one per test project, but RepoDirectoriesProvider may need some tweaking to share.
+    -->
+    <ItemGroup>
+      <SharedFrameworkPublishFiles Include="$(SharedFrameworkPublishDir)**" />
+    </ItemGroup>
+
+    <Copy
+      SourceFiles="@(SharedFrameworkPublishFiles)"
+      DestinationFiles="@(SharedFrameworkPublishFiles->'$(TestsOutputDir)sharedFrameworkPublish/%(RecursiveDir)%(Filename)%(Extension)')" />
+
+    <!-- Create file with a name that describes what a test dir is. Useful if path abbreviated. -->
+    <WriteLinesToFile
+      File="$(TestsOutputRootDir)$(TestsOutputName)-is-$(MSBuildProjectName).txt"
+      Overwrite="true"
+      Lines="$(MSBuildProjectName) intermediates are located in '$(TestsOutputName)'. Abbreviated to work around path limits on Windows."
+      Condition="'$(TestsOutputName)' != '$(MSBuildProjectName)'" />
+  </Target>
+
+  <Target Name="DetermineTestOutputDirectory">
+    <GetTargetMachineInfo>
+      <Output TaskParameter="RuntimeIdentifier" PropertyName="_HostRid" />
+    </GetTargetMachineInfo>
+
+    <PropertyGroup>
+      <TestTargetRid Condition="'$(TestTargetRid)' == ''">$(_HostRid)</TestTargetRid>
+      <TestsOutputName Condition="'$(TestsOutputName)' == ''">$(MSBuildProjectName)</TestsOutputName>
+
+      <TestsOutputRootDir Condition="'$(TestsOutputRootDir)' == ''">$(ArtifactsDir)tests/$(ConfigurationGroup)/</TestsOutputRootDir>
+      <TestsOutputDir Condition="'$(TestsOutputDir)' == ''">$(TestsOutputRootDir)$(TestsOutputName)/</TestsOutputDir>
+    </PropertyGroup>
+  </Target>
+
+  <Target Name="SetupTextFixtureEnvironment"
+          DependsOnTargets="
+            GetProductVersions;
+            DetermineTestOutputDirectory"
+          BeforeTargets="RunTests">
+    <PropertyGroup>
+      <!-- The tests use the TEST_ARTIFACTS env variable to determine the artifacts folder and then later compare that path to its expected path.
+           So, the TEST_ARTIFACTS variable has to have system specific path separators or the string compoarison will fail. -->
+      <DirectorySeparatorChar>$([System.IO.Path]::DirectorySeparatorChar)</DirectorySeparatorChar>
+      <SystemPathTestsOutputDir>$([System.String]::Copy('$(TestsOutputDir)').Replace('/', '$(DirectorySeparatorChar)'))</SystemPathTestsOutputDir>
+      <SystemPathTestsOutputDir>$([System.String]::Copy('$(SystemPathTestsOutputDir)').Replace('\', '$(DirectorySeparatorChar)'))</SystemPathTestsOutputDir>
+    </PropertyGroup>
+
+    <!-- Set properties used inside tests as environment variables. -->
+    <ItemGroup>
+      <TestRunnerEnvironmentVariable Include="NUGET_PACKAGES=$(PackagesDir)" />
+      <TestRunnerEnvironmentVariable Include="TEST_ARTIFACTS=$(SystemPathTestsOutputDir)" />
+      <TestRunnerEnvironmentVariable Include="TEST_TARGETRID=$(TestTargetRid)" />
+      <TestRunnerEnvironmentVariable Include="BUILDRID=$(OutputRid)" />
+      <TestRunnerEnvironmentVariable Include="BUILD_ARCHITECTURE=$(TargetArchitecture)" />
+      <TestRunnerEnvironmentVariable Include="BUILD_CONFIGURATION=$(ConfigurationGroup)" />
+      <TestRunnerEnvironmentVariable Include="MNA_VERSION=$(ProductVersion)" />
+      <TestRunnerEnvironmentVariable Include="MNA_TFM=$(NETCoreAppFramework)" />
+      <TestRunnerEnvironmentVariable Include="DOTNET_SDK_PATH=$(DotNetRoot)" />
+    </ItemGroup>
+  </Target>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.targets))\Directory.Build.targets" />
+
+  <!--
+    Rewrite Arcade RunTests target to add TestRunnerEnvironmentVariable support. In the future we
+    should switch to a file to transfer this information, or derive the info from information on
+    disk. Env vars are not likely to be supported in upstream Arcade.
+
+    See https://github.com/dotnet/arcade/issues/3077.
+  -->
+  <!-- <OVERRIDE> https://github.com/dotnet/arcade/blob/dc538a29793fd56618d0fa3186e2388d47d00c19/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.targets#L25-L120 -->
+  <!-- 
+    Include '*' target to force running tests even if the input assemblies haven't changed and the outputs are present.
+    This matches the common expectations that test command always runs all tests in scope.
+  -->
+  <Target Name="RunTests"
+          Inputs="@(TestToRun);*"
+          Outputs="%(TestToRun.ResultsStdOutPath);%(TestToRun.ResultsXmlPath);%(TestToRun.ResultsHtmlPath)">
+
+    <PropertyGroup>
+      <_TestEnvironment>%(TestToRun.EnvironmentDisplay)</_TestEnvironment>
+      <_TestAssembly>%(TestToRun.Identity)</_TestAssembly>
+      <_TestRuntime>%(TestToRun.TestRuntime)</_TestRuntime>
+      <_TestRunnerAdditionalArguments>%(TestToRun.TestRunnerAdditionalArguments)</_TestRunnerAdditionalArguments>
+
+      <!-- Always use net472 for desktop to enable displaying source location from Portable PDBs in stack traces -->
+      <_TestRunnerTargetFramework>net472</_TestRunnerTargetFramework>
+      <_TestRunnerTargetFramework Condition="'$(_TestRuntime)' == 'Core'">netcoreapp2.0</_TestRunnerTargetFramework>
+      <_TestRunnerTargetFramework Condition="%(TestToRun.TargetFramework) == 'netcoreapp1.1' or %(TestToRun.TargetFramework) == 'netcoreapp1.0'">netcoreapp1.0</_TestRunnerTargetFramework>
+    </PropertyGroup>
+
+    <PropertyGroup Condition="'$(_TestRuntime)' == 'Core'">
+      <_TargetFileNameNoExt>$([System.IO.Path]::GetFileNameWithoutExtension('$(_TestAssembly)'))</_TargetFileNameNoExt>
+      <_TargetDir>$([System.IO.Path]::GetDirectoryName('$(_TestAssembly)'))\</_TargetDir>
+      <_CoreRuntimeConfigPath>$(_TargetDir)$(_TargetFileNameNoExt).runtimeconfig.json</_CoreRuntimeConfigPath>
+      <_CoreDepsPath>$(_TargetDir)$(_TargetFileNameNoExt).deps.json</_CoreDepsPath>
+      
+      <_TestRunner Condition="'%(TestToRun.Architecture)'=='x86' And Exists('$(DotNetRoot)x86\dotnet.exe')">$(DotNetRoot)x86\dotnet.exe</_TestRunner>
+      <_TestRunner Condition="'$(_TestRunner)'==''">$(DotNetTool)</_TestRunner>
+      
+      <_TestRunnerArgs>exec --depsfile "$(_CoreDepsPath)" --runtimeconfig "$(_CoreRuntimeConfigPath)" $(TestRuntimeAdditionalArguments) "$(NuGetPackageRoot)xunit.runner.console/$(XUnitVersion)/tools/$(_TestRunnerTargetFramework)/xunit.console.dll" "$(_TestAssembly)" -noautoreporters -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" $(_TestRunnerAdditionalArguments)</_TestRunnerArgs>
+    </PropertyGroup>
+
+    <PropertyGroup Condition="'$(_TestRuntime)' != 'Core'">
+      <_XUnitConsoleExe>xunit.console.exe</_XUnitConsoleExe>
+      <_XUnitConsoleExe Condition="'%(TestToRun.Architecture)' == 'x86'">xunit.console.x86.exe</_XUnitConsoleExe>
+      <_XUnitConsoleExePath>$(NuGetPackageRoot)xunit.runner.console\$(XUnitVersion)\tools\$(_TestRunnerTargetFramework)\$(_XUnitConsoleExe)</_XUnitConsoleExePath>
+
+      <_TestRunnerArgs>"$(_TestAssembly)" -noshadow -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" $(_TestRunnerAdditionalArguments)</_TestRunnerArgs>
+      <_TestRunnerArgs Condition="'$(_TestRuntime)' == 'Mono'">$(TestRuntimeAdditionalArguments) "$(_XUnitConsoleExePath)" $(_TestRunnerArgs)</_TestRunnerArgs>
+
+      <_TestRunner Condition="'$(_TestRuntime)' == 'Mono'">$(MonoTool)</_TestRunner>
+      <_TestRunner Condition="'$(_TestRuntime)' != 'Mono'">$(_XUnitConsoleExePath)</_TestRunner>
+    </PropertyGroup>
+
+    <PropertyGroup>
+      <_TestRunnerCommand>"$(_TestRunner)" $(_TestRunnerArgs)</_TestRunnerCommand>
+
+      <!-- 
+        Redirect std output of the runner.
+        Note that xUnit outputs failure info to both STDOUT (stack trace, message) and STDERR (failed test name) 
+      -->
+      <_TestRunnerCommand Condition="'$(TestCaptureOutput)' != 'false'">$(_TestRunnerCommand) > "%(TestToRun.ResultsStdOutPath)" 2>&amp;1</_TestRunnerCommand>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <_OutputFiles Include="%(TestToRun.ResultsXmlPath)" />
+      <_OutputFiles Include="%(TestToRun.ResultsHtmlPath)" />
+      <_OutputFiles Include="%(TestToRun.ResultsStdOutPath)" />
+    </ItemGroup>
+
+    <MakeDir Directories="@(_OutputFiles->'%(RootDir)%(Directory)')"/>
+    <Delete Files="@(_OutputFiles)" />
+
+    <Message Text="Running tests: $(_TestAssembly) [$(_TestEnvironment)]" Importance="high"/>
+    <!-- <CHANGE> Add env var parameter, taking TestRunnerEnvironmentVariable items. -->
+    <Exec
+      Command='$(_TestRunnerCommand)'
+      EnvironmentVariables="@(TestRunnerEnvironmentVariable)"
+      LogStandardErrorAsError="false"
+      WorkingDirectory="$(_TargetDir)"
+      IgnoreExitCode="true">
+    <!-- </CHANGE> -->
+      <Output TaskParameter="ExitCode" PropertyName="_TestErrorCode" />
+    </Exec>
+
+    <!--
+      Add command line to the log.
+    -->
+    <WriteLinesToFile File="%(TestToRun.ResultsStdOutPath)" 
+                      Overwrite="false" 
+                      Lines=";=== COMMAND LINE ===;$(_TestRunnerCommand)"
+                      Condition="'$(TestCaptureOutput)' != 'false'" />
+
+    <!--
+      Report test status.
+    -->
+    <Message Text="Tests succeeded: $(_TestAssembly) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' == '0'" Importance="high" />
+
+    <PropertyGroup>
+      <_ResultsFileToDisplay>%(TestToRun.ResultsHtmlPath)</_ResultsFileToDisplay>
+      <_ResultsFileToDisplay Condition="!Exists('$(_ResultsFileToDisplay)')">%(TestToRun.ResultsStdOutPath)</_ResultsFileToDisplay>
+    </PropertyGroup>
+
+    <!-- 
+      Ideally we would set ContinueOnError="ErrorAndContinue" so that when a test fails in multi-targeted test project
+      we'll still run tests for all target frameworks. ErrorAndContinue doesn't work well on Linux though: https://github.com/Microsoft/msbuild/issues/3961.
+    -->
+    <Error Text="Tests failed: $(_ResultsFileToDisplay) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' != '0'" File="XUnit" />
+
+    <ItemGroup>
+      <FileWrites Include="@(_OutputFiles)"/>
+    </ItemGroup>
+  </Target>
+  <!-- </OVERRIDE> -->
+
+</Project>
index 9693f54..0387f1f 100644 (file)
@@ -1,11 +1,14 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.0</TargetFramework>
+    <TargetFramework>$(NETCoreAppFramework)</TargetFramework>
     <AssemblyName>HostActivation.Tests</AssemblyName>
     <PackageId>HostActivation.Tests</PackageId>
     <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
     <DefineConstants Condition="'$(OSGroup)' == 'Windows_NT'">$(DefineConstants);WINDOWS</DefineConstants>
+    <!-- Reduce the length of the test output dir to make it more reliable on Windows. -->
+    <TestsOutputName>ha</TestsOutputName>
+    <UsesTestAssets>true</UsesTestAssets>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
@@ -18,9 +21,6 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
-    <PackageReference Include="xunit" Version="2.2.0" />
-    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
     <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
     <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
     <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
index 5f21058..2c7d6bd 100644 (file)
@@ -2,9 +2,9 @@
 
   <PropertyGroup>
     <Description>Microsoft.DotNet.Tools.Tests.Utilities Class Library</Description>
-    <TargetFramework>netcoreapp2.0</TargetFramework>
+    <TargetFramework>$(NETCoreAppFramework)</TargetFramework>
     <AssemblyName>Microsoft.Extensions.DependencyModel.Tests</AssemblyName>
-    <AssemblyOriginatorKeyFile>../../../tools-local/setuptools/Key.snk</AssemblyOriginatorKeyFile>
+    <StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
     <SignAssembly>true</SignAssembly>
     <PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
     <PackageId>Microsoft.Extensions.DependencyModel.Tests</PackageId>
@@ -12,9 +12,6 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
-    <PackageReference Include="xunit" Version="2.2.0" />
-    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
     <PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
     <PackageReference Include="FluentAssertions" Version="4.19.4" />
     <PackageReference Include="Moq" Version="4.7.142" />
     <ProjectReference Include="..\..\managed\Microsoft.Extensions.DependencyModel\Microsoft.Extensions.DependencyModel.csproj" />
   </ItemGroup>
 
+  <!--
+    This test project gets internals from the implementation project, which uses the
+    System.Text.Json source package. This results in duplicate types. Resolve this by removing the
+    reference to System.Text.Json here in the test project.
+  -->
+  <Target Name="RemoveSystemTextJsonRef" AfterTargets="ResolveTargetingPacks">
+    <ItemGroup>
+      <Reference Remove="@(Reference)" Condition="'%(Reference.Filename)' == 'System.Text.Json'" />
+    </ItemGroup>
+  </Target>
+
 </Project>
diff --git a/src/installer/test/PrepareTestAssets/PrepareTestAssets.proj b/src/installer/test/PrepareTestAssets/PrepareTestAssets.proj
new file mode 100644 (file)
index 0000000..3e2ab1d
--- /dev/null
@@ -0,0 +1,40 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <Target Name="PrepareTestAssets"
+          DependsOnTargets="
+            GetProductVersions;
+            DetermineTestOutputDirectory">
+    <!-- Ensure installers (and therefore shared framework projects) are built first. -->
+    <MSBuild Projects="$(SourceDir)pkg\packaging\installers.proj" Targets="Build" />
+
+    <PropertyGroup>
+      <TempFolderRoot>$(IntermediateOutputPath)temp\</TempFolderRoot>
+      <TestTargetRid Condition="'$(TestTargetRid)' == ''">$(_HostRid)</TestTargetRid>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <DirsToClean Include="$(TestDir)\**\bin" />
+      <DirsToClean Include="$(TestDir)\**\obj" />
+      <DirsToClean Include="$(TestRestorePackagesPath)" />
+      <DirsToClean Include="$(TempFolderRoot)$(TargetArchitecture)" />
+
+      <TestAssetProjectToRestore Include="$(TestAssetsDir)**\*.csproj" />
+
+      <AllTestRestoreSources Include="@(RestoreTestSource)"/>
+      <AllTestRestoreSources Include="@(RestoreTestFallbackSource)"/>
+    </ItemGroup>
+
+    <RemoveDir Directories="@(DirsToClean)" />
+
+    <Message Importance="High" Text="Running NuGet Restore for test asset projects..." />
+
+    <MSBuild
+      Projects="@(TestAssetProjectToRestore)"
+      Targets="Restore"
+      Properties="
+        ArtifactsShippingPackagesDir=$(ArtifactsShippingPackagesDir);
+        TestTargetRid=$(TestTargetRid);
+        MNAVersion=$(ProductVersion)" />
+  </Target>
+
+</Project>
index 9cfffda..e6457c8 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.IO;
 
 namespace Microsoft.DotNet.CoreSetup.Test
@@ -28,7 +29,9 @@ namespace Microsoft.DotNet.CoreSetup.Test
         {
             RepoRoot = repoRoot ?? GetRepoRootDirectory();
 
-            string baseArtifactsFolder = artifacts ?? Path.Combine(RepoRoot, "bin");
+            string baseArtifactsFolder = artifacts ?? Path.Combine(RepoRoot, "artifacts");
+            string baseBinFolder = artifacts ?? Path.Combine(baseArtifactsFolder, "bin");
+            string baseObjFolder = artifacts ?? Path.Combine(baseArtifactsFolder, "obj");
 
             TargetRID = Environment.GetEnvironmentVariable("TEST_TARGETRID");
             BuildRID = Environment.GetEnvironmentVariable("BUILDRID");
@@ -45,13 +48,13 @@ namespace Microsoft.DotNet.CoreSetup.Test
                 throw new InvalidOperationException("ERROR: Test SDK folder not found.");
             }
 
-            Artifacts = Path.Combine(baseArtifactsFolder, osPlatformConfig);
+            Artifacts = Path.Combine(baseBinFolder, osPlatformConfig);
             HostArtifacts = artifacts ?? Path.Combine(Artifacts, "corehost");
 
             NugetPackages = nugetPackages ?? Path.Combine(RepoRoot, "packages");
 
             CorehostPackages = corehostPackages ?? Path.Combine(Artifacts, "corehost");
-            BuiltDotnet = builtDotnet ?? Path.Combine(baseArtifactsFolder, "obj", osPlatformConfig, "sharedFrameworkPublish");
+            BuiltDotnet = builtDotnet ?? Path.Combine(baseObjFolder, osPlatformConfig, "sharedFrameworkPublish");
         }
 
         private static string GetRepoRootDirectory()
index 79f420b..a421dc5 100644 (file)
@@ -79,28 +79,35 @@ namespace Microsoft.DotNet.CoreSetup.Test
 
         private TestProject CopyTestProject(TestProject sourceTestProject)
         {
-            EnsureDirectoryBuildProps(TestArtifact.TestArtifactsPath);
+            EnsureDirectoryBuildFiles(TestArtifact.TestArtifactsPath);
             return sourceTestProject.Copy();
         }
 
-        private void EnsureDirectoryBuildProps(string testArtifactDirectory)
+        private void EnsureDirectoryBuildFiles(string testArtifactDirectory)
         {
-            string directoryBuildPropsPath = Path.Combine(testArtifactDirectory, "Directory.Build.props");
             Directory.CreateDirectory(testArtifactDirectory);
 
-            for(int i = 0; i < 3 && !File.Exists(directoryBuildPropsPath); i++)
+            // write an empty Directory.Build.* file to ensure that msbuild doesn't pick up
+            // the repo's root Directory.Build.*.
+            EnsureTestProjectsFileContent(testArtifactDirectory, "props");
+            EnsureTestProjectsFileContent(testArtifactDirectory, "targets");
+        }
+
+        private void EnsureTestProjectsFileContent(string dir, string type) => EnsureFileWithContent(
+            Path.Combine(dir, $"Directory.Build.{type}"),
+            string.Join(
+                Environment.NewLine,
+                "<Project>",
+                $"  <Import Project=\"$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), TestProjects.{type}))\\TestProjects.{type}\" />",
+                "</Project>"));
+
+        private void EnsureFileWithContent(string path, string content)
+        {
+            for(int i = 0; i < 3 && !File.Exists(path); i++)
             {
                 try
                 {
-                    StringBuilder propsFile = new StringBuilder();
-
-                    propsFile.AppendLine("<Project>");
-                    propsFile.AppendLine("  <Import Project=\"$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), TestProjects.props))\\TestProjects.props\" />");
-                    propsFile.AppendLine("</Project>");
-
-                    // write an empty Directory.Build.props to ensure that msbuild doesn't pick up
-                    // the repo's root Directory.Build.props.
-                    File.WriteAllText(directoryBuildPropsPath, propsFile.ToString());
+                    File.WriteAllText(path, content);
                 }
                 catch (IOException)
                 {}
diff --git a/src/installer/test/dir.proj b/src/installer/test/dir.proj
deleted file mode 100644 (file)
index 2784938..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="Directory.Build.props" />
-  <UsingTask TaskName="GetTargetMachineInfo" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
-
-  <PropertyGroup>
-    <BuildTestTargets>
-        DetermineTestOutputDirectory;
-        RestoreTests;
-        BuildTests;
-        RunTests;
-    </BuildTestTargets>
-  </PropertyGroup>
-
-  <Target Name="Build" DependsOnTargets="$(BuildTestTargets)" />
-
-  <Target Name="DetermineTestOutputDirectory">
-    <GetTargetMachineInfo>
-      <Output TaskParameter="RuntimeIdentifier" PropertyName="_HostRid" />
-    </GetTargetMachineInfo>
-    <PropertyGroup>
-      <TestTargetRid Condition="'$(TestTargetRid)' == ''">$(_HostRid)</TestTargetRid>
-      <TestOSPlatformConfig>$(TestTargetRid).$(ConfigurationGroup)</TestOSPlatformConfig>
-      <TestsOutputDir Condition="'$(TestsOutputDir)' == ''">$(BaseOutputPath)tests/$(TestOSPlatformConfig)/</TestsOutputDir>
-    </PropertyGroup>
-  </Target>
-
-  <Target Name="RestoreTests">
-    <ItemGroup>
-      <RestoreTest Include="$(TestDir)/**/*.csproj" />
-    </ItemGroup>
-
-    <PropertyGroup>
-      <TempFolderRoot Condition="'$(OSGroup)' == 'Windows_NT'">$(USERPROFILE)\.dotnet\</TempFolderRoot>
-      <TempFolderRoot Condition="'$(OSGroup)' != 'Windows_NT'">$(HOME)/.dotnet/</TempFolderRoot>
-    </PropertyGroup>
-    <ItemGroup>
-      <DirsToClean Include="$(TestDir)\**\bin" />
-      <DirsToClean Include="$(TestDir)\**\obj" />
-      <DirsToClean Include="$(TempFolderRoot)$(TargetArchitecture)" />
-    </ItemGroup>
-
-    <RemoveDir Directories="@(DirsToClean)" />
-    <MakeDir Directories="$(TempFolderRoot)NuGetFallbackFolder" />
-
-    <PropertyGroup>
-      <RestoreSourceArg>@(RestoreTestSource->'--source %(Identity)', ' ')</RestoreSourceArg>
-      <RestoreSourceArg>$(RestoreSourceArg) @(RestoreTestFallbackSource->'--source %(Identity)', ' ')</RestoreSourceArg>
-      <RestoreArgs>--packages "$(PackagesDir.TrimEnd('/').TrimEnd('\'))" $(RestoreSourceArg)</RestoreArgs>
-      <RestoreArgs>$(RestoreArgs) $(MSBuildPassThroughPropertyList) /p:MNAVersion=$(ProductVersion) /p:TestTargetRid=$(TestTargetRid)</RestoreArgs>
-      <RestorePrefix Condition="'$(OsEnvironment)' != 'Windows_NT'">DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1</RestorePrefix>
-    </PropertyGroup>
-
-    <Exec Command="$(RestorePrefix) $(DotnetToolCommand) restore $(RestoreArgs) %(RestoreTest.Identity)"
-          EnvironmentVariables="NUGET_PACKAGES=$(PackagesDir.TrimEnd('/').TrimEnd('\'))" />
-  </Target>
-
-  <Target Name="BuildTests"
-          DependsOnTargets="DetermineTestOutputDirectory">
-
-    <PropertyGroup>
-      <BuildArgs>--no-restore $(MSBuildPassThroughPropertyList)</BuildArgs>
-    </PropertyGroup>
-
-    <Message Text="Building Tests" Importance="High" />
-    <Message Importance="High" Text="TestProjects: @(TestProjects)" />
-    <Exec Command="$(DotnetToolCommand) build $(BuildArgs) %(TestProjects.Identity)"
-          WorkingDirectory="$([System.IO.Path]::GetDirectoryName(%(TestProjects.Identity)))"
-          EnvironmentVariables="NUGET_PACKAGES=$(PackagesDir.TrimEnd('/').TrimEnd('\'))" />
-  </Target>
-
-  <Target Name="RunTest"
-          DependsOnTargets="DetermineTestOutputDirectory"
-          Inputs="%(TestProjects.Identity)"
-          Outputs="fake">
-    <PropertyGroup>
-      <TestProject>%(TestProjects.Identity)</TestProject>
-      <TestProjectFilename>%(TestProjects.Filename)</TestProjectFilename>
-      <TestWorkingDirectory>$([System.IO.Path]::GetDirectoryName($(TestProject)))</TestWorkingDirectory>
-      <DirectorySeparatorChar>$([System.IO.Path]::DirectorySeparatorChar)</DirectorySeparatorChar>
-      <!-- The tests use the TEST_ARTIFACTS env variable to determine the artifacts folder and then later compare that path to its expected path.
-           So, the TEST_ARTIFACTS variable has to have system specific path separators or the string compoarison will fail. -->
-      <SystemPathTestsOutputDir>$([System.String]::Copy('$(TestsOutputDir)').Replace('/', '$(DirectorySeparatorChar)'))</SystemPathTestsOutputDir>
-      <SystemPathTestsOutputDir>$([System.String]::Copy('$(SystemPathTestsOutputDir)').Replace('\', '$(DirectorySeparatorChar)'))</SystemPathTestsOutputDir>
-    </PropertyGroup>
-    <PropertyGroup>
-      <TestArgs>--no-restore $(MSBuildPassThroughPropertyList)</TestArgs>
-      <IsCrossArch>false</IsCrossArch>
-      <IsCrossArch Condition="'$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'armel'">true</IsCrossArch>
-      <TestResultsXml>$(SystemPathTestsOutputDir)$(TestProjectFilename)-testResults.trx</TestResultsXml>
-    </PropertyGroup>
-    <Exec Command="$(DotnetToolCommand) test $(TestArgs) --logger &quot;trx;LogFileName=$(TestResultsXml)&quot;"
-          WorkingDirectory="$(TestWorkingDirectory)"
-          EnvironmentVariables="NUGET_PACKAGES=$(PackagesDir);TEST_ARTIFACTS=$(SystemPathTestsOutputDir);TEST_TARGETRID=$(TestTargetRid);BUILDRID=$(OutputRid);BUILD_ARCHITECTURE=$(TargetArchitecture);BUILD_CONFIGURATION=$(ConfigurationGroup);MNA_VERSION=$(ProductVersion);MNA_TFM=$(NETCoreAppFramework);DOTNET_SDK_PATH=$(DotnetCliPath)"
-          Condition="'$(TestProjectFilename)' != 'HostActivation.Tests' or '$(IsCrossArch)' != 'true'"
-          ContinueOnError="true"
-          IgnoreStandardErrorWarningFormat="true"
-          IgnoreExitCode="true">
-        <Output TaskParameter="ExitCode" PropertyName="_ErrorCode" />
-    </Exec>
-
-    <ItemGroup>
-      <TestResults Include="$(TestProject)">
-        <ResultsXml>$(TestResultsXml)</ResultsXml>
-        <ExitCode>$(_ErrorCode)</ExitCode>
-        <ExitCode Condition="'$(_ErrorCode)' == ''">0</ExitCode>
-      </TestResults>
-    </ItemGroup>
-    <Message Importance="High" Condition="'$(_ErrorCode)' != '0' and '$(_ErrorCode)' != ''" Text="Test run failed with exit code '$(_ErrorCode)', see $(TestResultsXml)" />
-  </Target>
-
-  <Target Name="RunTests"
-          DependsOnTargets="PrepareTestFolders;RunTest">
-    <ItemGroup>
-      <FailedTests Include="@(TestResults)" Condition="'%(TestResults.ExitCode)' != '0'">
-      </FailedTests>
-    </ItemGroup>
-    <Message Importance="High" Condition="'@(FailedTests)' != ''" Text="Failed test summary" />
-    <Message Importance="High" Condition="'@(FailedTests)' != ''" Text="  %(FailedTests.Identity) failed with exit code %(FailedTests.ExitCode), see %(FailedTests.ResultsXml)" />
-    <Error Condition="'@(FailedTests)' != ''" Text="One or more test runs failed." />
-  </Target>
-
-  <Target Name="PrepareTestFolders"
-          DependsOnTargets="DetermineTestOutputDirectory">
-    <ItemGroup>
-      <SharedFrameworkPublishFiles Include="$(IntermediateOutputRootPath)sharedFrameworkPublish/**" />
-    </ItemGroup>
-
-    <Copy SourceFiles="@(SharedFrameworkPublishFiles)"
-          DestinationFiles="@(SharedFrameworkPublishFiles->'$(TestsOutputDir)sharedFrameworkPublish/%(RecursiveDir)%(Filename)%(Extension)')" />
-  </Target>
-
-</Project>