Improve error messages for the migrate command
This commit is contained in:
Justin Goshi 2016-10-11 10:58:49 -10:00 committed by GitHub
commit 19abf66412
3 changed files with 57 additions and 7 deletions

View file

@ -268,8 +268,54 @@ namespace Microsoft.DotNet.Migration.Tests
outputsIdentical.Should().BeTrue();
VerifyAllMSBuildOutputsRunnable(projectDirectory);
}
[Theory]
// https://github.com/dotnet/cli/issues/4313
[InlineData(true)]
[InlineData(false)]
public void Migration_outputs_error_when_no_projects_found(bool useGlobalJson)
{
var projectDirectory = TestAssetsManager.CreateTestDirectory("Migration_outputs_error_when_no_projects_found");
private void VerifyMigration(IEnumerable<string> expectedProjects, string rootDir)
string argstr = string.Empty;
string errorMessage = string.Empty;
if (useGlobalJson)
{
var globalJsonPath = Path.Combine(projectDirectory.Path, "global.json");
using (FileStream fs = File.Create(globalJsonPath))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine("{");
sw.WriteLine("\"projects\": [ \".\" ]");
sw.WriteLine("}");
}
}
argstr = globalJsonPath;
errorMessage = "Unable to find any projects in global.json";
}
else
{
argstr = projectDirectory.Path;
errorMessage = $"No project.json file found in '{projectDirectory.Path}'";
}
var result = new TestCommand("dotnet")
.WithWorkingDirectory(projectDirectory.Path)
.ExecuteWithCapturedOutput($"migrate {argstr}");
// Expecting an error exit code.
result.ExitCode.Should().Be(1);
// Verify the error messages. Note that debug builds also show the call stack, so we search
// for the error strings that should be present (rather than an exact match).
result.StdErr.Should().Contain(errorMessage);
result.StdErr.Should().Contain("Migration failed.");
}
private void VerifyMigration(IEnumerable<string> expectedProjects, string rootDir)
{
var migratedProjects = Directory.EnumerateFiles(rootDir, "project.json", SearchOption.AllDirectories)
.Where(s => Directory.EnumerateFiles(Path.GetDirectoryName(s), "*.csproj").Count() == 1)