dotnet-installer/src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/DotNetFormatTests.cs

46 lines
1.7 KiB
C#
Raw Normal View History

// 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.IO;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
2023-10-12 15:50:19 -05:00
public class DotNetFormatTests : SdkTests
{
private const string TestFileName = "FormatTest.cs";
private const string UnformattedFileName = "FormatTestUnformatted.cs";
private const string ExpectedFormattedFileName = "FormatTestFormatted.cs";
public DotNetFormatTests(ITestOutputHelper outputHelper) : base(outputHelper) { }
/// <Summary>
/// Format an unformatted project and verify that the output matches the pre-computed solution.
/// </Summary>
2023-10-24 15:45:25 -05:00
// https://github.com/dotnet/source-build/issues/3668
// [Fact]
public void FormatProject()
{
if (Config.TargetRid.Contains("alpine"))
{
// Skipping this test on Alpine due to https://github.com/dotnet/format/issues/1945
return;
}
string unformattedCsFilePath = Path.Combine(BaselineHelper.GetAssetsDirectory(), UnformattedFileName);
string projectDirectory = DotNetHelper.ExecuteNew("console", nameof(FormatProject), "C#");
string projectFilePath = Path.Combine(projectDirectory, nameof(FormatProject) + ".csproj");
string testFilePath = Path.Combine(projectDirectory, TestFileName);
File.Copy(unformattedCsFilePath, testFilePath);
DotNetHelper.ExecuteCmd($"format {projectFilePath}");
BaselineHelper.CompareFiles(BaselineHelper.GetBaselineFilePath(ExpectedFormattedFileName), testFilePath, OutputHelper);
}
}