Skip to content

Commit

Permalink
Updating CommandLine + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Jan 1, 2025
1 parent af9571f commit 08a7d64
Show file tree
Hide file tree
Showing 12 changed files with 375 additions and 417 deletions.
1 change: 1 addition & 0 deletions CSharpier.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Concated/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=csharpier/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=csharpierignore/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Scriban" Version="5.10.0" />
<PackageVersion Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.IO.Abstractions" Version="21.0.29" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="21.0.29" />
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
Expand Down
71 changes: 44 additions & 27 deletions Src/CSharpier.Cli.Tests/CliTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CliWrap;
using CliWrap.Buffered;
Expand Down Expand Up @@ -52,7 +50,7 @@ void DeleteDirectory()

[TestCase("\n")]
[TestCase("\r\n")]
public async Task Should_Format_Basic_File(string lineEnding)
public async Task Format_Should_Format_Basic_File(string lineEnding)
{
var formattedContent = "public class ClassName { }" + lineEnding;
var unformattedContent = $"public class ClassName {{{lineEnding}{lineEnding}}}";
Expand All @@ -71,7 +69,7 @@ public async Task Should_Format_Basic_File(string lineEnding)

[TestCase("Subdirectory")]
[TestCase("./Subdirectory")]
public async Task Should_Format_Subdirectory(string subdirectory)
public async Task Format_Should_Format_Subdirectory(string subdirectory)
{
var formattedContent = "public class ClassName { }\n";
var unformattedContent = "public class ClassName {\n\n}";
Expand All @@ -88,7 +86,7 @@ public async Task Should_Format_Subdirectory(string subdirectory)
}

[Test]
public async Task Should_Respect_Ignore_File_With_Subdirectory_When_DirectorOrFile_Is_Dot()
public async Task Format_Should_Respect_Ignore_File_With_Subdirectory_When_DirectorOrFile_Is_Dot()
{
var unformattedContent = "public class Unformatted { }";
var filePath = "Subdirectory/IgnoredFile.cs";
Expand All @@ -105,7 +103,7 @@ public async Task Should_Respect_Ignore_File_With_Subdirectory_When_DirectorOrFi
}

[Test]
public async Task Should_Support_Config_Path()
public async Task Format_Should_Support_Config_Path()
{
const string fileContent = "var myVariable = someLongValue;";
var fileName = "TooWide.cs";
Expand All @@ -122,7 +120,23 @@ public async Task Should_Support_Config_Path()
}

[Test]
public async Task Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_StdIn()
public async Task Check_Should_Support_Config_Path()
{
const string fileContent = "var myVariable = someLongValue;\n";
var fileName = "TooWide.cs";
await this.WriteFileAsync(fileName, fileContent);
await this.WriteFileAsync("config/.csharpierrc", "printWidth: 10");

var result = await new CsharpierProcess()
.WithArguments("check --config-path config/.csharpierrc . ")
.ExecuteAsync();

result.ExitCode.Should().Be(1);
result.ErrorOutput.Should().StartWith("Error ./TooWide.cs - Was not formatted.");
}

[Test]
public async Task Format_Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_StdIn()
{
if (CannotRunTestWithRedirectedInput())
{
Expand All @@ -139,7 +153,7 @@ public async Task Should_Return_Error_When_No_DirectoryOrFile_And_Not_Piping_Std

[TestCase("\n")]
[TestCase("\r\n")]
public async Task Should_Format_Piped_File(string lineEnding)
public async Task Format_Should_Format_Piped_File(string lineEnding)
{
var formattedContent1 = "public class ClassName1 { }" + lineEnding;
var unformattedContent1 = $"public class ClassName1 {{{lineEnding}{lineEnding}}}";
Expand All @@ -154,7 +168,7 @@ public async Task Should_Format_Piped_File(string lineEnding)
}

[Test]
public async Task Should_Format_Piped_File_With_Config()
public async Task Format_Should_Format_Piped_File_With_Config()
{
await this.WriteFileAsync(".csharpierrc", "printWidth: 10");

Expand All @@ -171,7 +185,7 @@ public async Task Should_Format_Piped_File_With_Config()
}

[Test]
public async Task Should_Format_Piped_File_With_EditorConfig()
public async Task Format_Should_Format_Piped_File_With_EditorConfig()
{
await this.WriteFileAsync(
".editorconfig",
Expand All @@ -192,7 +206,7 @@ await this.WriteFileAsync(
}

[Test]
public async Task Should_Format_Unicode()
public async Task Format_Should_Handle_Unicode()
{
// use the \u so that we don't accidentally reformat this to be '?'
var unicodeContent = $"var test = '{'\u3002'}';\n";
Expand All @@ -210,7 +224,7 @@ public async Task Should_Format_Unicode()
[TestCase("BasicFile.cs")]
[TestCase("./BasicFile.cs")]
[TestCase("/BasicFile.cs")]
public async Task Should_Print_NotFound(string path)
public async Task Format_Print_NotFound(string path)
{
var result = await new CsharpierProcess().WithArguments($"format {path}").ExecuteAsync();

Expand All @@ -220,7 +234,7 @@ public async Task Should_Print_NotFound(string path)
}

[Test]
public async Task Should_Write_To_StdError_For_Piped_Invalid_File()
public async Task Format_Should_Write_To_StdError_For_Piped_Invalid_File()
{
const string invalidFile = "public class ClassName { ";

Expand All @@ -235,7 +249,7 @@ public async Task Should_Write_To_StdError_For_Piped_Invalid_File()
}

[Test]
public async Task With_Check_Should_Write_Unformatted_File()
public async Task Check_Should_Write_Unformatted_File()
{
var unformattedContent = "public class ClassName1 {\n\n}";

Expand All @@ -255,7 +269,7 @@ public async Task With_Check_Should_Write_Unformatted_File()
// TODO overrides tests for piping files
[TestCase("\n")]
[TestCase("\r\n")]
public async Task Should_Format_Multiple_Piped_Files(string lineEnding)
public async Task PipeFiles_Should_Format_Multiple_Piped_Files(string lineEnding)
{
var formattedContent1 = "public class ClassName1 { }" + lineEnding;
var formattedContent2 = "public class ClassName2 { }" + lineEnding;
Expand All @@ -280,7 +294,10 @@ public async Task Should_Format_Multiple_Piped_Files(string lineEnding)

[TestCase("InvalidFile.cs", "./InvalidFile.cs")]
[TestCase("./InvalidFile.cs", "./InvalidFile.cs")]
public async Task Should_Write_Error_With_Multiple_Piped_Files(string input, string output)
public async Task PipeFiles_Should_Write_Error_With_Multiple_Piped_Files(
string input,
string output
)
{
const string invalidFile = "public class ClassName { ";

Expand All @@ -298,7 +315,7 @@ public async Task Should_Write_Error_With_Multiple_Piped_Files(string input, str
}

[Test]
public async Task Should_Ignore_Piped_File_With_Multiple_Piped_Files()
public async Task PipeFiles_Should_Ignore_Piped_File_With_Multiple_Piped_Files()
{
const string ignoredFile = "public class ClassName { }";
var fileName = Path.Combine(testFileDirectory, "Ignored.cs");
Expand All @@ -314,7 +331,7 @@ public async Task Should_Ignore_Piped_File_With_Multiple_Piped_Files()
}

[Test]
public async Task Should_Support_Config_With_Multiple_Piped_Files()
public async Task PipeFiles_Should_Support_Config_With_Multiple_Piped_Files()
{
const string fileContent = "var myVariable = someLongValue;";
var fileName = Path.Combine(testFileDirectory, "TooWide.cs");
Expand All @@ -330,7 +347,7 @@ public async Task Should_Support_Config_With_Multiple_Piped_Files()
}

[Test]
public async Task Should_Support_Override_Config_With_Multiple_Piped_Files()
public async Task PipeFiles_Should_Support_Override_Config_With_Multiple_Piped_Files()
{
const string fileContent = "var myVariable = someLongValue;";
var fileName = Path.Combine(testFileDirectory, "TooWide.cst");
Expand All @@ -354,7 +371,7 @@ await this.WriteFileAsync(
}

[Test]
public async Task Should_Not_Fail_On_Empty_File()
public async Task Format_Should_Not_Fail_On_Empty_File()
{
await this.WriteFileAsync("BasicFile.cs", "");

Expand All @@ -366,7 +383,7 @@ public async Task Should_Not_Fail_On_Empty_File()
}

[Test]
public async Task Should_Not_Fail_On_Bad_Csproj()
public async Task Format_Should_Not_Fail_On_Bad_Csproj()
{
await this.WriteFileAsync("Empty.csproj", "");

Expand All @@ -378,7 +395,7 @@ public async Task Should_Not_Fail_On_Bad_Csproj()
}

[Test]
public async Task Should_Not_Fail_On_Mismatched_MSBuild_With_No_Check()
public async Task Format_Should_Not_Fail_On_Mismatched_MSBuild_With_No_Check()
{
await this.WriteFileAsync(
"Test.csproj",
Expand All @@ -399,7 +416,7 @@ await this.WriteFileAsync(
}

[Test]
public async Task Should_Fail_On_Mismatched_MSBuild()
public async Task Format_Should_Fail_On_Mismatched_MSBuild()
{
await this.WriteFileAsync(
"Test.csproj",
Expand All @@ -419,7 +436,7 @@ await this.WriteFileAsync(
}

[Test]
public async Task Should_Cache_And_Validate_Too_Many_Things()
public async Task Format_Should_Cache_And_Validate_Too_Many_Things()
{
var unformattedContent = "public class ClassName { }\n";
var formattedContent = "public class ClassName { }\n";
Expand All @@ -442,7 +459,7 @@ public async Task Should_Cache_And_Validate_Too_Many_Things()
}

[Test]
public async Task Should_Reformat_When_Options_Change_With_Cache()
public async Task Format_Should_Reformat_When_Options_Change_With_Cache()
{
var unformattedContent = "public class ClassName { \n// break\n }\n";

Expand All @@ -456,7 +473,7 @@ public async Task Should_Reformat_When_Options_Change_With_Cache()
}

[Test]
public void Should_Handle_Concurrent_Processes()
public void Format_Should_Handle_Concurrent_Processes()
{
var unformattedContent = "public class ClassName { }\n";
var totalFolders = 10;
Expand Down Expand Up @@ -494,7 +511,7 @@ async Task FormatFolder(string folder)
[Ignore(
"This is somewhat useful for testing locally, but doesn't reliably reproduce a problem and takes a while to run. Commenting out the delete cache file line helps to reproduce problems"
)]
public async Task Should_Handle_Concurrent_Processes_2()
public async Task Format_Should_Handle_Concurrent_Processes_2()
{
var unformattedContent = "public class ClassName { }\n";
var filesPerFolder = 1000;
Expand Down
Loading

0 comments on commit 08a7d64

Please sign in to comment.