Making dotnet-compile run with dotnet test. Added a method to PathUtil to calculate target paths ignoring directory traversal characters.
Making dotnet-build.tests run with dotnet test Making dotnet-publish.test work with dotnet test
This commit is contained in:
parent
7236a72917
commit
3048eb487c
10 changed files with 116 additions and 73 deletions
|
@ -70,13 +70,22 @@ namespace Microsoft.DotNet.Tools.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetRelativePath(string path1, string path2)
|
public static string GetRelativePath(string path1, string path2)
|
||||||
{
|
{
|
||||||
return GetRelativePath(path1, path2, Path.DirectorySeparatorChar);
|
return GetRelativePath(path1, path2, Path.DirectorySeparatorChar, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns path2 relative to path1, with Path.DirectorySeparatorChar as separator but ignoring directory
|
||||||
|
/// traversals.
|
||||||
|
/// </summary>
|
||||||
|
public static string GetRelativePathIgnoringDirectoryTraversals(string path1, string path2)
|
||||||
|
{
|
||||||
|
return GetRelativePath(path1, path2, Path.DirectorySeparatorChar, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns path2 relative to path1, with given path separator
|
/// Returns path2 relative to path1, with given path separator
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetRelativePath(string path1, string path2, char separator)
|
public static string GetRelativePath(string path1, string path2, char separator, bool includeDirectoryTraversals)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path1))
|
if (string.IsNullOrEmpty(path1))
|
||||||
{
|
{
|
||||||
|
@ -138,10 +147,14 @@ namespace Microsoft.DotNet.Tools.Common
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (includeDirectoryTraversals)
|
||||||
|
{
|
||||||
for (var i = index; len1 > i; ++i)
|
for (var i = index; len1 > i; ++i)
|
||||||
{
|
{
|
||||||
path += ".." + separator;
|
path += ".." + separator;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = index; len2 - 1 > i; ++i)
|
for (var i = index; len2 - 1 > i; ++i)
|
||||||
{
|
{
|
||||||
path += path2Segments[i] + separator;
|
path += path2Segments[i] + separator;
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace Microsoft.Dotnet.Cli.Compiler.Common
|
||||||
var pathMap = sourceFiles
|
var pathMap = sourceFiles
|
||||||
.ToDictionary(s => s,
|
.ToDictionary(s => s,
|
||||||
s => Path.Combine(targetDirectory,
|
s => Path.Combine(targetDirectory,
|
||||||
PathUtility.GetRelativePath(sourceDirectory, s)));
|
PathUtility.GetRelativePathIgnoringDirectoryTraversals(sourceDirectory, s)));
|
||||||
|
|
||||||
foreach (var targetDir in pathMap.Values
|
foreach (var targetDir in pathMap.Values
|
||||||
.Select(Path.GetDirectoryName)
|
.Select(Path.GetDirectoryName)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"NETStandard.Library": "1.0.0-rc2-23728"
|
"NETStandard.Library": "1.0.0-rc2-23728"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"content": "testcontentfile.txt",
|
||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnxcore50": { }
|
"dnxcore50": { }
|
||||||
|
|
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Builder.Tests
|
namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||||
|
@ -16,7 +15,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||||
private string[] _projects = new[] { "L0", "L11", "L12", "L21", "L22" };
|
private string[] _projects = new[] { "L0", "L11", "L12", "L21", "L22" };
|
||||||
|
|
||||||
public ProjectToProjectDependenciesIncrementalTest() : base(
|
public ProjectToProjectDependenciesIncrementalTest() : base(
|
||||||
Path.Combine("TestProjects", "TestProjectToProjectDependencies"),
|
Path.Combine(AppContext.BaseDirectory, "TestProjects", "TestProjectToProjectDependencies"),
|
||||||
"L0",
|
"L0",
|
||||||
"L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine)
|
"L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||||
{
|
{
|
||||||
|
|
||||||
public IncrementalTests() : base(
|
public IncrementalTests() : base(
|
||||||
Path.Combine("TestProjects", "TestSimpleIncrementalApp"),
|
Path.Combine(AppContext.BaseDirectory, "TestProjects", "TestSimpleIncrementalApp"),
|
||||||
"TestSimpleIncrementalApp",
|
"TestSimpleIncrementalApp",
|
||||||
"Hello World!" + Environment.NewLine)
|
"Hello World!" + Environment.NewLine)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,23 +3,28 @@
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NETStandard.Library": "1.0.0-rc2-23728",
|
"NETStandard.Library": "1.0.0-rc2-23728",
|
||||||
"Microsoft.NETCore.TestHost" : "1.0.0-rc2-23728",
|
|
||||||
|
|
||||||
"xunit": "2.1.0",
|
|
||||||
"xunit.console.netcore": "1.0.2-prerelease-00101",
|
|
||||||
"xunit.netcore.extensions": "1.0.0-prerelease-*",
|
|
||||||
"xunit.runner.utility": "2.1.0",
|
|
||||||
|
|
||||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||||
"Microsoft.DotNet.Cli.Utils": {
|
"Microsoft.DotNet.Cli.Utils": {
|
||||||
"target": "project",
|
"target": "project",
|
||||||
"type": "build"
|
"type": "build"
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"xunit": "2.1.0",
|
||||||
|
"dotnet-test-xunit": "1.0.0-dev-45337-57"
|
||||||
},
|
},
|
||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnxcore50": {
|
"dnxcore50": {
|
||||||
"imports": "portable-net45+win8"
|
"imports": "portable-net45+win8"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"content": [
|
||||||
|
"../TestProjects/TestSimpleIncrementalApp/*",
|
||||||
|
"../TestProjects/TestProjectToProjectDependencies/**/*",
|
||||||
|
"../TestProjects/global.json"
|
||||||
|
],
|
||||||
|
|
||||||
|
"testRunner": "xunit"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,16 @@ using System.IO;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Publish.Tests
|
namespace Microsoft.DotNet.Tools.Compiler.Tests
|
||||||
{
|
{
|
||||||
public class CompilerTests : TestBase
|
public class CompilerTests : TestBase
|
||||||
{
|
{
|
||||||
private string _testProjectsRoot = @"TestProjects";
|
private readonly string _testProjectsRoot;
|
||||||
|
|
||||||
|
public CompilerTests()
|
||||||
|
{
|
||||||
|
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, @"TestProjects");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void XmlDocumentationFileIsGenerated()
|
public void XmlDocumentationFileIsGenerated()
|
||||||
|
@ -20,8 +25,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||||
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
|
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
|
||||||
|
|
||||||
var testLibDir = root.CreateDirectory("TestLibrary");
|
var testLibDir = root.CreateDirectory("TestLibrary");
|
||||||
|
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibrary");
|
||||||
|
|
||||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
||||||
|
|
||||||
// run compile
|
// run compile
|
||||||
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
||||||
|
@ -42,8 +48,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||||
{
|
{
|
||||||
var root = Temp.CreateDirectory();
|
var root = Temp.CreateDirectory();
|
||||||
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
|
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
|
||||||
|
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer");
|
||||||
|
|
||||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer"), testLibDir);
|
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
||||||
|
|
||||||
// run compile
|
// run compile
|
||||||
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
||||||
|
|
|
@ -3,23 +3,28 @@
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NETStandard.Library": "1.0.0-rc2-23728",
|
"NETStandard.Library": "1.0.0-rc2-23728",
|
||||||
"Microsoft.NETCore.TestHost" : "1.0.0-rc2-23728",
|
|
||||||
|
|
||||||
"xunit": "2.1.0",
|
|
||||||
"xunit.console.netcore": "1.0.2-prerelease-00101",
|
|
||||||
"xunit.netcore.extensions": "1.0.0-prerelease-*",
|
|
||||||
"xunit.runner.utility": "2.1.0",
|
|
||||||
|
|
||||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||||
"Microsoft.DotNet.Cli.Utils": {
|
"Microsoft.DotNet.Cli.Utils": {
|
||||||
"target": "project",
|
"target": "project",
|
||||||
"type": "build"
|
"type": "build"
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"xunit": "2.1.0",
|
||||||
|
"dotnet-test-xunit": "1.0.0-dev-45337-57"
|
||||||
},
|
},
|
||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnxcore50": {
|
"dnxcore50": {
|
||||||
"imports": "portable-net45+win8"
|
"imports": "portable-net451+win8"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"content": [
|
||||||
|
"../TestProjects/TestLibraryWithAnalyzer/*",
|
||||||
|
"../TestProjects/TestLibrary/*",
|
||||||
|
"../TestProjects/global.json"
|
||||||
|
],
|
||||||
|
|
||||||
|
"testRunner": "xunit"
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,17 @@ using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Publish.Tests
|
namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||||
{
|
{
|
||||||
public class PublishTests : TestBase
|
public class PublishTests : TestBase
|
||||||
{
|
{
|
||||||
private string _testProjectsRoot = @"TestProjects";
|
private readonly string _testProjectsRoot;
|
||||||
|
|
||||||
|
public PublishTests()
|
||||||
|
{
|
||||||
|
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, @"TestProjects");
|
||||||
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> PublishOptions
|
public static IEnumerable<object[]> PublishOptions
|
||||||
{
|
{
|
||||||
|
@ -68,7 +72,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[ActiveIssue(491)]
|
|
||||||
public void ProjectWithContentsTest()
|
public void ProjectWithContentsTest()
|
||||||
{
|
{
|
||||||
// create unique directories in the 'temp' folder
|
// create unique directories in the 'temp' folder
|
||||||
|
|
|
@ -3,23 +3,33 @@
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NETStandard.Library": "1.0.0-rc2-23728",
|
"NETStandard.Library": "1.0.0-rc2-23728",
|
||||||
"Microsoft.NETCore.TestHost": "1.0.0-rc2-*",
|
|
||||||
|
|
||||||
"xunit": "2.1.0",
|
|
||||||
"xunit.console.netcore": "1.0.2-prerelease-00101",
|
|
||||||
"xunit.netcore.extensions": "1.0.0-prerelease-*",
|
|
||||||
"xunit.runner.utility": "2.1.0",
|
|
||||||
|
|
||||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||||
"Microsoft.DotNet.Cli.Utils": {
|
"Microsoft.DotNet.Cli.Utils": {
|
||||||
"target": "project",
|
"target": "project",
|
||||||
"type": "build"
|
"type": "build"
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"xunit": "2.1.0",
|
||||||
|
"xunit.netcore.extensions": "1.0.0-prerelease-*",
|
||||||
|
"dotnet-test-xunit": "1.0.0-dev-45337-57"
|
||||||
},
|
},
|
||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnxcore50": {
|
"dnxcore50": {
|
||||||
"imports": "portable-net45+win8"
|
"imports": "portable-net45+win8"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"content": [
|
||||||
|
"../TestProjects/TestApp/**/*",
|
||||||
|
"../TestProjects/TestLibrary/**/*",
|
||||||
|
"../TestProjects/CompileFail/**/*",
|
||||||
|
"../TestProjects/TestBindingRedirectGeneration/**/*",
|
||||||
|
"../TestProjects/TestAppCompilationContext/**/*",
|
||||||
|
"../TestProjects/TestAppWithContents/**/*",
|
||||||
|
"../TestProjects/global.json"
|
||||||
|
],
|
||||||
|
|
||||||
|
"testRunner": "xunit"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue