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
|
|
|
{
|
|
|
|
private const string UnformattedFileName = "FormatTestUnformatted.cs";
|
|
|
|
private const string ExpectedFormattedFileName = "FormatTestExpectedFormatted.cs";
|
|
|
|
|
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>
|
|
|
|
[Fact]
|
|
|
|
public void FormatProject()
|
|
|
|
{
|
|
|
|
string assetsDirectory = BaselineHelper.GetAssetsDirectory();
|
|
|
|
|
|
|
|
string unformattedCsFilePath = Path.Combine(assetsDirectory, UnformattedFileName);
|
|
|
|
string expectedFormattedCsFilePath = Path.Combine(assetsDirectory, ExpectedFormattedFileName);
|
|
|
|
|
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");
|
|
|
|
string formattedCsFilePath = Path.Combine(projectDirectory, UnformattedFileName);
|
|
|
|
|
|
|
|
File.Copy(unformattedCsFilePath, formattedCsFilePath);
|
|
|
|
|
2022-03-03 08:02:48 -06:00
|
|
|
DotNetHelper.ExecuteCmd($"format {projectFilePath}");
|
2022-02-18 06:51:43 -08:00
|
|
|
|
|
|
|
BaselineHelper.CompareFiles(expectedFormattedCsFilePath, formattedCsFilePath, OutputHelper);
|
|
|
|
}
|
|
|
|
}
|