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>
|
||||
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>
|
||||
/// Returns path2 relative to path1, with given path separator
|
||||
/// </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))
|
||||
{
|
||||
|
@ -138,10 +147,14 @@ namespace Microsoft.DotNet.Tools.Common
|
|||
return path;
|
||||
}
|
||||
|
||||
for (var i = index; len1 > i; ++i)
|
||||
if (includeDirectoryTraversals)
|
||||
{
|
||||
path += ".." + separator;
|
||||
for (var i = index; len1 > i; ++i)
|
||||
{
|
||||
path += ".." + separator;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = index; len2 - 1 > i; ++i)
|
||||
{
|
||||
path += path2Segments[i] + separator;
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Microsoft.Dotnet.Cli.Compiler.Common
|
|||
var pathMap = sourceFiles
|
||||
.ToDictionary(s => s,
|
||||
s => Path.Combine(targetDirectory,
|
||||
PathUtility.GetRelativePath(sourceDirectory, s)));
|
||||
PathUtility.GetRelativePathIgnoringDirectoryTraversals(sourceDirectory, s)));
|
||||
|
||||
foreach (var targetDir in pathMap.Values
|
||||
.Select(Path.GetDirectoryName)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"NETStandard.Library": "1.0.0-rc2-23728"
|
||||
},
|
||||
|
||||
"content": "testcontentfile.txt",
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
|
|
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
|
||||
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" };
|
||||
|
||||
public ProjectToProjectDependenciesIncrementalTest() : base(
|
||||
Path.Combine("TestProjects", "TestProjectToProjectDependencies"),
|
||||
Path.Combine(AppContext.BaseDirectory, "TestProjects", "TestProjectToProjectDependencies"),
|
||||
"L0",
|
||||
"L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
{
|
||||
|
||||
public IncrementalTests() : base(
|
||||
Path.Combine("TestProjects", "TestSimpleIncrementalApp"),
|
||||
Path.Combine(AppContext.BaseDirectory, "TestProjects", "TestSimpleIncrementalApp"),
|
||||
"TestSimpleIncrementalApp",
|
||||
"Hello World!" + Environment.NewLine)
|
||||
{
|
||||
|
|
|
@ -1,25 +1,30 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23728",
|
||||
|
||||
"dependencies": {
|
||||
"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.Cli.Utils": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
}
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-dev-45337-57"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"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 Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||
namespace Microsoft.DotNet.Tools.Compiler.Tests
|
||||
{
|
||||
public class CompilerTests : TestBase
|
||||
{
|
||||
private string _testProjectsRoot = @"TestProjects";
|
||||
private readonly string _testProjectsRoot;
|
||||
|
||||
public CompilerTests()
|
||||
{
|
||||
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, @"TestProjects");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void XmlDocumentationFileIsGenerated()
|
||||
|
@ -20,8 +25,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
|
||||
|
||||
var testLibDir = root.CreateDirectory("TestLibrary");
|
||||
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibrary");
|
||||
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
|
||||
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
||||
|
||||
// run compile
|
||||
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
||||
|
@ -39,11 +45,12 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
|
||||
[Fact]
|
||||
public void LibraryWithAnalyzer()
|
||||
{
|
||||
{
|
||||
var root = Temp.CreateDirectory();
|
||||
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
|
||||
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer"), testLibDir);
|
||||
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer");
|
||||
|
||||
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
||||
|
||||
// run compile
|
||||
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
||||
|
|
|
@ -1,25 +1,30 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"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.Cli.Utils": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
}
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23728",
|
||||
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-dev-45337-57"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"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 Xunit;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -68,7 +72,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
[ActiveIssue(491)]
|
||||
public void ProjectWithContentsTest()
|
||||
{
|
||||
// create unique directories in the 'temp' folder
|
||||
|
|
|
@ -1,25 +1,35 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23728",
|
||||
"Microsoft.NETCore.TestHost": "1.0.0-rc2-*",
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "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.Cli.Utils": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
}
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
"xunit": "2.1.0",
|
||||
"xunit.netcore.extensions": "1.0.0-prerelease-*",
|
||||
"dotnet-test-xunit": "1.0.0-dev-45337-57"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
},
|
||||
|
||||
"content": [
|
||||
"../TestProjects/TestApp/**/*",
|
||||
"../TestProjects/TestLibrary/**/*",
|
||||
"../TestProjects/CompileFail/**/*",
|
||||
"../TestProjects/TestBindingRedirectGeneration/**/*",
|
||||
"../TestProjects/TestAppCompilationContext/**/*",
|
||||
"../TestProjects/TestAppWithContents/**/*",
|
||||
"../TestProjects/global.json"
|
||||
],
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue