Skip to content

Commit

Permalink
Ensure we print nice bad path message (#510)
Browse files Browse the repository at this point in the history
* Ensure we print nice bad path message

closes #506

* Formatting
  • Loading branch information
belav authored Dec 6, 2021
1 parent f38e2e7 commit 1a3076c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Src/CSharpier.Cli.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ public async Task Should_Format_Piped_File(string lineEnding)
result.ExitCode.Should().Be(0);
}

[Test]
public async Task Should_Print_NotFound()
{
var result = await new CsharpierProcess().WithArguments("/BasicFile.cs").ExecuteAsync();

result.Output.Should().BeEmpty();
result.ErrorOutput
.Should()
.StartWith("There was no file or directory found at /BasicFile.cs");
result.ExitCode.Should().Be(1);
}

[Test]
public async Task Should_Write_To_StdError_For_Piped_Invalid_File()
{
Expand Down
9 changes: 8 additions & 1 deletion Src/CSharpier.Cli/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ await FormatPhysicalFile(
{
await FormatFile(directoryOrFile);
}
else
else if (fileSystem.Directory.Exists(directoryOrFile))
{
var tasks = fileSystem.Directory
.EnumerateFiles(directoryOrFile, "*.cs", SearchOption.AllDirectories)
Expand All @@ -110,6 +110,13 @@ await FormatPhysicalFile(
}
}
}
else
{
console.WriteErrorLine(
"There was no file or directory found at " + directoryOrFile
);
return 1;
}
}
}

Expand Down

0 comments on commit 1a3076c

Please sign in to comment.