Skip to content

Commit

Permalink
Merge pull request #3025 from dawedawe/fix_output_filename
Browse files Browse the repository at this point in the history
Fix output filename
  • Loading branch information
dawedawe authored Dec 22, 2023
2 parents c43224d + cb75d63 commit fc341e8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## 6.3.0-alpha-005 - 2023-12-22

### Changed
* Turn on strict indentation in the lexer in Fantomas.FCS. [#3014](https://github.com/fsprojects/fantomas/pull/3014)
Expand All @@ -9,6 +9,7 @@
* Unmatched '{' error when formatting the code. [#3017](https://github.com/fsprojects/fantomas/issues/3017)
* Comment lost after named pat pair. [#2953](https://github.com/fsprojects/fantomas/issues/2953)
* Fix accidental treatment of old flags as folder args. [#2854](https://github.com/fsprojects/fantomas/issues/2854)
* Fix removal of first character in output file name. [#3025](https://github.com/fsprojects/fantomas/pull/3025)

## 6.3.0-alpha-004 - 2023-12-06

Expand Down
32 changes: 32 additions & 0 deletions src/Fantomas.Tests/Integration/WriteTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Fantomas.Tests.Integration.WriteTests

open System.IO
open NUnit.Framework
open FsUnit
open Fantomas.Tests.TestHelpers
Expand Down Expand Up @@ -42,3 +43,34 @@ let ``incorrectly formatted file should be written`` () =
exitCode |> should equal 0

output |> should contain "has been written"

[<Test>]
let ``file should be written to out folder when input folder has trailing slash`` () =
use fileFixtureOne =
new TemporaryFileCodeSample(FormattedCode, fileName = "A", subFolder = "subsrc")

use outputFolder = new OutputFolder()

let arguments =
sprintf @"%s subsrc%c --out %s" Verbosity Path.DirectorySeparatorChar outputFolder.Foldername

let { ExitCode = exitCode; Output = output } = runFantomasTool arguments

exitCode |> should equal 0
let outputFilePath = Path.Combine(outputFolder.Foldername, "A.fs")
output |> should contain outputFilePath

[<Test>]
let ``file should be written to out folder when input folder has no trailing slash`` () =
use fileFixtureOne =
new TemporaryFileCodeSample(FormattedCode, fileName = "A", subFolder = "subsrc")

use outputFolder = new OutputFolder()

let arguments = sprintf @"%s subsrc --out %s" Verbosity outputFolder.Foldername

let { ExitCode = exitCode; Output = output } = runFantomasTool arguments

exitCode |> should equal 0
let outputFilePath = Path.Combine(outputFolder.Foldername, "A.fs")
output |> should contain outputFilePath
10 changes: 10 additions & 0 deletions src/Fantomas.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ type OutputFile internal () =
if File.Exists(filename) then
File.Delete(filename)

type OutputFolder internal () =
let foldername = Path.Join(Path.GetTempPath(), Guid.NewGuid().ToString())

member _.Foldername: string = foldername

interface IDisposable with
member this.Dispose() : unit =
if Directory.Exists(foldername) then
Directory.Delete(foldername, true)

type ConfigurationFile internal (content: string) =
let filename = Path.Join(Path.GetTempPath(), ".editorconfig")

Expand Down
5 changes: 2 additions & 3 deletions src/Fantomas/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,11 @@ let main argv =
findAllFilesRecursively inputFolder
|> Seq.toList
|> List.map (fun i ->
// s supposes to have form s1/suffix
let suffix = i.Substring(inputFolder.Length + 1)

let o =
if inputFolder <> outputFolder then
Path.Combine(outputFolder, suffix)
let fileName = Path.GetFileName(i)
Path.Combine(outputFolder, fileName)
else
i

Expand Down

0 comments on commit fc341e8

Please sign in to comment.