Skip to content

Commit

Permalink
Refactoring (#507)
Browse files Browse the repository at this point in the history
* WIP refactoring

* Self code review

* Updates

* More cleanup

* Fixing some tests

* More fixes

* formatting
  • Loading branch information
belav authored Dec 6, 2021
1 parent a32bab4 commit 6c0ea70
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 307 deletions.
3 changes: 2 additions & 1 deletion Scripts/RunLinuxTests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# running this seems to screw up the nuget restore, but provides a way to figure out why a test is failing on linux while working on windows.
# you have to run this from the root, IE powershell ./Scripts/RunLinuxTests.ps1
docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app/tests mcr.microsoft.com/dotnet/sdk:5.0 dotnet test /app/Src/CSharpier.Tests/CSharpier.Tests.csproj --logger:trx
# also a lot of these tests fail due to line endings in your local files being \r\n but the writeLine using \n
docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app/tests mcr.microsoft.com/dotnet/sdk:6.0 dotnet test /app/Src/CSharpier.Tests/CSharpier.Tests.csproj --logger:trx

# gross way to run csharpier against the csharpier-repos
#docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app mcr.microsoft.com/dotnet/sdk:5.0 dotnet ./csharpier/Src/CSharpier/bin/Debug/net6.0/dotnet-csharpier.dll csharpier-repos --skip-write
28 changes: 18 additions & 10 deletions Src/CSharpier.Cli.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ public async Task With_Check_Should_Write_Unformatted_File()
.WithArguments("CheckUnformatted.cs --check")
.ExecuteAsync();

result.Output.Should().StartWith("Warning /CheckUnformatted.cs - Was not formatted.");
result.Output
.Replace("\\", "/")
.Should()
.StartWith("Warning /CheckUnformatted.cs - Was not formatted.");
result.ExitCode.Should().Be(1);
}

Expand Down Expand Up @@ -166,7 +169,7 @@ public async Task Should_Write_Error_With_Multiple_Piped_Files()
result.ErrorOutput
.Should()
.Be(
$"Error {Path.DirectorySeparatorChar}InvalidFile.cs - Failed to compile so was not formatted.{Environment.NewLine}"
$"Error /InvalidFile.cs - Failed to compile so was not formatted.{Environment.NewLine}"
);
result.ExitCode.Should().Be(1);
}
Expand Down Expand Up @@ -200,14 +203,19 @@ public async Task Should_Support_Config_With_Multiple_Piped_Files()
.ExecuteAsync();

result.ErrorOutput.Should().BeEmpty();
result.Output
.TrimEnd('\u0003')
.Should()
.Be(
@"var myVariable =
someLongValue;
"
);
result.Output.TrimEnd('\u0003').Should().Be("var myVariable =\n someLongValue;\n");
}

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

var result = await new CsharpierProcess().WithArguments(".").ExecuteAsync();

result.Output.Should().StartWith("Total time:");
result.ErrorOutput.Should().BeEmpty();
result.ExitCode.Should().Be(0);
}

private async Task WriteFileAsync(string path, string content)
Expand Down
Loading

0 comments on commit 6c0ea70

Please sign in to comment.