Merge pull request #1340 from Sridhar-MS/test-fx
[WIP]: TestFramework with support for managing test projects.
This commit is contained in:
commit
735b4beb7c
48 changed files with 843 additions and 248 deletions
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"projects": [ "."]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the message from the helper. This comment is here to help test XML documentation file generation, please do not remove it.
|
||||
/// </summary>
|
||||
/// <returns>A message</returns>
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from the test library!";
|
||||
}
|
||||
|
||||
public static void SayHi()
|
||||
{
|
||||
Console.WriteLine("Hello there!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>947dd232-8d9b-4b78-9c6a-94f807d2dd58</ProjectGuid>
|
||||
<RootNamespace>TestLibrary</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"nowarn": [ "CS1591" ],
|
||||
"xmlDoc": true,
|
||||
"additionalArguments": [ "-highentropyva+" ]
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23808"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
3
TestAssets/TestProjects/TestAppWithLibrary/global.json
Normal file
3
TestAssets/TestProjects/TestAppWithLibrary/global.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"projects": [ "."]
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(TestLibrary.Helper.GetMessage());
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>58808bbc-371e-47d6-a3d0-4902145eda4e</ProjectGuid>
|
||||
<RootNamespace>TestApp</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"TestLibrary": { "target":"project", "version":"1.0.0-*" },
|
||||
|
||||
"NETStandard.Library": "1.0.0-rc2-23811"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
},
|
||||
|
||||
"scripts": {
|
||||
"prepublish" : ["echo prepublish_output ?%publish:ProjectPath%? ?%publish:Configuration%? ?%publish:OutputPath%? ?%publish:Framework%? ?%publish:Runtime%?"],
|
||||
"postpublish" : ["echo postpublish_output ?%publish:ProjectPath%? ?%publish:Configuration%? ?%publish:OutputPath%? ?%publish:Framework%? ?%publish:Runtime%?"]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the message from the helper. This comment is here to help test XML documentation file generation, please do not remove it.
|
||||
/// </summary>
|
||||
/// <returns>A message</returns>
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from the test library!";
|
||||
}
|
||||
|
||||
public static void SayHi()
|
||||
{
|
||||
Console.WriteLine("Hello there!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>947dd232-8d9b-4b78-9c6a-94f807d2dd58</ProjectGuid>
|
||||
<RootNamespace>TestLibrary</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"nowarn": [ "CS1591" ],
|
||||
"xmlDoc": true,
|
||||
"additionalArguments": [ "-highentropyva+" ]
|
||||
},
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23808"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"projects": [ "."]
|
||||
}
|
|
@ -58,6 +58,13 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
|
||||
[Target]
|
||||
public static BuildTargetResult BuildTestPrerequisites(BuildTargetContext c)
|
||||
{
|
||||
BuildTestAssetPackages(c);
|
||||
BuildTestAssetProjects(c);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
public static void BuildTestAssetPackages(BuildTargetContext c)
|
||||
{
|
||||
var dotnet = DotNetCli.Stage2;
|
||||
|
||||
|
@ -73,8 +80,24 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
public static void BuildTestAssetProjects(BuildTargetContext c)
|
||||
{
|
||||
var dotnet = DotNetCli.Stage2;
|
||||
string testProjectsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects");
|
||||
List<string> exclusionList = new List<string> { Path.Combine(testProjectsRoot, "CompileFail", "project.json") };
|
||||
var projects = Directory.GetFiles(testProjectsRoot, "project.json", SearchOption.AllDirectories)
|
||||
.Where(p => !exclusionList.Any(e => e.Contains(p)));
|
||||
|
||||
foreach (var project in projects)
|
||||
{
|
||||
c.Info($"Building: {project}");
|
||||
dotnet.Build("--framework", "dnxcore50")
|
||||
.WorkingDirectory(Path.GetDirectoryName(project))
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
[Target]
|
||||
|
|
45
scripts/test/setup/build-test-prerequisites.ps1
Normal file
45
scripts/test/setup/build-test-prerequisites.ps1
Normal file
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
#
|
||||
|
||||
. "$PSScriptRoot\..\..\common\_common.ps1"
|
||||
|
||||
function buildTestPackages
|
||||
{
|
||||
mkdir -Force $TestPackageDir
|
||||
|
||||
loadTestPackageList | foreach {
|
||||
dotnet pack "$RepoRoot\TestAssets\TestPackages\$($_.ProjectName)" --output "$TestPackageDir"
|
||||
|
||||
if (!$?) {
|
||||
error "Command failed: dotnet pack"
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function buildTestProjects
|
||||
{
|
||||
$testProjectsRoot = "$RepoRoot\TestAssets\TestProjects"
|
||||
$exclusionList = @("$testProjectsRoot\CompileFail\project.json")
|
||||
$testProjectsList = (Get-ChildItem "$testProjectsRoot" -rec -filter "project.json").FullName
|
||||
|
||||
$testProjectsList | foreach {
|
||||
if ($exclusionList -notcontains $_) {
|
||||
|
||||
Write-Host "$_"
|
||||
dotnet build "$_"
|
||||
|
||||
if (!$?) {
|
||||
error "Command failed: dotnet build"
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTestPackages
|
||||
|
||||
buildTestProjects
|
|
@ -0,0 +1,101 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
public class TestAssetsManager
|
||||
{
|
||||
public string AssetsRoot
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public TestAssetsManager(string assetsRoot, bool doRestore = false, bool doBuild = false)
|
||||
{
|
||||
if (!Directory.Exists(assetsRoot))
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Directory not found at '{assetsRoot}'");
|
||||
}
|
||||
|
||||
AssetsRoot = assetsRoot;
|
||||
|
||||
if (doRestore)
|
||||
{
|
||||
Restore();
|
||||
}
|
||||
|
||||
if (doBuild)
|
||||
{
|
||||
Build();
|
||||
}
|
||||
}
|
||||
|
||||
private void Restore()
|
||||
{
|
||||
string[] restoreArgs = new string[] { "restore", AssetsRoot };
|
||||
|
||||
Console.WriteLine("Executing - 'dotnet {0}'", string.Join(" ", restoreArgs));
|
||||
var commandResult = Command.Create("dotnet", restoreArgs)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.Execute();
|
||||
|
||||
int exitCode = commandResult.ExitCode;
|
||||
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Console.WriteLine(commandResult.StdOut);
|
||||
Console.WriteLine(commandResult.StdErr);
|
||||
string message = string.Format("Command Failed - 'dotnet {0}' with exit code - {1}", string.Join(" ", restoreArgs), exitCode);
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void Build()
|
||||
{
|
||||
var projects = Directory.GetFiles(AssetsRoot, "project.json", SearchOption.AllDirectories);
|
||||
foreach (var project in projects)
|
||||
{
|
||||
string[] buildArgs = new string[] { "build", project };
|
||||
|
||||
Console.WriteLine("Executing - 'dotnet {0}'", string.Join(" ", buildArgs));
|
||||
var commandResult = Command.Create("dotnet", buildArgs)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.Execute();
|
||||
|
||||
int exitCode = commandResult.ExitCode;
|
||||
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Console.WriteLine(commandResult.StdOut);
|
||||
Console.WriteLine(commandResult.StdErr);
|
||||
string message = string.Format("Command Failed - 'dotnet {0}' with exit code - {1}", string.Join(" ", buildArgs), exitCode);
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TestInstance CreateTestInstance(string testProjectName, [CallerMemberName] string callingMethod = "", string identifier = "")
|
||||
{
|
||||
string testProjectDir = Path.Combine(AssetsRoot, testProjectName);
|
||||
|
||||
if (!Directory.Exists(testProjectDir))
|
||||
{
|
||||
throw new Exception($"Cannot find '{testProjectName}' at '{AssetsRoot}'");
|
||||
}
|
||||
|
||||
string testDestination = Path.Combine(AppContext.BaseDirectory, callingMethod + identifier, testProjectName);
|
||||
var testInstance = new TestInstance(testProjectDir, testDestination);
|
||||
return testInstance;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
public class TestInstance
|
||||
{
|
||||
private string _testDestination;
|
||||
private string _testAssetRoot;
|
||||
|
||||
internal TestInstance(string testAssetRoot, string testDestination)
|
||||
{
|
||||
if (string.IsNullOrEmpty(testAssetRoot))
|
||||
{
|
||||
throw new ArgumentException("testScenario");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(testDestination))
|
||||
{
|
||||
throw new ArgumentException("testDestination");
|
||||
}
|
||||
|
||||
_testAssetRoot = testAssetRoot;
|
||||
_testDestination = testDestination;
|
||||
|
||||
if (Directory.Exists(testDestination))
|
||||
{
|
||||
Directory.Delete(testDestination, true);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(testDestination);
|
||||
CopySource();
|
||||
}
|
||||
|
||||
private void CopySource()
|
||||
{
|
||||
var sourceDirs = Directory.GetDirectories(_testAssetRoot, "*", SearchOption.AllDirectories)
|
||||
.Where(dir =>
|
||||
{
|
||||
dir = dir.ToLower();
|
||||
return !dir.EndsWith($"{Path.DirectorySeparatorChar}bin")
|
||||
&& !dir.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}")
|
||||
&& !dir.EndsWith($"{Path.DirectorySeparatorChar}obj")
|
||||
&& !dir.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}");
|
||||
});
|
||||
|
||||
foreach (string sourceDir in sourceDirs)
|
||||
{
|
||||
Directory.CreateDirectory(sourceDir.Replace(_testAssetRoot, _testDestination));
|
||||
}
|
||||
|
||||
var sourceFiles = Directory.GetFiles(_testAssetRoot, "*.*", SearchOption.AllDirectories)
|
||||
.Where(file =>
|
||||
{
|
||||
file = file.ToLower();
|
||||
return !file.EndsWith("project.lock.json")
|
||||
&& !file.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}")
|
||||
&& !file.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}");
|
||||
});
|
||||
|
||||
foreach (string srcFile in sourceFiles)
|
||||
{
|
||||
string destFile = srcFile.Replace(_testAssetRoot, _testDestination);
|
||||
File.Copy(srcFile, destFile, true);
|
||||
FixTimeStamp(srcFile, destFile);
|
||||
}
|
||||
}
|
||||
|
||||
public TestInstance WithLockFiles()
|
||||
{
|
||||
foreach (string lockFile in Directory.GetFiles(_testAssetRoot, "project.lock.json", SearchOption.AllDirectories))
|
||||
{
|
||||
string destinationLockFile = lockFile.Replace(_testAssetRoot, _testDestination);
|
||||
File.Copy(lockFile, destinationLockFile, true);
|
||||
FixTimeStamp(lockFile, destinationLockFile);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestInstance WithBuildArtifacts()
|
||||
{
|
||||
var binDirs = Directory.GetDirectories(_testAssetRoot, "*", SearchOption.AllDirectories)
|
||||
.Where(dir =>
|
||||
{
|
||||
dir = dir.ToLower();
|
||||
return dir.EndsWith($"{Path.DirectorySeparatorChar}bin")
|
||||
|| dir.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}")
|
||||
|| dir.EndsWith($"{Path.DirectorySeparatorChar}obj")
|
||||
|| dir.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}");
|
||||
});
|
||||
|
||||
foreach (string dirPath in binDirs)
|
||||
{
|
||||
Directory.CreateDirectory(dirPath.Replace(_testAssetRoot, _testDestination));
|
||||
}
|
||||
|
||||
var binFiles = Directory.GetFiles(_testAssetRoot, "*.*", SearchOption.AllDirectories)
|
||||
.Where(file =>
|
||||
{
|
||||
file = file.ToLower();
|
||||
return file.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}")
|
||||
|| file.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}");
|
||||
});
|
||||
|
||||
foreach (string binFile in binFiles)
|
||||
{
|
||||
string destFile = binFile.Replace(_testAssetRoot, _testDestination);
|
||||
File.Copy(binFile, destFile, true);
|
||||
FixTimeStamp(binFile, destFile);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string TestRoot
|
||||
{
|
||||
get { return _testDestination; }
|
||||
}
|
||||
|
||||
private static void FixTimeStamp(string originalFile, string newFile)
|
||||
{
|
||||
// workaround for https://github.com/dotnet/corefx/issues/6083
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var originalTime = File.GetLastWriteTime(originalFile);
|
||||
File.SetLastWriteTime(newFile, originalTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>0724ed7c-56e3-4604-9970-25e600611383</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.TestFramework</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
21
src/Microsoft.DotNet.TestFramework/project.json
Normal file
21
src/Microsoft.DotNet.TestFramework/project.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Microsoft.DotNet.TestFramework Class Library",
|
||||
"authors": [
|
||||
"sridhper"
|
||||
],
|
||||
"tags": [
|
||||
""
|
||||
],
|
||||
"projectUrl": "",
|
||||
"licenseUrl": "",
|
||||
"dependencies": {
|
||||
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
|
||||
"NETStandard.Library": "1.0.0-rc2-23811"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
}
|
||||
}
|
27
test/Microsoft.DotNet.Tools.Tests.Utilities/ProjectUtils.cs
Normal file
27
test/Microsoft.DotNet.Tools.Tests.Utilities/ProjectUtils.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public class ProjectUtils
|
||||
{
|
||||
public static string GetProjectJson(string testRoot, string project)
|
||||
{
|
||||
// We assume that the project name same as the directory name with contains the project.json
|
||||
// We can do better here by using ProjectReader to get the correct project name
|
||||
string projectPath = Directory.GetFiles(testRoot, "project.json", SearchOption.AllDirectories)
|
||||
.FirstOrDefault(pj => Directory.GetParent(pj).Name.Equals(project));
|
||||
|
||||
if (string.IsNullOrEmpty(projectPath))
|
||||
{
|
||||
throw new Exception($"Cannot file project '{project}' in '{testRoot}'");
|
||||
}
|
||||
|
||||
return projectPath;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,10 +7,11 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all unit test classes.
|
||||
/// </summary>
|
||||
|
@ -18,6 +19,48 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
protected const string DefaultFramework = "dnxcore50";
|
||||
private TempRoot _temp;
|
||||
private static TestAssetsManager s_testsAssetsMgr;
|
||||
private static string s_repoRoot;
|
||||
|
||||
protected static string RepoRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(s_repoRoot))
|
||||
{
|
||||
return s_repoRoot;
|
||||
}
|
||||
|
||||
string directory = AppContext.BaseDirectory;
|
||||
|
||||
while (!Directory.Exists(Path.Combine(directory, ".git")) && directory != null)
|
||||
{
|
||||
directory = Directory.GetParent(directory).FullName;
|
||||
}
|
||||
|
||||
if (directory == null)
|
||||
{
|
||||
throw new Exception("Cannot find the git repository root");
|
||||
}
|
||||
|
||||
s_repoRoot = directory;
|
||||
return s_repoRoot;
|
||||
}
|
||||
}
|
||||
|
||||
protected static TestAssetsManager TestAssetsManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_testsAssetsMgr == null)
|
||||
{
|
||||
string assetsRoot = Path.Combine(RepoRoot, "TestAssets", "TestProjects");
|
||||
s_testsAssetsMgr = new TestAssetsManager(assetsRoot);
|
||||
}
|
||||
|
||||
return s_testsAssetsMgr;
|
||||
}
|
||||
}
|
||||
|
||||
protected TestBase()
|
||||
{
|
||||
|
@ -71,9 +114,9 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
result.Should().HaveStdOut(expectedOutput);
|
||||
result.Should().NotHaveStdErr();
|
||||
result.Should().Pass();
|
||||
result.Should().Pass();
|
||||
}
|
||||
|
||||
|
||||
protected void TestOutputExecutable(
|
||||
string outputDir,
|
||||
string executableName,
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-dev-48273-16",
|
||||
|
||||
"Microsoft.DotNet.TestFramework": "1.0.0-*",
|
||||
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
|
||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537",
|
||||
"Microsoft.DotNet.InternalAbstractions": {
|
||||
|
|
|
@ -16,7 +16,12 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
{
|
||||
public class BuildOutputTests : TestBase
|
||||
{
|
||||
private readonly string _testProjectsRoot;
|
||||
private string _testProjectsRoot;
|
||||
private string _runtime;
|
||||
private DirectoryInfo _rootDirInfo;
|
||||
private DirectoryInfo _testAppDirDirInfo;
|
||||
private DirectoryInfo _testLibDirInfo;
|
||||
|
||||
private readonly string[] _runtimeFiles =
|
||||
{
|
||||
"TestApp" + FileNameSuffixes.DotNet.DynamicLib,
|
||||
|
@ -37,28 +42,18 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
"TestLibrary" + FileNameSuffixes.DotNet.ProgramDatabase,
|
||||
};
|
||||
|
||||
public BuildOutputTests()
|
||||
private void GetProjectInfo(string testRoot)
|
||||
{
|
||||
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
|
||||
}
|
||||
|
||||
private void PrepareProject(out TempDirectory root, out TempDirectory testAppDir, out TempDirectory testLibDir, out string runtime)
|
||||
{
|
||||
root = Temp.CreateDirectory();
|
||||
var src = root.CreateDirectory("src");
|
||||
|
||||
testAppDir = src.CreateDirectory("TestApp");
|
||||
testLibDir = src.CreateDirectory("TestLibrary");
|
||||
|
||||
// copy projects to the temp dir
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
||||
_testProjectsRoot = testRoot;
|
||||
_rootDirInfo = new DirectoryInfo(_testProjectsRoot);
|
||||
_testAppDirDirInfo = new DirectoryInfo(Path.Combine(_testProjectsRoot, "TestApp"));
|
||||
_testLibDirInfo = new DirectoryInfo(Path.Combine(_testProjectsRoot, "TestLibrary"));
|
||||
|
||||
var contexts = ProjectContext.CreateContextForEachFramework(
|
||||
testLibDir.Path,
|
||||
_testAppDirDirInfo.FullName,
|
||||
null,
|
||||
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers());
|
||||
runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
|
||||
_runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
|
||||
}
|
||||
|
||||
private string FormatPath(string input, string framework, string runtime)
|
||||
|
@ -68,37 +63,30 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
|
||||
[Theory]
|
||||
// global.json exists
|
||||
[InlineData(true, null, null, "src/TestLibrary/bin/Debug/{fw}", "src/TestApp/bin/Debug/{fw}", "src/TestApp/bin/Debug/{fw}/{rid}")]
|
||||
[InlineData(true, "out", null, "src/TestLibrary/bin/Debug/{fw}", "src/TestApp/bin/Debug/{fw}", "out")]
|
||||
[InlineData(true, null, "build", "build/src/TestLibrary/bin/Debug/{fw}", "build/src/TestApp/bin/Debug/{fw}", "build/src/TestApp/bin/Debug/{fw}/{rid}")]
|
||||
[InlineData(true, "out", "build", "build/src/TestLibrary/bin/Debug/{fw}", "build/src/TestApp/bin/Debug/{fw}", "out")]
|
||||
[InlineData("1", true, null, null, "TestLibrary/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}/{rid}")]
|
||||
[InlineData("2", true, "out", null, "TestLibrary/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}", "out")]
|
||||
[InlineData("3", true, null, "build", "build/TestLibrary/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}/{rid}")]
|
||||
[InlineData("4", true, "out", "build", "build/TestLibrary/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}", "out")]
|
||||
//no global.json
|
||||
//[InlineData(false, null, null, "src/TestLibrary/bin/debug/{fw}", "src/TestApp/bin/debug/{fw}", "src/TestApp/bin/debug/{fw}/{rid}")]
|
||||
//[InlineData(false, "out", null, "src/TestLibrary/bin/debug/{fw}", "src/TestApp/bin/debug/{fw}", "out")]
|
||||
//[InlineData(false, null, null, "TestLibrary/bin/debug/{fw}", "TestApp/bin/debug/{fw}", "TestApp/bin/debug/{fw}/{rid}")]
|
||||
//[InlineData(false, "out", null, "TestLibrary/bin/debug/{fw}", "TestApp/bin/debug/{fw}", "out")]
|
||||
//[InlineData(false, null, "build", "build/TestLibrary/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}/{rid}")]
|
||||
//[InlineData(false, "out", "build", "build/TestLibrary/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}", "out")]
|
||||
public void DefaultPaths(bool global, string outputValue, string baseValue, string expectedLibCompile, string expectedAppCompile, string expectedAppRuntime)
|
||||
public void DefaultPaths(string testIdentifer, bool global, string outputValue, string baseValue, string expectedLibCompile, string expectedAppCompile, string expectedAppRuntime)
|
||||
{
|
||||
TempDirectory root;
|
||||
TempDirectory testAppDir;
|
||||
TempDirectory testLibDir;
|
||||
string runtime;
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifer)
|
||||
.WithLockFiles();
|
||||
GetProjectInfo(testInstance.TestRoot);
|
||||
|
||||
PrepareProject(out root, out testAppDir, out testLibDir, out runtime);
|
||||
if (global)
|
||||
{
|
||||
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
|
||||
}
|
||||
|
||||
new BuildCommand(GetProjectPath(testAppDir),
|
||||
output: outputValue != null ? Path.Combine(root.Path, outputValue) : string.Empty,
|
||||
buidBasePath: baseValue != null ? Path.Combine(root.Path, baseValue) : string.Empty,
|
||||
new BuildCommand(GetProjectPath(_testAppDirDirInfo),
|
||||
output: outputValue != null ? Path.Combine(_testProjectsRoot, outputValue) : string.Empty,
|
||||
buidBasePath: baseValue != null ? Path.Combine(_testProjectsRoot, baseValue) : string.Empty,
|
||||
framework: DefaultFramework)
|
||||
.ExecuteWithCapturedOutput().Should().Pass();
|
||||
|
||||
var libdebug = root.DirectoryInfo.Sub(FormatPath(expectedLibCompile, DefaultFramework, runtime));
|
||||
var appdebug = root.DirectoryInfo.Sub(FormatPath(expectedAppCompile, DefaultFramework, runtime));
|
||||
var appruntime = root.DirectoryInfo.Sub(FormatPath(expectedAppRuntime, DefaultFramework, runtime));
|
||||
var libdebug = _rootDirInfo.Sub(FormatPath(expectedLibCompile, DefaultFramework, _runtime));
|
||||
var appdebug = _rootDirInfo.Sub(FormatPath(expectedAppCompile, DefaultFramework, _runtime));
|
||||
var appruntime = _rootDirInfo.Sub(FormatPath(expectedAppRuntime, DefaultFramework, _runtime));
|
||||
|
||||
libdebug.Should().Exist().And.HaveFiles(_libCompileFiles);
|
||||
appdebug.Should().Exist().And.HaveFiles(_appCompileFiles);
|
||||
|
@ -108,38 +96,37 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
[Fact]
|
||||
public void ResourceTest()
|
||||
{
|
||||
TempDirectory root;
|
||||
TempDirectory testAppDir;
|
||||
TempDirectory testLibDir;
|
||||
string runtime;
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary")
|
||||
.WithLockFiles();
|
||||
GetProjectInfo(testInstance.TestRoot);
|
||||
|
||||
PrepareProject(out root, out testAppDir, out testLibDir, out runtime);
|
||||
var names = new[]
|
||||
{
|
||||
"uk-UA",
|
||||
"en",
|
||||
"en-US"
|
||||
};
|
||||
foreach (var folder in new [] { testAppDir, testLibDir })
|
||||
foreach (var folder in new[] { _testAppDirDirInfo, _testLibDirInfo })
|
||||
{
|
||||
foreach (var name in names)
|
||||
{
|
||||
folder.CreateFile($"Resource.{name}.resx").WriteAllText("<root></root>");
|
||||
var resourceFile = Path.Combine(folder.FullName, $"Resource.{name}.resx");
|
||||
File.WriteAllText(resourceFile, "<root></root>");
|
||||
}
|
||||
}
|
||||
|
||||
new BuildCommand(GetProjectPath(testAppDir), framework: DefaultFramework)
|
||||
new BuildCommand(GetProjectPath(_testAppDirDirInfo), framework: DefaultFramework)
|
||||
.ExecuteWithCapturedOutput().Should().Pass();
|
||||
|
||||
var libdebug = testLibDir.DirectoryInfo.Sub("bin/Debug").Sub(DefaultFramework);
|
||||
var appdebug = testAppDir.DirectoryInfo.Sub("bin/Debug").Sub(DefaultFramework);
|
||||
var appruntime = appdebug.Sub(runtime);
|
||||
var libdebug = _testLibDirInfo.Sub("bin/Debug").Sub(DefaultFramework);
|
||||
var appdebug = _testAppDirDirInfo.Sub("bin/Debug").Sub(DefaultFramework);
|
||||
var appruntime = appdebug.Sub(_runtime);
|
||||
|
||||
foreach (var name in names)
|
||||
{
|
||||
libdebug.Sub(name).Should().Exist().And.HaveFile("TestLibrary.resources.dll");
|
||||
appdebug.Sub(name).Should().Exist().And.HaveFile("TestApp.resources.dll");
|
||||
appruntime.Sub(name).Should().Exist().And.HaveFiles(new [] { "TestLibrary.resources.dll", "TestApp.resources.dll" });
|
||||
appruntime.Sub(name).Should().Exist().And.HaveFiles(new[] { "TestLibrary.resources.dll", "TestApp.resources.dll" });
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -152,9 +139,9 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private string GetProjectPath(TempDirectory projectDir)
|
||||
private string GetProjectPath(DirectoryInfo projectDir)
|
||||
{
|
||||
return Path.Combine(projectDir.Path, "project.json");
|
||||
return Path.Combine(projectDir.FullName, "project.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ using FluentAssertions;
|
|||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||
{
|
||||
|
@ -16,26 +17,35 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
{
|
||||
private readonly string[] _projects = new[] { "L0", "L11", "L12", "L21", "L22" };
|
||||
|
||||
public ProjectToProjectDependenciesIncrementalTest() : base(
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectToProjectDependencies"),
|
||||
"L0",
|
||||
"L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine)
|
||||
private string MainProjectExe
|
||||
{
|
||||
get
|
||||
{
|
||||
return MainProject + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "");
|
||||
}
|
||||
}
|
||||
|
||||
public ProjectToProjectDependenciesIncrementalTest()
|
||||
{
|
||||
MainProject = "L0";
|
||||
ExpectedOutput = "L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine;
|
||||
|
||||
}
|
||||
|
||||
[Theory,
|
||||
InlineData("L0", new[] { "L0" }),
|
||||
InlineData("L11", new[] { "L0", "L11" }),
|
||||
InlineData("L12", new[] { "L0", "L11", "L12" }),
|
||||
InlineData("L22", new[] { "L0", "L11", "L12", "L22" }),
|
||||
InlineData("L21", new[] { "L0", "L11", "L21" })
|
||||
InlineData("1", "L0", new[] { "L0" }),
|
||||
InlineData("2", "L11", new[] { "L0", "L11" }),
|
||||
InlineData("3", "L12", new[] { "L0", "L11", "L12" }),
|
||||
InlineData("4", "L22", new[] { "L0", "L11", "L12", "L22" }),
|
||||
InlineData("5", "L21", new[] { "L0", "L11", "L21" })
|
||||
]
|
||||
public void TestIncrementalBuildOfDependencyGraph(string projectToTouch, string[] expectedRebuiltProjects)
|
||||
public void TestIncrementalBuildOfDependencyGraph(string testIdentifer, string projectToTouch, string[] expectedRebuiltProjects)
|
||||
{
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies", identifier: testIdentifer)
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
// first clean build; all projects required compilation
|
||||
var result1 = BuildProject();
|
||||
AssertRebuilt(result1, _projects);
|
||||
TestProjectRoot = testInstance.TestRoot;
|
||||
|
||||
// second build; nothing changed; no project required compilation
|
||||
var result2 = BuildProject();
|
||||
|
@ -52,11 +62,13 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
[Fact]
|
||||
public void TestNoDependencyFlag()
|
||||
{
|
||||
var dependencies = new[] { "L11", "L12", "L21", "L22" };
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies")
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
TestProjectRoot = testInstance.TestRoot;
|
||||
|
||||
// first clean build; all projects required compilation
|
||||
var result1 = BuildProject();
|
||||
AssertRebuilt(result1, _projects);
|
||||
var dependencies = new[] { "L11", "L12", "L21", "L22" };
|
||||
|
||||
// modify the source code of a leaf dependency
|
||||
TouchSourcesOfProject("L22");
|
||||
|
@ -104,7 +116,25 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
|
||||
protected override string GetProjectDirectory(string projectName)
|
||||
{
|
||||
return Path.Combine(TempProjectRoot.Path, "src", projectName);
|
||||
return Path.Combine(TestProjectRoot, "src", projectName);
|
||||
}
|
||||
|
||||
protected override string GetOutputDir()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
protected override string GetOutputExePath()
|
||||
{
|
||||
var outputExe = Directory.GetFiles(TestProjectRoot, MainProjectExe, SearchOption.AllDirectories)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrEmpty(outputExe))
|
||||
{
|
||||
throw new FileNotFoundException($"Unable to find {outputExe} in {TestProjectRoot} or its subdirectories");
|
||||
}
|
||||
|
||||
return Path.GetDirectoryName(outputExe);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,20 +12,32 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
{
|
||||
public class IncrementalTestBase : TestBase
|
||||
{
|
||||
protected readonly TempDirectory TempProjectRoot;
|
||||
protected virtual string MainProject
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
protected virtual string ExpectedOutput
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
protected virtual string TestProjectRoot
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
protected IncrementalTestBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected readonly string MainProject;
|
||||
protected readonly string ExpectedOutput;
|
||||
protected readonly TempDirectory Root;
|
||||
|
||||
public IncrementalTestBase(string testProjectsRoot, string mainProject, string expectedOutput)
|
||||
{
|
||||
MainProject = mainProject;
|
||||
ExpectedOutput = expectedOutput;
|
||||
|
||||
Root = Temp.CreateDirectory();
|
||||
|
||||
TempProjectRoot = Root.CopyDirectory(testProjectsRoot);
|
||||
TestProjectRoot = testProjectsRoot;
|
||||
}
|
||||
|
||||
protected void TouchSourcesOfProject()
|
||||
|
@ -49,14 +61,18 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
protected CommandResult BuildProject(bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false)
|
||||
{
|
||||
var mainProjectFile = GetProjectFile(MainProject);
|
||||
return BuildProject(mainProjectFile, noDependencies, noIncremental, expectBuildFailure);
|
||||
}
|
||||
|
||||
var buildCommand = new BuildCommand(mainProjectFile, output: GetBinRoot(), framework: "dnxcore50", noIncremental : noIncremental, noDependencies : noDependencies);
|
||||
protected CommandResult BuildProject(string projectFile, bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false)
|
||||
{
|
||||
var buildCommand = new BuildCommand(projectFile, output: GetOutputDir(), framework: "dnxcore50", noIncremental: noIncremental, noDependencies : noDependencies);
|
||||
var result = buildCommand.ExecuteWithCapturedOutput();
|
||||
|
||||
if (!expectBuildFailure)
|
||||
{
|
||||
result.Should().Pass();
|
||||
TestOutputExecutable(GetBinRoot(), buildCommand.GetOutputExecutableName(), ExpectedOutput);
|
||||
TestOutputExecutable(GetOutputExePath(), buildCommand.GetOutputExecutableName(), ExpectedOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -66,14 +82,24 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
return result;
|
||||
}
|
||||
|
||||
protected virtual string GetOutputExePath()
|
||||
{
|
||||
return GetBinRoot();
|
||||
}
|
||||
|
||||
protected virtual string GetOutputDir()
|
||||
{
|
||||
return GetBinRoot();
|
||||
}
|
||||
|
||||
protected string GetBinRoot()
|
||||
{
|
||||
return Path.Combine(TempProjectRoot.Path, "bin");
|
||||
return Path.Combine(TestProjectRoot, "bin");
|
||||
}
|
||||
|
||||
protected virtual string GetProjectDirectory(string projectName)
|
||||
{
|
||||
return Path.Combine(TempProjectRoot.Path);
|
||||
return Path.Combine(TestProjectRoot);
|
||||
}
|
||||
|
||||
protected string GetProjectFile(string projectName)
|
||||
|
@ -99,4 +125,4 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
return executablePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,22 +7,33 @@ using System.Linq;
|
|||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||
{
|
||||
public class IncrementalTests : IncrementalTestBase
|
||||
{
|
||||
|
||||
public IncrementalTests() : base(
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestSimpleIncrementalApp"),
|
||||
"TestSimpleIncrementalApp",
|
||||
"Hello World!" + Environment.NewLine)
|
||||
public IncrementalTests()
|
||||
{
|
||||
MainProject = "TestSimpleIncrementalApp";
|
||||
ExpectedOutput = "Hello World!" + Environment.NewLine;
|
||||
}
|
||||
|
||||
private TestInstance _testInstance;
|
||||
|
||||
private void CreateTestInstance()
|
||||
{
|
||||
_testInstance = TestAssetsManager.CreateTestInstance("TestSimpleIncrementalApp")
|
||||
.WithLockFiles();
|
||||
TestProjectRoot = _testInstance.TestRoot;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestNoIncrementalFlag()
|
||||
{
|
||||
CreateTestInstance();
|
||||
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
|
||||
|
@ -33,46 +44,49 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
[Fact]
|
||||
public void TestRebuildMissingPdb()
|
||||
{
|
||||
CreateTestInstance();
|
||||
TestDeleteOutputWithExtension("pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRebuildMissingDll()
|
||||
{
|
||||
CreateTestInstance();
|
||||
TestDeleteOutputWithExtension("dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRebuildMissingXml()
|
||||
{
|
||||
CreateTestInstance();
|
||||
TestDeleteOutputWithExtension("xml");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestNoLockFile()
|
||||
{
|
||||
|
||||
CreateTestInstance();
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
|
||||
var lockFile = Path.Combine(TempProjectRoot.Path, "project.lock.json");
|
||||
var lockFile = Path.Combine(TestProjectRoot, "project.lock.json");
|
||||
Assert.True(File.Exists(lockFile));
|
||||
|
||||
File.Delete(lockFile);
|
||||
Assert.False(File.Exists(lockFile));
|
||||
|
||||
buildResult = BuildProject(expectBuildFailure : true);
|
||||
buildResult = BuildProject(expectBuildFailure: true);
|
||||
Assert.Contains("does not have a lock file", buildResult.StdErr);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRebuildChangedLockFile()
|
||||
{
|
||||
|
||||
CreateTestInstance();
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
|
||||
var lockFile = Path.Combine(TempProjectRoot.Path, "project.lock.json");
|
||||
var lockFile = Path.Combine(TestProjectRoot, "project.lock.json");
|
||||
TouchFile(lockFile);
|
||||
|
||||
buildResult = BuildProject();
|
||||
|
@ -82,7 +96,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
[Fact]
|
||||
public void TestRebuildChangedProjectFile()
|
||||
{
|
||||
|
||||
CreateTestInstance();
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
|
||||
|
@ -96,6 +110,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
[Fact]
|
||||
public void TestInputWithSameTimeAsOutputCausesProjectToCompile()
|
||||
{
|
||||
CreateTestInstance();
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
|
||||
|
|
|
@ -10,16 +10,21 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
{
|
||||
public class IncrementalTestsOnCultureSpecificResource : IncrementalTestBase
|
||||
{
|
||||
public IncrementalTestsOnCultureSpecificResource() : base(
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectWithCultureSpecificResource"),
|
||||
"TestProjectWithCultureSpecificResource",
|
||||
"Hello World!" + Environment.NewLine + "Bonjour!" + Environment.NewLine)
|
||||
public IncrementalTestsOnCultureSpecificResource()
|
||||
{
|
||||
MainProject = "TestProjectWithCultureSpecificResource";
|
||||
ExpectedOutput = "Hello World!" + Environment.NewLine + "Bonjour!" + Environment.NewLine;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
// Sridhar-MS - temporarily disable the test and investigate why it is failing in CI machine.
|
||||
// [Fact]
|
||||
public void TestRebuildSkipsCompilationOnNonCultureResource()
|
||||
{
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithCultureSpecificResource")
|
||||
.WithLockFiles();
|
||||
|
||||
TestProjectRoot = testInstance.TestRoot;
|
||||
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
|
||||
|
@ -28,4 +33,4 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
buildResult.Should().HaveSkippedProjectCompilation(MainProject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,16 +10,20 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
{
|
||||
public class IncrementalTestsOnResources : IncrementalTestBase
|
||||
{
|
||||
public IncrementalTestsOnResources() : base(
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectWithResource"),
|
||||
"TestProjectWithResource",
|
||||
"Hello World!" + Environment.NewLine)
|
||||
public IncrementalTestsOnResources()
|
||||
{
|
||||
MainProject = "TestProjectWithResource";
|
||||
ExpectedOutput = "Hello World!" + Environment.NewLine;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRebuildSkipsCompilationOnNonCultureResource()
|
||||
{
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithResource")
|
||||
.WithLockFiles();
|
||||
|
||||
TestProjectRoot = testInstance.TestRoot;
|
||||
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
|
||||
|
@ -27,4 +31,4 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
buildResult.Should().HaveSkippedProjectCompilation(MainProject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,19 +14,18 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
private const string LibraryProject = "TestLibrary";
|
||||
private const string AppProject = "TestApp";
|
||||
|
||||
public IncrementalTestsTransitiveRuntime() : base(
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestAppWithTransitiveAppDependency"),
|
||||
"TestAppWithTransitiveAppDependency",
|
||||
"This string came from the test library!" + Environment.NewLine)
|
||||
public IncrementalTestsTransitiveRuntime()
|
||||
{
|
||||
Root.CopyDirectory(Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", LibraryProject));
|
||||
Root.CopyDirectory(Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", AppProject));
|
||||
Root.CopyDirectory(Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", TestLibraryWithAppDependency));
|
||||
MainProject = "TestLibrary2";
|
||||
ExpectedOutput = "This string came from the test library!" + Environment.NewLine;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSkipsRebuildWithTransitiveExeDependency()
|
||||
{
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithTransitiveAppDependency")
|
||||
.WithLockFiles();
|
||||
TestProjectRoot = testInstance.TestRoot;
|
||||
var buildResult = BuildProject();
|
||||
buildResult.Should().HaveCompiledProject(MainProject);
|
||||
buildResult.Should().HaveCompiledProject(TestLibraryWithAppDependency);
|
||||
|
@ -40,5 +39,10 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
buildResult.Should().HaveSkippedProjectCompilation(AppProject);
|
||||
buildResult.Should().HaveSkippedProjectCompilation(LibraryProject);
|
||||
}
|
||||
|
||||
protected override string GetProjectDirectory(string projectName)
|
||||
{
|
||||
return Path.Combine(TestProjectRoot, projectName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,17 +19,5 @@
|
|||
}
|
||||
},
|
||||
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/TestApp/**/*",
|
||||
"../../TestAssets/TestProjects/TestLibrary/**/*",
|
||||
"../../TestAssets/TestProjects/TestSimpleIncrementalApp/*",
|
||||
"../../TestAssets/TestProjects/TestProjectToProjectDependencies/**/*",
|
||||
"../../TestAssets/TestProjects/TestProjectWithCultureSpecificResource/**/*",
|
||||
"../../TestAssets/TestProjects/TestProjectWithResource/**/*",
|
||||
"../../TestAssets/TestProjects/TestLibraryWithAppDependency/**/*",
|
||||
"../../TestAssets/TestProjects/TestAppWithTransitiveAppDependency/**/*",
|
||||
"../../TestAssets/TestProjects/global.json"
|
||||
],
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
|
||||
|
||||
var testLibDir = root.CreateDirectory("TestLibrary");
|
||||
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibrary");
|
||||
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestAppWithLibrary", "TestLibrary");
|
||||
|
||||
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/TestLibraryWithAnalyzer/*",
|
||||
"../../TestAssets/TestProjects/TestLibrary/*",
|
||||
"../../TestAssets/TestProjects/TestAppWithLibrary/TestLibrary/*",
|
||||
"../../TestAssets/TestProjects/TestProjectWithCultureSpecificResource/*",
|
||||
"../../TestAssets/TestProjects/global.json"
|
||||
],
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
public GivenACompilationDriverController()
|
||||
{
|
||||
_projectJson =
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestApp", "project.json");
|
||||
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestAppWithLibrary", "TestApp", "project.json");
|
||||
_managedCompilerMock = new Mock<ICompiler>();
|
||||
_managedCompilerMock.Setup(c => c
|
||||
.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()))
|
||||
|
|
|
@ -156,6 +156,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
AppContext.BaseDirectory,
|
||||
"TestAssets",
|
||||
"TestProjects",
|
||||
"TestAppWithLibrary",
|
||||
"TestApp");
|
||||
|
||||
public static string OutputPath = Path.Combine(
|
||||
|
|
|
@ -24,9 +24,7 @@
|
|||
},
|
||||
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/TestLibrary/*",
|
||||
"../../TestAssets/TestProjects/TestApp/*",
|
||||
"../../TestAssets/TestProjects/global.json"
|
||||
"../../TestAssets/TestProjects/TestAppWithLibrary/**/*"
|
||||
],
|
||||
|
||||
"testRunner": "xunit"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Xunit;
|
||||
|
@ -14,10 +15,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
public class PublishTests : TestBase
|
||||
{
|
||||
private readonly string _testProjectsRoot;
|
||||
private readonly Func<string, string, string> _getProjectJson = ProjectUtils.GetProjectJson;
|
||||
|
||||
public PublishTests()
|
||||
{
|
||||
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
|
||||
_testProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "TestProjects");
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> PublishOptions
|
||||
|
@ -26,35 +28,29 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
{
|
||||
return new[]
|
||||
{
|
||||
new object[] { "", "", "", "" },
|
||||
new object[] { "dnxcore50", "", "", "" },
|
||||
new object[] { "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" },
|
||||
new object[] { "", "", "Release", "" },
|
||||
new object[] { "", "", "", "some/dir"},
|
||||
new object[] { "", "", "", "some/dir/with spaces" },
|
||||
new object[] { "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" },
|
||||
new object[] { "1", "", "", "", "" },
|
||||
new object[] { "2", "dnxcore50", "", "", "" },
|
||||
new object[] { "3", "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" },
|
||||
new object[] { "4", "", "", "Release", "" },
|
||||
new object[] { "5", "", "", "", "some/dir"},
|
||||
new object[] { "6", "", "", "", "some/dir/with spaces" },
|
||||
new object[] { "7", "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData("PublishOptions")]
|
||||
public void PublishOptionsTest(string framework, string runtime, string config, string outputDir)
|
||||
public void PublishOptionsTest(string testIdentifier, string framework, string runtime, string config, string outputDir)
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
var root = Temp.CreateDirectory();
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifier)
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
var testAppDir = root.CreateDirectory("TestApp");
|
||||
var testLibDir = root.CreateDirectory("TestLibrary");
|
||||
string testRoot = _getProjectJson(instance.TestRoot, "TestApp");
|
||||
|
||||
//copy projects to the temp dir
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
||||
|
||||
// run publish
|
||||
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(root.Path, outputDir);
|
||||
var testProject = GetProjectPath(testAppDir);
|
||||
var publishCommand = new PublishCommand(testProject, output: outputDir);
|
||||
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(instance.TestRoot, outputDir);
|
||||
var publishCommand = new PublishCommand(testRoot, output: outputDir);
|
||||
publishCommand.Execute().Should().Pass();
|
||||
|
||||
// verify the output executable generated
|
||||
|
@ -74,40 +70,23 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
[Fact]
|
||||
public void ProjectWithContentsTest()
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
var testDir = Temp.CreateDirectory();
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithContents")
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
var testAppDir = Path.Combine(_testProjectsRoot, "TestAppWithContents");
|
||||
|
||||
// copy projects to the temp dir
|
||||
CopyProjectToTempDir(testAppDir, testDir);
|
||||
|
||||
// run publish
|
||||
var testProject = GetProjectPath(testDir);
|
||||
var testProject = _getProjectJson(instance.TestRoot, "TestAppWithContents");
|
||||
var publishCommand = new PublishCommand(testProject);
|
||||
publishCommand.Execute().Should().Pass();
|
||||
|
||||
// make sure that the output dir has the content files
|
||||
publishCommand.Execute().Should().Pass();
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("testcontentfile.txt");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailWhenNoRestoreTest()
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
var root = Temp.CreateDirectory();
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary");
|
||||
|
||||
var testAppDir = root.CreateDirectory("TestApp");
|
||||
var testLibDir = root.CreateDirectory("TestLibrary");
|
||||
|
||||
// copy projects to the temp dir
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
||||
|
||||
File.Delete(Path.Combine(testAppDir.Path, "project.lock.json"));
|
||||
File.Delete(Path.Combine(testLibDir.Path, "project.lock.json"));
|
||||
|
||||
var testProject = GetProjectPath(testAppDir);
|
||||
string testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
||||
var publishCommand = new PublishCommand(testProject);
|
||||
publishCommand.Execute().Should().Fail();
|
||||
}
|
||||
|
@ -115,15 +94,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
[Fact]
|
||||
public void LibraryPublishTest()
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
var root = Temp.CreateDirectory();
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppWithLibrary"))
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
var testLibDir = root.CreateDirectory("TestLibrary");
|
||||
|
||||
//copy projects to the temp dir
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
||||
|
||||
var testProject = GetProjectPath(testLibDir);
|
||||
var testProject = _getProjectJson(instance.TestRoot, "TestLibrary");
|
||||
var publishCommand = new PublishCommand(testProject);
|
||||
publishCommand.Execute().Should().Pass();
|
||||
|
||||
|
@ -137,22 +112,19 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
[WindowsOnlyFact]
|
||||
public void TestLibraryBindingRedirectGeneration()
|
||||
{
|
||||
// Set up Test Staging in Temporary Directory
|
||||
var root = Temp.CreateDirectory();
|
||||
root.CopyDirectory(Path.Combine(_testProjectsRoot, "TestBindingRedirectGeneration"));
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestBindingRedirectGeneration")
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
var testProjectsRootDir = Path.Combine(root.Path, "TestBindingRedirectGeneration");
|
||||
var greaterTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryGreater");
|
||||
var lesserTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryLesser");
|
||||
var lesserTestProject = _getProjectJson(instance.TestRoot, "TestLibraryLesser");
|
||||
|
||||
var lesserTestProject = Path.Combine(lesserTestLibDir, "project.json");
|
||||
var publishCommand = new PublishCommand(lesserTestProject, "net451");
|
||||
publishCommand.Execute().Should().Pass();
|
||||
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll.config");
|
||||
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.deps");
|
||||
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.deps");
|
||||
|
||||
// dependencies should also be copied
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
|
||||
|
@ -164,7 +136,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
|
||||
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.dll.config");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.deps");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.deps");
|
||||
|
||||
// dependencies should also be copied
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
|
||||
|
@ -173,21 +145,15 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
[Fact]
|
||||
public void RefsPublishTest()
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
var root = Temp.CreateDirectory();
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppCompilationContext")
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
var testAppDir = root.CreateDirectory("TestAppCompilationContext");
|
||||
var testLibDir = root.CreateDirectory("TestLibrary");
|
||||
|
||||
// copy projects to the temp dir
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir);
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
||||
|
||||
var testProject = GetProjectPath(testAppDir);
|
||||
var testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
||||
var publishCommand = new PublishCommand(testProject);
|
||||
publishCommand.Execute().Should().Pass();
|
||||
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestAppCompilationContext.dll");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestApp.dll");
|
||||
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibrary.dll");
|
||||
|
||||
var refsDirectory = new DirectoryInfo(Path.Combine(publishCommand.GetOutputDirectory().FullName, "refs"));
|
||||
|
@ -201,13 +167,10 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
[Fact]
|
||||
public void CompilationFailedTest()
|
||||
{
|
||||
var testDir = Temp.CreateDirectory();
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("CompileFail")
|
||||
.WithLockFiles();
|
||||
|
||||
var compileFailDir = Path.Combine(_testProjectsRoot, "CompileFail");
|
||||
|
||||
CopyProjectToTempDir(compileFailDir, testDir);
|
||||
|
||||
var testProject = GetProjectPath(testDir);
|
||||
var testProject = _getProjectJson(instance.TestRoot, "CompileFail");
|
||||
var publishCommand = new PublishCommand(testProject);
|
||||
|
||||
publishCommand.Execute().Should().Fail();
|
||||
|
@ -216,36 +179,17 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
[Fact]
|
||||
public void PublishScriptsRun()
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
var root = Temp.CreateDirectory();
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithScripts")
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
var testAppDir = root.CreateDirectory("TestAppWithScripts");
|
||||
var testProject = _getProjectJson(instance.TestRoot, "TestAppWithScripts");
|
||||
|
||||
//copy projects to the temp dir
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppWithScripts"), testAppDir);
|
||||
|
||||
// run publish
|
||||
var testProject = GetProjectPath(testAppDir);
|
||||
var publishCommand = new PublishCommand(testProject);
|
||||
|
||||
var result = publishCommand.ExecuteWithCapturedOutput();
|
||||
|
||||
result.Should().StdOutMatchPattern("\nprepublish_output( \\?[^%]+\\?){5}.+\npostpublish_output( \\?[^%]+\\?){5}", RegexOptions.Singleline);
|
||||
result.Should().Pass();
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
{
|
||||
// copy all the files to temp dir
|
||||
foreach (var file in Directory.EnumerateFiles(projectDir))
|
||||
{
|
||||
tempDir.CopyFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetProjectPath(TempDirectory projectDir)
|
||||
{
|
||||
return Path.Combine(projectDir.Path, "project.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||
|
||||
"Microsoft.DotNet.TestFramework": "1.0.0-*",
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project"
|
||||
|
@ -20,15 +21,5 @@
|
|||
}
|
||||
},
|
||||
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/TestApp/**/*",
|
||||
"../../TestAssets/TestProjects/TestAppWithScripts/**/*",
|
||||
"../../TestAssets/TestProjects/TestLibrary/**/*",
|
||||
"../../TestAssets/TestProjects/CompileFail/**/*",
|
||||
"../../TestAssets/TestProjects/TestBindingRedirectGeneration/**/*",
|
||||
"../../TestAssets/TestProjects/TestAppCompilationContext/**/*",
|
||||
"../../TestAssets/TestProjects/TestAppWithContents/**/*"
|
||||
],
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue