Skip to content

Commit

Permalink
use relative file path in CommandLineFormatter (#680)
Browse files Browse the repository at this point in the history
* use relative file path in CommandLineFormatter

This changes the format of the file name to add a leading "." so that
the path is a relative path instead of an absolute path.

Modern terminal programs allow control-clicking on paths to jump to a
file, so if this is a relative path, we can jump to the file. If it is
printed as an absolute path, this doesn't work.

* Test to cover subdirectory relative path

* Modifying logging to use relative or absolute path based on what is input to cli

* Fix warning

* Fixing another bug

Co-authored-by: Bela VanderVoort <[email protected]>
  • Loading branch information
dlech and belav authored Jun 13, 2022
1 parent a62195e commit a56a47a
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 160 deletions.
13 changes: 6 additions & 7 deletions Src/CSharpier.Cli.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public async Task With_Check_Should_Write_Unformatted_File()
result.Output
.Replace("\\", "/")
.Should()
.StartWith("Warning /CheckUnformatted.cs - Was not formatted.");
.StartWith("Warning ./CheckUnformatted.cs - Was not formatted.");
result.ExitCode.Should().Be(1);
}

Expand Down Expand Up @@ -203,21 +203,20 @@ public async Task Should_Format_Multiple_Piped_Files(string lineEnding)
results[1].Should().Be(formattedContent2);
}

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

var result = await new CsharpierProcess()
.WithArguments("--pipe-multiple-files")
.WithPipedInput($"InvalidFile.cs{'\u0003'}{invalidFile}{'\u0003'}")
.WithPipedInput($"{input}{'\u0003'}{invalidFile}{'\u0003'}")
.ExecuteAsync();

result.ErrorOutput
.Should()
.Be(
$"Error /InvalidFile.cs - Failed to compile so was not formatted.{Environment.NewLine}"
);
.Be($"Error {output} - Failed to compile so was not formatted.{Environment.NewLine}");
result.ExitCode.Should().Be(1);
}

Expand Down
Loading

0 comments on commit a56a47a

Please sign in to comment.