Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/nuget/xunit.runner.visualstudio-2…
Browse files Browse the repository at this point in the history
….5.6

Signed-off-by: Andy Gerlicher <angerlic@microsoft.com>
  • Loading branch information
AndyGerlicher committed Mar 5, 2024
2 parents f6cb21e + c3d862b commit 46d56cb
Show file tree
Hide file tree
Showing 20 changed files with 2,096 additions and 50 deletions.
8 changes: 5 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CopyOnWrite" Version="0.3.7" Condition=" '$(TargetFramework)' != 'net46' " />
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="System.CodeDom" Version="7.0.0" />
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="7.0.0" Condition=" '$(TargetFramework)' != 'net46' " />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="4.11.1" Condition=" '$(TargetFramework)' == 'net46' " />
</ItemGroup>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageVersion Include="AssemblyShader" Version="1.0.3-preview" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="MSBuild.ProjectCreation" Version="10.0.0" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="xunit" Version="2.6.0" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="6.0.6" Condition="'$(EnableArtifacts)' != 'false'" />
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="6.1.10" Condition="'$(EnableArtifacts)' != 'false'" />
<GlobalPackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="1.0.0" Condition="'$(EnableMicroBuild)' != 'false'" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" Condition="'$(EnableGitVersioning)' != 'false'" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions MSBuildSdks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.CopyOnWrite
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.CopyOnWrite.UnitTests", "src\CopyOnWrite.UnitTests\Microsoft.Build.CopyOnWrite.UnitTests.csproj", "{AF9F2AFE-04D4-40B3-B17F-54ABD3DE7E4E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.RunVSTest", "src\RunTests\Microsoft.Build.RunVSTest.csproj", "{B4CA4749-4CDE-499F-8372-C71966C6DB16}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -142,6 +144,10 @@ Global
{153D1183-2953-4D4D-A5AD-AA2CF99B0DE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{153D1183-2953-4D4D-A5AD-AA2CF99B0DE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{153D1183-2953-4D4D-A5AD-AA2CF99B0DE3}.Release|Any CPU.Build.0 = Release|Any CPU
{B4CA4749-4CDE-499F-8372-C71966C6DB16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4CA4749-4CDE-499F-8372-C71966C6DB16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4CA4749-4CDE-499F-8372-C71966C6DB16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4CA4749-4CDE-499F-8372-C71966C6DB16}.Release|Any CPU.Build.0 = Release|Any CPU
{AF9F2AFE-04D4-40B3-B17F-54ABD3DE7E4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF9F2AFE-04D4-40B3-B17F-54ABD3DE7E4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF9F2AFE-04D4-40B3-B17F-54ABD3DE7E4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"rollForward": "latestMinor"
},
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "3.7.0"
"Microsoft.Build.NoTargets": "3.7.56"
}
}
}
2 changes: 1 addition & 1 deletion src/Artifacts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ The following properties control artifacts staging:
| Property | Description | Default |
|-------------------------------------|-------------|---------|
| `EnableDefaultArtifacts` | Set this to `false` to disable the default staging of the `$(OutputPath)` to the artifacts directory.| `true` |
| `DefaultArtifactsSource` | The default path to use as a source for staging artifacts. | `$(OutputPath)` |
| `DefaultArtifactsSource` | The default path to use as a source for staging artifacts. | `$(OutputPath)` if `AppendTargetFrameworkToOutputPath` is not true, otherwise the parent of `$(OutputPath)` (behavior changed in version 2.0.20). If you need the old behavior, set `AppendTargetFrameworkToOutputPath` to true, or set the property value `<DefaultArtifactsSource>$(OutputPath)</DefaultArtifactsSource>`. |
| `ArtifactsPath` | The default path to use as a destination for staging artifacts | |
| `DefaultArtifactsFileMatch` | The default filter to use for staging artifacts | `*exe *dll *exe.config` |
| `DefaultArtifactsFileExclude` | The default file filter to exclude when staging artifacts | |
Expand Down
131 changes: 131 additions & 0 deletions src/CopyOnWrite.UnitTests/CopyUpToDateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Licensed under the MIT license.

using Microsoft.Build.Framework;
using Microsoft.Build.Tasks;
using Microsoft.Build.UnitTests.Common;
using Microsoft.Build.Utilities;
using System;
using System.IO;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Build.CopyOnWrite.UnitTests;

