2017-01-12 23:42:36 +00:00
|
|
|
// 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.IO;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Utils.Tests
|
|
|
|
{
|
|
|
|
public class GivenAppThrowingException : TestBase
|
|
|
|
{
|
2017-04-27 22:48:48 +00:00
|
|
|
[RequiresSpecificFrameworkFact("netcoreapp1.1")]
|
2017-01-12 23:42:36 +00:00
|
|
|
public void ItShowsStackTraceWhenRun()
|
|
|
|
{
|
|
|
|
var root = TestAssets.Get("NonRestoredTestProjects", "AppThrowingException")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root;
|
|
|
|
|
|
|
|
var appRoot = Path.Combine(root.FullName, "App");
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(appRoot)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
string msg1 = "Unhandled Exception: AppThrowing.MyException: "
|
|
|
|
+ "Exception of type 'AppThrowing.MyException' was thrown.";
|
|
|
|
string msg2 = "at AppThrowing.MyException.Main(String[] args)";
|
2017-04-27 20:45:12 +00:00
|
|
|
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
2017-01-12 23:42:36 +00:00
|
|
|
.WithWorkingDirectory(appRoot)
|
2017-04-27 20:45:12 +00:00
|
|
|
.ExecuteWithCapturedOutput("run")
|
2017-01-12 23:42:36 +00:00
|
|
|
.Should().Fail()
|
|
|
|
.And.HaveStdErrContaining(msg1)
|
|
|
|
.And.HaveStdErrContaining(msg2);
|
|
|
|
}
|
|
|
|
|
2017-04-27 22:48:48 +00:00
|
|
|
[RequiresSpecificFrameworkFact("netcoreapp1.1")]
|
2017-01-12 23:42:36 +00:00
|
|
|
public void ItShowsStackTraceWhenRunAsTool()
|
|
|
|
{
|
|
|
|
var root = TestAssets.Get("NonRestoredTestProjects", "AppThrowingException")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root;
|
|
|
|
|
|
|
|
var appRoot = Path.Combine(root.FullName, "App");
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(appRoot)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new PackCommand()
|
|
|
|
.WithWorkingDirectory(appRoot)
|
|
|
|
.Execute("-o ../pkgs")
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
var appWithToolDepRoot = Path.Combine(root.FullName, "AppDependingOnOtherAsTool");
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(appWithToolDepRoot)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
string msg1 = "Unhandled Exception: AppThrowing.MyException: "
|
|
|
|
+ "Exception of type 'AppThrowing.MyException' was thrown.";
|
|
|
|
string msg2 = "at AppThrowing.MyException.Main(String[] args)";
|
2017-04-27 20:45:12 +00:00
|
|
|
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
2017-01-12 23:42:36 +00:00
|
|
|
.WithWorkingDirectory(appWithToolDepRoot)
|
|
|
|
.ExecuteWithCapturedOutput("throwingtool")
|
|
|
|
.Should().Fail()
|
|
|
|
.And.HaveStdErrContaining(msg1)
|
|
|
|
.And.HaveStdErrContaining(msg2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|