Skip to content

Commit

Permalink
(cake-build#3549) Add DotNetTest alias (synonym to DotNetCoreTest)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustoproiete committed Oct 23, 2021
1 parent 82038fe commit ae527d8
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 126 deletions.
169 changes: 169 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet.Restore;
using Cake.Common.Tools.DotNet.Run;
using Cake.Common.Tools.DotNet.Test;
using Cake.Common.Tools.DotNet.Tool;
using Cake.Common.Tools.DotNetCore.Build;
using Cake.Common.Tools.DotNetCore.BuildServer;
Expand All @@ -20,6 +21,7 @@
using Cake.Common.Tools.DotNetCore.MSBuild;
using Cake.Common.Tools.DotNetCore.Restore;
using Cake.Common.Tools.DotNetCore.Run;
using Cake.Common.Tools.DotNetCore.Test;
using Cake.Common.Tools.DotNetCore.Tool;
using Cake.Core;
using Cake.Core.Annotations;
Expand Down Expand Up @@ -274,6 +276,173 @@ public static void DotNetBuild(this ICakeContext context, string project, DotNet
builder.Build(project, settings);
}

/// <summary>
/// Test project.
/// </summary>
/// <param name="context">The context.</param>
/// <example>
/// <code>
/// DotNetTest();
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Test")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Test")]
public static void DotNetTest(this ICakeContext context)
{
context.DotNetTest(null, null, null);
}

/// <summary>
/// Test project with path.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The project path.</param>
/// <example>
/// <para>Specify the path to the .csproj file in the test project.</para>
/// <code>
/// DotNetTest("./test/Project.Tests/Project.Tests.csproj");
/// </code>
/// <para>You could also specify a task that runs multiple test projects.</para>
/// <para>Cake task:</para>
/// <code>
/// Task("Test")
/// .Does(() =>
/// {
/// var projectFiles = GetFiles("./test/**/*.csproj");
/// foreach(var file in projectFiles)
/// {
/// DotNetTest(file.FullPath);
/// }
/// });
/// </code>
/// <para>If your test project is using project.json, the project parameter should just be the directory path.</para>
/// <code>
/// DotNetTest("./test/Project.Tests/");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Test")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Test")]
public static void DotNetTest(this ICakeContext context, string project)
{
context.DotNetTest(project, null, null);
}

/// <summary>
/// Test project with settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The project path.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetTestSettings
/// {
/// Configuration = "Release"
/// };
///
/// DotNetTest("./test/Project.Tests/Project.Tests.csproj", settings);
/// </code>
/// <para>You could also specify a task that runs multiple test projects.</para>
/// <para>Cake task:</para>
/// <code>
/// Task("Test")
/// .Does(() =>
/// {
/// var settings = new DotNetTestSettings
/// {
/// Configuration = "Release"
/// };
///
/// var projectFiles = GetFiles("./test/**/*.csproj");
/// foreach(var file in projectFiles)
/// {
/// DotNetTest(file.FullPath, settings);
/// }
/// });
/// </code>
/// <para>If your test project is using project.json, the project parameter should just be the directory path.</para>
/// <code>
/// var settings = new DotNetTestSettings
/// {
/// Configuration = "Release"
/// };
///
/// DotNetTest("./test/Project.Tests/", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Test")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Test")]
public static void DotNetTest(this ICakeContext context, string project, DotNetTestSettings settings)
{
context.DotNetTest(project, null, settings);
}

