Merge pull request #2700 from eerhardt/FixFilePath
"dotnet test project.json" fails in a directory with a test project.json in it
This commit is contained in:
commit
38d0c28a1e
9 changed files with 140 additions and 24 deletions
|
@ -103,6 +103,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-dependency-tool-invo
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Compiler.Common.Tests", "test\Microsoft.DotNet.Compiler.Common.Tests\Microsoft.DotNet.Compiler.Common.Tests.xproj", "{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-pack.Tests", "test\dotnet-pack.Tests\dotnet-pack.Tests.xproj", "{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-run.Tests", "test\dotnet-run.Tests\dotnet-run.Tests.xproj", "{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Performance", "test\Performance\Performance.xproj", "{6A3095FF-A7C5-4300-85A9-C025C384401D}"
|
||||
|
@ -727,6 +729,22 @@ Global
|
|||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Release|x64.Build.0 = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
@ -807,6 +825,7 @@ Global
|
|||
{1AB5B24B-B317-4142-A5D1-A6E84F15BA34} = {ADA7052B-884B-4776-8B8D-D04191D0AA70}
|
||||
{C26A48BB-193F-450C-AB09-4D3324C78188} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
|
||||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{6A3095FF-A7C5-4300-85A9-C025C384401D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
EndGlobalSection
|
||||
|
|
48
src/Microsoft.DotNet.ProjectModel/ProjectPathHelper.cs
Normal file
48
src/Microsoft.DotNet.ProjectModel/ProjectPathHelper.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
// 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;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel
|
||||
{
|
||||
internal static class ProjectPathHelper
|
||||
{
|
||||
public static string NormalizeProjectDirectoryPath(string path)
|
||||
{
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
|
||||
if (IsProjectFilePath(fullPath))
|
||||
{
|
||||
return Path.GetDirectoryName(fullPath);
|
||||
}
|
||||
else if (IsDirectoryContainingProjectFile(fullPath))
|
||||
{
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string NormalizeProjectFilePath(string path)
|
||||
{
|
||||
if (!path.EndsWith(Project.FileName))
|
||||
{
|
||||
path = Path.Combine(path, Project.FileName);
|
||||
}
|
||||
|
||||
return Path.GetFullPath(path);
|
||||
}
|
||||
|
||||
private static bool IsProjectFilePath(string path)
|
||||
{
|
||||
return File.Exists(path) &&
|
||||
string.Equals(Path.GetFileName(path), Project.FileName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static bool IsDirectoryContainingProjectFile(string path)
|
||||
{
|
||||
return Directory.Exists(path) && File.Exists(Path.Combine(path, Project.FileName));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,10 +64,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public static Project GetProject(string projectPath, ProjectReaderSettings settings = null)
|
||||
{
|
||||
if (!projectPath.EndsWith(Project.FileName))
|
||||
{
|
||||
projectPath = Path.Combine(projectPath, Project.FileName);
|
||||
}
|
||||
projectPath = ProjectPathHelper.NormalizeProjectFilePath(projectPath);
|
||||
|
||||
var name = Path.GetFileName(Path.GetDirectoryName(projectPath));
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public void AddProject(string path)
|
||||
{
|
||||
var projectPath = NormalizeProjectPath(path);
|
||||
var projectPath = ProjectPathHelper.NormalizeProjectDirectoryPath(path);
|
||||
|
||||
if (projectPath != null)
|
||||
{
|
||||
|
@ -228,7 +228,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public ProjectContextCollection GetProjectContextCollection(string projectPath)
|
||||
{
|
||||
var normalizedPath = NormalizeProjectPath(projectPath);
|
||||
var normalizedPath = ProjectPathHelper.NormalizeProjectDirectoryPath(projectPath);
|
||||
if (normalizedPath == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -242,7 +242,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
private FileModelEntry<Project> GetProjectCore(string projectDirectory)
|
||||
{
|
||||
var normalizedPath = NormalizeProjectPath(projectDirectory);
|
||||
var normalizedPath = ProjectPathHelper.NormalizeProjectDirectoryPath(projectDirectory);
|
||||
if (normalizedPath == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -256,7 +256,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
private LockFile GetLockFile(string projectDirectory)
|
||||
{
|
||||
var normalizedPath = NormalizeProjectPath(projectDirectory);
|
||||
var normalizedPath = ProjectPathHelper.NormalizeProjectDirectoryPath(projectDirectory);
|
||||
if (normalizedPath == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -441,22 +441,6 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
}
|
||||
}
|
||||
|
||||
private static string NormalizeProjectPath(string path)
|
||||
{
|
||||
if (File.Exists(path) &&
|
||||
string.Equals(Path.GetFileName(path), Project.FileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Path.GetFullPath(Path.GetDirectoryName(path));
|
||||
}
|
||||
else if (Directory.Exists(path) &&
|
||||
File.Exists(Path.Combine(path, Project.FileName)))
|
||||
{
|
||||
return Path.GetFullPath(path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<string> ResolveProjectPath(string projectPath)
|
||||
{
|
||||
if (File.Exists(projectPath))
|
||||
|
|
|
@ -43,6 +43,20 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
.Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_builds_projects_with_a_local_project_json_path()
|
||||
{
|
||||
var testInstance = TestAssetsManager
|
||||
.CreateTestInstance("TestAppSimple")
|
||||
.WithLockFiles();
|
||||
|
||||
new BuildCommand("project.json")
|
||||
.WithWorkingDirectory(testInstance.TestRoot)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_builds_projects_with_xmlDoc_and_spaces_in_the_path()
|
||||
{
|
||||
|
|
|
@ -136,6 +136,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.pdb");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PackWorksWithLocalProjectJson()
|
||||
{
|
||||
var testInstance = TestAssetsManager
|
||||
.CreateTestInstance("TestAppSimple")
|
||||
.WithLockFiles();
|
||||
|
||||
new PackCommand(Project.FileName)
|
||||
.WithWorkingDirectory(testInstance.TestRoot)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
{
|
||||
// copy all the files to temp dir
|
||||
|
|
|
@ -360,5 +360,18 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
command.Execute($"publish {temp}").Should().Fail();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishWorksWithLocalProjectJson()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppSimple")
|
||||
.WithLockFiles();
|
||||
|
||||
new PublishCommand("project.json")
|
||||
.WithWorkingDirectory(instance.TestRoot)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,21 @@ namespace Microsoft.DotNet.Tools.Run.Tests
|
|||
new RunCommand(instance.TestRoot).Execute().Should().Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItRunsWithLocalProjectJsonArg()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppSimple")
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
new RunCommand("project.json")
|
||||
.WithWorkingDirectory(instance.TestRoot)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Pass()
|
||||
.And
|
||||
.HaveStdOutContaining("Hello World!");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItRunsAppsThatOutputUnicodeCharacters()
|
||||
{
|
||||
|
|
|
@ -55,6 +55,18 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
result.Should().Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_runs_tests_for_a_local_project_json()
|
||||
{
|
||||
string projectDirectory = Path.GetDirectoryName(_projectFilePath);
|
||||
|
||||
new DotnetTestCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.Execute("project.json")
|
||||
.Should()
|
||||
.Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_builds_the_project_using_the_output_passed()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue