2022-02-18 06:51:43 -08:00
|
|
|
// 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;
|
|
|
|
|
2022-03-03 08:02:48 -06:00
|
|
|
public class DotNetFormatTests : SmokeTests
|
2022-02-18 06:51:43 -08:00
|
|
|
{
|
2022-03-31 19:12:59 -05:00
|
|
|
private const string TestFileName = "FormatTest.cs";
|
2022-02-18 06:51:43 -08:00
|
|
|
private const string UnformattedFileName = "FormatTestUnformatted.cs";
|
2022-03-31 19:12:59 -05:00
|
|
|
private const string ExpectedFormattedFileName = "FormatTestFormatted.cs";
|
2022-02-18 06:51:43 -08:00
|
|
|
|
2022-03-03 08:02:48 -06:00
|
|
|
public DotNetFormatTests(ITestOutputHelper outputHelper) : base(outputHelper) { }
|
2022-02-18 06:51:43 -08:00
|
|
|
|
|
|
|
/// <Summary>
|
|
|
|
/// Format an unformatted project and verify that the output matches the pre-computed solution.
|
|
|
|
/// </Summary>
|
2023-08-28 10:20:35 -07:00
|
|
|
[Fact]
|
2022-02-18 06:51:43 -08:00
|
|
|
public void FormatProject()
|
|
|
|
{
|
2023-08-28 10:20:35 -07:00
|
|
|
if (Config.TargetRid.Contains("alpine"))
|
|
|
|
{
|
|
|
|
// Skipping this test on Alpine due to https://github.com/dotnet/format/issues/1945
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:12:59 -05:00
|
|
|
string unformattedCsFilePath = Path.Combine(BaselineHelper.GetAssetsDirectory(), UnformattedFileName);
|
2022-02-18 06:51:43 -08:00
|
|
|
|
2022-03-03 08:02:48 -06:00
|
|
|
string projectDirectory = DotNetHelper.ExecuteNew("console", nameof(FormatProject), "C#");
|
2022-02-18 06:51:43 -08:00
|
|
|
|
|
|
|
string projectFilePath = Path.Combine(projectDirectory, nameof(FormatProject) + ".csproj");
|
2022-03-31 19:12:59 -05:00
|
|
|
string testFilePath = Path.Combine(projectDirectory, TestFileName);
|
2022-02-18 06:51:43 -08:00
|
|
|
|
2022-03-31 19:12:59 -05:00
|
|
|
File.Copy(unformattedCsFilePath, testFilePath);
|
2022-02-18 06:51:43 -08:00
|
|
|
|
2022-03-03 08:02:48 -06:00
|
|
|
DotNetHelper.ExecuteCmd($"format {projectFilePath}");
|
2022-02-18 06:51:43 -08:00
|
|
|
|
2023-07-28 09:48:27 -05:00
|
|
|
BaselineHelper.CompareFiles(BaselineHelper.GetBaselineFilePath(ExpectedFormattedFileName), testFilePath, OutputHelper);
|
2022-02-18 06:51:43 -08:00
|
|
|
}
|
|
|
|
}
|