/// <summary>
/// Test project with settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The project path.</param>
/// <param name="arguments">The arguments.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetTestSettings
/// {
/// Configuration = "Release"
/// };
///
/// DotNetTest("./test/Project.Tests/Project.Tests.csproj", settings);
/// </code>
/// <para>You could also specify a task that runs multiple test projects.</para>
/// <para>Cake task:</para>
/// <code>
/// Task("Test")
/// .Does(() =>
/// {
/// var settings = new DotNetTestSettings
/// {
/// Configuration = "Release"
/// };
///
/// var projectFiles = GetFiles("./test/**/*.csproj");
/// foreach(var file in projectFiles)
/// {
/// DotNetTest(file.FullPath, "MSTest.MapInconclusiveToFailed=true", settings);
/// }
/// });
/// </code>
/// <para>If your test project is using project.json, the project parameter should just be the directory path.</para>
/// <code>
/// var settings = new DotNetTestSettings
/// {
/// Configuration = "Release"
/// };
///
/// DotNetTest("./test/Project.Tests/", "MSTest.MapInconclusiveToFailed=true", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Test")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Test")]
public static void DotNetTest(this ICakeContext context, string project, ProcessArgumentBuilder arguments, DotNetTestSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (settings is null)
{
settings = new DotNetTestSettings();
}

var tester = new DotNetCoreTester(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
tester.Test(project, arguments, settings);
}

/// <summary>
/// Cleans a project's output.
/// </summary>
Expand Down
123 changes: 123 additions & 0 deletions src/Cake.Common/Tools/DotNet/Test/DotNetTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Test;
using Cake.Core.IO;

namespace Cake.Common.Tools.DotNet.Test
{
/// <summary>
/// Contains settings used by <see cref="DotNetCoreTester" />.
/// </summary>
public class DotNetTestSettings : DotNetCoreSettings
{
/// <summary>
/// Gets or sets the settings file to use when running tests.
/// </summary>
public FilePath Settings { get; set; }

/// <summary>
/// Gets or sets the filter expression to filter out tests in the current project.
/// </summary>
/// <remarks>
/// For more information on filtering support, see https://aka.ms/vstest-filtering.
/// </remarks>
public string Filter { get; set; }

/// <summary>
/// Gets or sets the path to use for the custom test adapter in the test run.
/// </summary>
public DirectoryPath TestAdapterPath { get; set; }

/// <summary>
/// Gets or sets a logger for test results.
/// </summary>
[Obsolete("Please use Loggers instead.")]
public string Logger { get; set; }

/// <summary>
/// Gets or sets the loggers for test results.
/// </summary>
public ICollection<string> Loggers { get; set; } = new List<string>();

/// <summary>
/// Gets or sets the output directory.
/// </summary>
public DirectoryPath OutputDirectory { get; set; }

/// <summary>
/// Gets or sets the configuration under which to build.
/// </summary>
public string Configuration { get; set; }

/// <summary>
/// Gets or sets the data collectors for the test run.
/// </summary>
public ICollection<string> Collectors { get; set; } = new List<string>();

/// <summary>
/// Gets or sets specific framework to compile.
/// </summary>
public string Framework { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to not build the project before testing.
/// </summary>
public bool NoBuild { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to not do implicit NuGet package restore.
/// This makes build faster, but requires restore to be done before build is executed.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public bool NoRestore { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to run tests without displaying the Microsoft TestPlatform banner.
/// </summary>
/// <remarks>
/// Available since .NET Core 3.0 SDK.
/// </remarks>
public bool NoLogo { get; set; }

/// <summary>
/// Gets or sets a file to write diagnostic messages to.
/// </summary>
public FilePath DiagnosticFile { get; set; }

/// <summary>
/// Gets or sets the results directory. This setting is only available from 2.0.0 upward.
/// </summary>
public DirectoryPath ResultsDirectory { get; set; }

/// <summary>
/// Gets or sets the file path to write VSTest reports to.
/// </summary>
public FilePath VSTestReportPath { get; set; }

/// <summary>
/// Gets or sets the target runtime to test for. This setting is only available from .NET Core 3.x upward.
/// </summary>
public string Runtime { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to run the tests in blame mode. This option is helpful in isolating a problematic test causing the test host to crash.
/// Outputs a 'Sequence.xml' file in the current directory that captures the order of execution of test before the crash.
/// </summary>
public bool Blame { get; set; }

/// <summary>
/// Gets or sets the specified NuGet package sources to use during testing.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public ICollection<string> Sources { get; set; } = new List<string>();
}
}
Loading

0 comments on commit ae527d8

Please sign in to comment.