From 61ab709a39f1eb1db255a67e7d582ce65e122870 Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 21 Dec 2023 19:00:21 +0100 Subject: [PATCH 1/5] fix removal of first character in output filename --- src/Fantomas/Program.fs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Fantomas/Program.fs b/src/Fantomas/Program.fs index f359270817..239158df97 100644 --- a/src/Fantomas/Program.fs +++ b/src/Fantomas/Program.fs @@ -321,12 +321,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 From 896643485054e74d1d62171d50fe4de4c8fdd887 Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 21 Dec 2023 19:02:28 +0100 Subject: [PATCH 2/5] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15e388ab33..bf32938c18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed * 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 removal of first character in output file name. [#3025](https://github.com/fsprojects/fantomas/pull/3025) ## 6.3.0-alpha-004 - 2023-12-06 From f609fd7573bf4f4378da60c313b6c40652a28e83 Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 21 Dec 2023 23:26:19 +0100 Subject: [PATCH 3/5] add tests --- src/Fantomas.Tests/Integration/WriteTests.fs | 31 ++++++++++++++++++++ src/Fantomas.Tests/TestHelpers.fs | 10 +++++++ 2 files changed, 41 insertions(+) diff --git a/src/Fantomas.Tests/Integration/WriteTests.fs b/src/Fantomas.Tests/Integration/WriteTests.fs index 7746b1f03e..4373a1bea6 100644 --- a/src/Fantomas.Tests/Integration/WriteTests.fs +++ b/src/Fantomas.Tests/Integration/WriteTests.fs @@ -42,3 +42,34 @@ let ``incorrectly formatted file should be written`` () = exitCode |> should equal 0 output |> should contain "has been written" + +[] +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 System.IO.Path.DirectorySeparatorChar outputFolder.Foldername + + let { ExitCode = exitCode; Output = output } = runFantomasTool arguments + + exitCode |> should equal 0 + let outputFilePath = System.IO.Path.Combine(outputFolder.Foldername, "A.fs") + output |> should contain outputFilePath + +[] +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 = System.IO.Path.Combine(outputFolder.Foldername, "A.fs") + output |> should contain outputFilePath diff --git a/src/Fantomas.Tests/TestHelpers.fs b/src/Fantomas.Tests/TestHelpers.fs index 64642f0635..ad7f536ecb 100644 --- a/src/Fantomas.Tests/TestHelpers.fs +++ b/src/Fantomas.Tests/TestHelpers.fs @@ -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") From c4802005d7ea5b9f2cbe8a89768b6e23a74b5720 Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 21 Dec 2023 23:47:03 +0100 Subject: [PATCH 4/5] cleanup --- src/Fantomas.Tests/Integration/WriteTests.fs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Fantomas.Tests/Integration/WriteTests.fs b/src/Fantomas.Tests/Integration/WriteTests.fs index 4373a1bea6..d09da02422 100644 --- a/src/Fantomas.Tests/Integration/WriteTests.fs +++ b/src/Fantomas.Tests/Integration/WriteTests.fs @@ -1,5 +1,6 @@ module Fantomas.Tests.Integration.WriteTests +open System.IO open NUnit.Framework open FsUnit open Fantomas.Tests.TestHelpers @@ -51,12 +52,12 @@ let ``file should be written to out folder when input folder has trailing slash` use outputFolder = new OutputFolder() let arguments = - sprintf @"%s subsrc%c --out %s" Verbosity System.IO.Path.DirectorySeparatorChar outputFolder.Foldername + sprintf @"%s subsrc%c --out %s" Verbosity Path.DirectorySeparatorChar outputFolder.Foldername let { ExitCode = exitCode; Output = output } = runFantomasTool arguments exitCode |> should equal 0 - let outputFilePath = System.IO.Path.Combine(outputFolder.Foldername, "A.fs") + let outputFilePath = Path.Combine(outputFolder.Foldername, "A.fs") output |> should contain outputFilePath [] @@ -71,5 +72,5 @@ let ``file should be written to out folder when input folder has no trailing sla let { ExitCode = exitCode; Output = output } = runFantomasTool arguments exitCode |> should equal 0 - let outputFilePath = System.IO.Path.Combine(outputFolder.Foldername, "A.fs") + let outputFilePath = Path.Combine(outputFolder.Foldername, "A.fs") output |> should contain outputFilePath From cb75d633d897bb17710679d2b16588925d1c437d Mon Sep 17 00:00:00 2001 From: dawe Date: Fri, 22 Dec 2023 10:37:25 +0100 Subject: [PATCH 5/5] Switch changelog to 6.3.0-alpha-005 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7580a7c150..88857aa072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)