Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing raise for formatting functions #1376

Merged
merged 3 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Fantomas.CoreGlobalTool.Tests/ExitCodeTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Fantomas.CoreGlobalTool.Tests.ExitCodeTests

open NUnit.Framework
open FsUnit
open Fantomas.CoreGlobalTool.Tests.TestHelpers

[<Literal>]
let WithErrors = """let a ="""

[<Test>]
let ``invalid files should report exit code 1`` () =
use fileFixture = new TemporaryFileCodeSample(WithErrors)
let (exitCode, _) = formatCode fileFixture.Filename
exitCode |> should equal 1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="ByteOrderMarkTests.fs" />
<Compile Include="ConfigTests.fs" />
<Compile Include="IgnoreFilesTests.fs" />
<Compile Include="ExitCodeTests.fs" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
4 changes: 4 additions & 0 deletions src/Fantomas.CoreGlobalTool.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@ let runFantomasTool arguments =
let checkCode file =
let arguments = sprintf "--check \"%s\"" file
runFantomasTool arguments

let formatCode file =
let arguments = sprintf "\"%s\"" file
runFantomasTool arguments
7 changes: 7 additions & 0 deletions src/Fantomas.CoreGlobalTool/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ let main argv =
File.WriteAllText(outFile, File.ReadAllText inFile)
printfn "Force writing original contents to %s" outFile

raise exn

let stringToFile (s: string) (outFile: string) config =
try
let fsi = Path.GetExtension(outFile) = ".fsi"
Expand All @@ -329,6 +331,8 @@ let main argv =
File.WriteAllText(outFile, s)
printfn "Force writing original contents to %s." outFile

raise exn

let stringToStdOut s config =
try
use buffer = new StringWriter() :> TextWriter
Expand All @@ -337,6 +341,7 @@ let main argv =
with exn ->
eprintfn "The following exception occurs while formatting stdin: %O" exn
if force then stdout.Write(s)
raise exn

let processFile inputFile outputFile =
if inputFile <> outputFile then
Expand Down Expand Up @@ -377,6 +382,8 @@ let main argv =
if force then
stdout.Write(File.ReadAllText inFile)

raise exn

if Option.isSome version then
let version = CodeFormatter.GetVersion()
printfn "Fantomas v%s" version
Expand Down