Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for globbing filter #46495

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,90 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.RegularExpressions;
using dotnet.Tests;
using CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult;

namespace Microsoft.DotNet.Cli.Test.Tests
{
public class GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter : SdkTest
{
private const string TestApplicationArgsPattern = @".*(Test application arguments).*";

public GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter(ITestOutputHelper log) : base(log)
{
}

[InlineData(Constants.Debug)]
[InlineData(Constants.Release)]
[Theory]
public void RunTestProjectWithFilterOfDll_ShouldReturnZeroAsExitCode(string configuration)
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString())
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

var binDirectory = new FileInfo($"{testInstance.Path}/bin").Directory;
var binDirectoryLastWriteTime = binDirectory?.LastWriteTime;

CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.WithEnableTestingPlatform()
.Execute(TestingPlatformOptions.TestModulesFilterOption.Name, "**/bin/**/Debug/net8.0/TestProject.dll",
TestingPlatformOptions.ConfigurationOption.Name, configuration);

// Assert that the bin folder hasn't been modified
Assert.Equal(binDirectoryLastWriteTime, binDirectory?.LastWriteTime);

if (!TestContext.IsLocalized())
{
result.StdOut
.Should().Contain("Test run summary: Passed!")
.And.Contain("total: 2")
.And.Contain("succeeded: 1")
.And.Contain("failed: 0")
.And.Contain("skipped: 1");
}

result.ExitCode.Should().Be(ExitCodes.Success);
}

[InlineData(Constants.Debug)]
[InlineData(Constants.Release)]
[Theory]
public void RunTestProjectWithFilterOfDllWithRootDirectory_ShouldReturnZeroAsExitCode(string configuration)
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString())
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.WithEnableTestingPlatform()
.WithTraceOutput()
.Execute(TestingPlatformOptions.TestModulesFilterOption.Name, "**/bin/**/Debug/net8.0/TestProject.dll",
TestingPlatformOptions.TestModulesRootDirectoryOption.Name, testInstance.TestRoot,
TestingPlatformOptions.ConfigurationOption.Name, configuration);


var testAppArgs = Regex.Matches(result.StdOut!, TestApplicationArgsPattern);
Assert.Contains($"exec {testInstance.TestRoot}\\bin\\Debug\\net8.0\\TestProject.dll", testAppArgs.FirstOrDefault()?.Value);

if (!TestContext.IsLocalized())
{
result.StdOut
.Should().Contain("Test run summary: Passed!")
.And.Contain("total: 2")
.And.Contain("succeeded: 1")
.And.Contain("failed: 0")
.And.Contain("skipped: 1");
}

result.ExitCode.Should().Be(ExitCodes.Success);
}
}
public class GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter : SdkTest
{
private const string TestApplicationArgsPattern = @".*(Test application arguments).*";

public GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter(ITestOutputHelper log) : base(log)
{
}

[InlineData(TestingConstants.Debug)]
[InlineData(TestingConstants.Release)]
[Theory]
public void RunTestProjectWithFilterOfDll_ShouldReturnZeroAsExitCode(string configuration)
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString())
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

var binDirectory = new FileInfo($"{testInstance.Path}{Path.DirectorySeparatorChar}bin").Directory;
var binDirectoryLastWriteTime = binDirectory?.LastWriteTime;

CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.WithEnableTestingPlatform()
.Execute(TestingPlatformOptions.TestModulesFilterOption.Name, "**/bin/**/Debug/net8.0/TestProject.dll".Replace('/', Path.DirectorySeparatorChar),
TestingPlatformOptions.ConfigurationOption.Name, configuration);

// Assert that the bin folder hasn't been modified
Assert.Equal(binDirectoryLastWriteTime, binDirectory?.LastWriteTime);

if (!TestContext.IsLocalized())
{
result.StdOut
.Should().Contain("Test run summary: Passed!")
.And.Contain("total: 2")
.And.Contain("succeeded: 1")
.And.Contain("failed: 0")
.And.Contain("skipped: 1");
}

result.ExitCode.Should().Be(ExitCodes.Success);
}

[InlineData(TestingConstants.Debug)]
[InlineData(TestingConstants.Release)]
[Theory]
public void RunTestProjectWithFilterOfDllWithRootDirectory_ShouldReturnZeroAsExitCode(string configuration)
{
TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithTests", Guid.NewGuid().ToString())
.WithSource();

new BuildCommand(testInstance)
.Execute()
.Should().Pass();

CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
.WithWorkingDirectory(testInstance.Path)
.WithEnableTestingPlatform()
.WithTraceOutput()
.Execute(TestingPlatformOptions.TestModulesFilterOption.Name, "**/bin/**/Debug/net8.0/TestProject.dll".Replace('/', Path.DirectorySeparatorChar),
TestingPlatformOptions.TestModulesRootDirectoryOption.Name, testInstance.TestRoot,
TestingPlatformOptions.ConfigurationOption.Name, configuration);


var testAppArgs = Regex.Matches(result.StdOut!, TestApplicationArgsPattern);
Assert.Contains(RegexPatternHelper.GenerateProjectRegexPattern("TestProject", true, configuration, "exec", addVersionAndArchPattern: false), testAppArgs.FirstOrDefault()?.Value);

if (!TestContext.IsLocalized())
{
result.StdOut
.Should().Contain("Test run summary: Passed!")
.And.Contain("total: 2")
.And.Contain("succeeded: 1")
.And.Contain("failed: 0")
.And.Contain("skipped: 1");
}

result.ExitCode.Should().Be(ExitCodes.Success);
}
}
}
1 change: 0 additions & 1 deletion test/dotnet.Tests/dotnet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<Compile Include="..\Microsoft.DotNet.Configurer.UnitTests\**\*.cs" LinkBase="Configurer" />
<Compile Include="..\Microsoft.DotNet.ShellShim.Tests\**\*.cs" LinkBase="ShellShim" />
<Compile Remove="..\dotnet-test.Tests\GivenDotnetTestBuildsAndRunsHelp.cs" />
<Compile Remove="..\dotnet-test.Tests\GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter.cs" />

<None Include="..\Microsoft.DotNet.ShellShim.Tests\WpfBinaryTestAsssets\testwpf.dll" LinkBase="WpfBinaryTestAsssets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Loading