Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<AwesomeAssertionsJsonVersion>8.0.0</AwesomeAssertionsJsonVersion>
<MoqPackageVersion>4.18.4</MoqPackageVersion>
<XunitCombinatorialVersion>1.3.2</XunitCombinatorialVersion>
<XUnitRunnerVisualStudioPackageVersion>3.1.4</XUnitRunnerVisualStudioPackageVersion>
<MicrosoftDotNetInstallerWindowsSecurityTestDataPackageVersion>8.0.0-beta.23607.1</MicrosoftDotNetInstallerWindowsSecurityTestDataPackageVersion>
<BenchmarkDotNetPackageVersion>0.14.0</BenchmarkDotNetPackageVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Commands;
using Microsoft.DotNet.Cli.Commands.Build;
using Microsoft.DotNet.Cli.Commands.MSBuild;
using Microsoft.DotNet.Cli.Commands.Test;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -116,10 +117,14 @@ internal sealed class CommandLineOptions
out var binLogToken,
out var binLogPath);

// We assume that forwarded options, if any, are intended for dotnet build.
// We assume that forwarded options, if any, are intended for `dotnet build`.
// Exclude --target option since we need to control the targets being built.
var msbuildCommandDefinition = new MSBuildCommandDefinition();

var buildArguments = buildOptions
.Select(option => option.ForwardingFunction!(parseResult))
.SelectMany(args => args)
.Where(arg => !msbuildCommandDefinition.Parse(arg).HasOption(msbuildCommandDefinition.TargetOption))
.ToList();

if (binLogToken != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
<_Parameter1>MicrosoftExtensionsServiceDiscoveryPackageVersion</_Parameter1>
<_Parameter2>$(MicrosoftExtensionsServiceDiscoveryPackageVersion)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>MicrosoftNETTestSdkPackageVersion</_Parameter1>
<_Parameter2>$(MicrosoftNETTestSdkPackageVersion)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>XUnitPackageVersion</_Parameter1>
<_Parameter2>$(XUnitVersion)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>XUnitRunnerVisualStudioPackageVersion</_Parameter1>
<_Parameter2>$(XUnitRunnerVisualStudioPackageVersion)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions test/TestAssets/TestProjects/WatchXUnit/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Xunit;

namespace XUnitTestProject1
{
public class UnitTest1
{
[Fact]
public void Test1()
{

}
}
}
13 changes: 13 additions & 0 deletions test/TestAssets/TestProjects/WatchXUnit/WatchXUnit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
<PackageReference Include="xunit" Version="$(XUnitPackageVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioPackageVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,10 @@ public void ForwardedOptionsAndArguments_Test(string[] args, string[] buildArgs,
var runOptions = VerifyOptions(["test", .. args]);

var isShortProperty = args[0].Contains("-p") || args[0].Contains("/p");
string[] expectedBuildArgs = isShortProperty
? ["--property:VSTestNoLogo=true", "--property:NuGetInteractive=false", .. buildArgs, "--target:VSTest"]
: ["--property:VSTestNoLogo=true", "--property:NuGetInteractive=false", "--target:VSTest", .. buildArgs];

// `test` subcommand forwards "--target:VSTest" to build, but BuildArguments are used to invoke
// `dotnet build` and design-time build and should not specify build targets:
string[] expectedBuildArgs = ["--property:VSTestNoLogo=true", "--property:NuGetInteractive=false", .. buildArgs];
AssertEx.SequenceEqual(expectedBuildArgs, runOptions.BuildArguments);

AssertEx.SequenceEqual(commandArgs ?? [], runOptions.CommandArguments);
Expand Down
45 changes: 45 additions & 0 deletions test/dotnet-watch.Tests/Watch/FileUpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,49 @@ public async Task RestartProcessThatTerminatesAfterFileChange()
Assert.NotEqual(processIdentifier, processIdentifier2);
await App.WaitUntilOutputContains("Exiting"); // process should exit after run
}

/// <summary>
/// Validates `dotnet watch test` scenario: https://github.com/dotnet/sdk/issues/52528
/// </summary>
[Fact]
public async Task TestCommand()
{
var testAsset = TestAssets.CopyTestAsset("WatchXUnit")
.WithSource();

var testFile = Path.Combine(testAsset.Path, "UnitTest1.cs");
File.WriteAllText(testFile, """
using Xunit;

public class UnitTest1
{
[Fact]
public void Test1()
{
Assert.True(false);
}
}
""");

App.Start(testAsset, ["test"]);

await App.WaitUntilOutputContains(MessageDescriptor.WaitingForChanges);
await App.WaitUntilOutputContains("Failed!");
App.Process.ClearOutput();

UpdateSourceFile(testFile, """
using Xunit;

public class UnitTest1
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}
""");

await App.WaitUntilOutputContains("Passed!");
}
}
Loading