// These tests rely on Microsoft.Build.Framework which has only a net472 and current-framework target.
// Don't compile these tests for .NET versions in between as Microsoft.Build.Framework.dll will not be
// propagated to the output dir.
#if !NET6_0 && !NET7_0

public class CopyUpToDateTests : MSBuildSdkTestBase
{
// If the developer has specified this environment variable (also used in the base CoW library unit tests),
// also run tests under ReFS locally even if the current drive volume is NTFS.
private static readonly string? ReFsTestDriveRoot = Environment.GetEnvironmentVariable("CoW_Test_ReFS_Drive");

private readonly ITestOutputHelper _output;

public CopyUpToDateTests(ITestOutputHelper output)
{
_output = output;
}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void CopyFileMultipleTimes(bool skipUnchangedFiles, bool runUnderReFsIfAvailable)
{
if (runUnderReFsIfAvailable && ReFsTestDriveRoot is null)
{
return;
}

DisposableTempDirectory tempDir;
if (runUnderReFsIfAvailable)
{
_output.WriteLine($"Running ReFS test under {ReFsTestDriveRoot}");
tempDir = new DisposableTempDirectory(basePath: Path.Combine(ReFsTestDriveRoot!, "CoWTests"));
}
else
{
tempDir = new DisposableTempDirectory();
}

using (tempDir)
{
string file1Path = Path.Combine(tempDir.Path, "file1.txt");
File.WriteAllBytes(file1Path, new byte[] { 0x00, 0x01, 0x02 });
var originalFileInfo = new FileInfo(file1Path);
string destDir = Path.Combine(tempDir.Path, "dest");

var engine = new MockEngine(logToConsole: true);

Copy copy = CreateFreshCopyTask();

copy.Execute();
engine.MockLogger.AssertNoErrors();
engine.MockLogger.AssertNoWarnings();
var file1Info = new FileInfo(file1Path);
AssertExistenceAndEqualTimes();

// Update the original file with different contents at the same size, and reset its last write time to the original.
// This allows determining a rewritten file for skipUnchangedFiles=false.
File.WriteAllBytes(file1Path, new byte[] { 0x04, 0x05, 0x06 });
File.SetLastWriteTimeUtc(file1Path, originalFileInfo.LastWriteTimeUtc);

string destFilePath = Path.Combine(destDir, "file1.txt");

for (int i = 0; i < 2; i++)
{
copy = CreateFreshCopyTask();
copy.Execute();
engine.MockLogger.AssertNoErrors();
engine.MockLogger.AssertNoWarnings();

file1Info = new FileInfo(file1Path);
AssertExistenceAndEqualTimes();

byte[] contents = File.ReadAllBytes(destFilePath);
Assert.Equal(3, contents.Length);
if (skipUnchangedFiles)
{
Assert.Equal(0x00, contents[0]);
Assert.Equal(0x01, contents[1]);
Assert.Equal(0x02, contents[2]);
}
else
{
Assert.Equal(0x04, contents[0]);
Assert.Equal(0x05, contents[1]);
Assert.Equal(0x06, contents[2]);
}
}

void AssertExistenceAndEqualTimes()
{
Assert.True(file1Info.Exists);

// Copy or clone should uphold file time propagation semantics to ensure up-to-date checks work in the future.
Assert.Equal(originalFileInfo.CreationTimeUtc, file1Info.CreationTimeUtc);
Assert.Equal(originalFileInfo.LastWriteTimeUtc, file1Info.LastWriteTimeUtc);
}

Copy CreateFreshCopyTask()
{
return new Copy
{
BuildEngine = engine,
DestinationFolder = new TaskItem(destDir),
RetryDelayMilliseconds = 1,
SourceFiles = new ITaskItem[] { new TaskItem(file1Path) },
SkipUnchangedFiles = skipUnchangedFiles,
};
}
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CopyOnWrite" />
<PackageReference Include="Microsoft.Build.Tasks.Core" />
<PackageReference Include="Microsoft.Build.Framework" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Win32.Registry" />
<PackageReference Include="MSBuild.ProjectCreation" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Shouldly" />
<PackageReference Include="System.CodeDom" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
Expand Down

0 comments on commit 46d56cb

Please sign in to comment.