Skip to content

Commit

Permalink
add missing raise for formatting functions (#1376)
Browse files Browse the repository at this point in the history
* add missing raise for formatting functions

* add ExitCodeTests file to include test of cli formatting without check parameter

Co-authored-by: Florian Verdonck <florian.verdonck@outlook.com>
  • Loading branch information
btzo and nojaf committed Jan 22, 2021
1 parent ce5a755 commit 232a644
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
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

0 comments on commit 232a644

Please sign in to comment.