dotnet-installer/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/CommandResultAssertions.cs
Bryan 0fd81e0a2d Extract dotnet-compile-fsc into a standalone command
Add basic Tests for dotnet-compile-fsc

Package Targets execute before TestTargets. Use Generated Nuget Packages in TestTargets. Generate Nuget packages on all platforms, and in C#

Fix bug in dotnet-restore, change fsharp new template, add support for native assets in DependencyContextCsvReader

copy fsc.exe to temp directory instead of package cache

fix rebase error

fix issue

fixes

fixes

fix

temporarily disable debian package e2e testing

fixes

bump fsc version

update fsc version

fix rebase errors

WIP update fsc tool

WIP, rebased and working again, need to solve issues with System.CommandLine

Working state for packaged, command, fsc.exe bugging out with dlopen(, 1): no suitable image found.

execute fsc like a unpublished standalone app

fixup after rebase

working? internet is out

working

cleanup

More cleanup, and run the debian package tests during the Test phase of the build.

update FSharp Test Projects NetStandard Library Version

Update Version Suffix when packing TestPackages. This will enable packing with the right dependency versions on Windows.

update dotnet-test version

Undo the reordering of the build

fix test package project pathsj

ignore net451 build failures for test packages which we need to build on non-windows

update dependency of desktop test app

add dotnetcli feed to nuget config for fsharp dotnet new

update deps after rebase

update dependency of dotnet-compile-fsc

pass args before commandPath when using muxer for tools

adjust testpackage cleaning not to clean packages which are also generated as part of the product from the nuget cache.

undo

Pass projectJson to pack instead of using WorkingDirectory

fix path separators using depsjsoncommandresolver on windows, fix building only specific frameworks for testpackages on non-windows.

PR Feedback

rebase

overwrite fsc runtimeconfig
2016-03-31 14:01:08 -07:00

129 lines
6.3 KiB
C#

// 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.Text.RegularExpressions;
using FluentAssertions;
using FluentAssertions.Execution;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class CommandResultAssertions
{
private CommandResult _commandResult;
public CommandResultAssertions(CommandResult commandResult)
{
_commandResult = commandResult;
}
public AndConstraint<CommandResultAssertions> ExitWith(int expectedExitCode)
{
Execute.Assertion.ForCondition(_commandResult.ExitCode == expectedExitCode)
.FailWith(AppendDiagnosticsTo($"Expected command to exit with {expectedExitCode} but it did not."));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> Pass()
{
Execute.Assertion.ForCondition(_commandResult.ExitCode == 0)
.FailWith(AppendDiagnosticsTo($"Expected command to pass but it did not."));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> Fail()
{
Execute.Assertion.ForCondition(_commandResult.ExitCode != 0)
.FailWith(AppendDiagnosticsTo($"Expected command to fail but it did not."));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdOut()
{
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(_commandResult.StdOut))
.FailWith(AppendDiagnosticsTo("Command did not output anything to stdout"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdOut(string expectedOutput)
{
Execute.Assertion.ForCondition(_commandResult.StdOut.Equals(expectedOutput, StringComparison.Ordinal))
.FailWith(AppendDiagnosticsTo($"Command did not output with Expected Output. Expected: {expectedOutput}"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdOutContaining(string pattern)
{
Execute.Assertion.ForCondition(_commandResult.StdOut.Contains(pattern))
.FailWith(AppendDiagnosticsTo($"The command output did not contain expected result: {pattern}{Environment.NewLine}"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdOutMatching(string pattern, RegexOptions options = RegexOptions.None)
{
Execute.Assertion.ForCondition(Regex.Match(_commandResult.StdOut, pattern, options).Success)
.FailWith(AppendDiagnosticsTo($"Matching the command output failed. Pattern: {pattern}{Environment.NewLine}"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdErr()
{
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(_commandResult.StdErr))
.FailWith(AppendDiagnosticsTo("Command did not output anything to stderr."));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdErrContaining(string pattern)
{
Execute.Assertion.ForCondition(_commandResult.StdErr.Contains(pattern))
.FailWith(AppendDiagnosticsTo($"The command error output did not contain expected result: {pattern}{Environment.NewLine}"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdErrMatching(string pattern, RegexOptions options = RegexOptions.None)
{
Execute.Assertion.ForCondition(Regex.Match(_commandResult.StdErr, pattern, options).Success)
.FailWith(AppendDiagnosticsTo($"Matching the command error output failed. Pattern: {pattern}{Environment.NewLine}"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> NotHaveStdOut()
{
Execute.Assertion.ForCondition(string.IsNullOrEmpty(_commandResult.StdOut))
.FailWith(AppendDiagnosticsTo($"Expected command to not output to stdout but it was not:"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> NotHaveStdErr()
{
Execute.Assertion.ForCondition(string.IsNullOrEmpty(_commandResult.StdErr))
.FailWith(AppendDiagnosticsTo("Expected command to not output to stderr but it was not:"));
return new AndConstraint<CommandResultAssertions>(this);
}
private string AppendDiagnosticsTo(string s)
{
return s + $"{Environment.NewLine}" +
$"File Name: {_commandResult.StartInfo.FileName}{Environment.NewLine}" +
$"Arguments: {_commandResult.StartInfo.Arguments}{Environment.NewLine}" +
$"Exit Code: {_commandResult.ExitCode}{Environment.NewLine}" +
$"StdOut:{Environment.NewLine}{_commandResult.StdOut}{Environment.NewLine}" +
$"StdErr:{Environment.NewLine}{_commandResult.StdErr}{Environment.NewLine}"; ;
}
public AndConstraint<CommandResultAssertions> HaveSkippedProjectCompilation(string skippedProject)
{
_commandResult.StdOut.Should().Contain($"Project {skippedProject} (.NETStandardApp,Version=v1.5) was previously compiled. Skipping compilation.");
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveCompiledProject(string compiledProject)
{
_commandResult.StdOut.Should().Contain($"Project {compiledProject} (.NETStandardApp,Version=v1.5) will be compiled");
return new AndConstraint<CommandResultAssertions>(this);
}
}
}