From d1ea73b8483b91bf745e64e6422e90ad98f60c97 Mon Sep 17 00:00:00 2001
From: Thomas Boby
Date: Thu, 24 Oct 2024 08:55:41 +0100
Subject: [PATCH] Apply formatting
---
src/Library.fs | 22 ++++++++-----
src/Log.fs | 11 ++-----
tests/IntegrationTests.fs | 11 ++++---
tests/UnitTests.fs | 67 ++++++++++++++++++++++++---------------
4 files changed, 63 insertions(+), 48 deletions(-)
diff --git a/src/Library.fs b/src/Library.fs
index 07c36a7..a48d7c6 100644
--- a/src/Library.fs
+++ b/src/Library.fs
@@ -32,7 +32,8 @@ type ChangelogExtensions =
(string section.Type,
section.ItemCollection
|> Seq.map _.MarkdownText
- |> String.concat Environment.NewLine))
+ |> String.concat Environment.NewLine)
+ )
[]
static member ToTaskItem(unreleased: ChangelogSectionUnreleased) =
@@ -51,9 +52,12 @@ type ChangelogExtensions =
| false, _ -> None
| true, version ->
Some
- {| version = version
- date = section.ToDateTime()
- collection = section.SubSectionCollection |})
+ {|
+ version = version
+ date = section.ToDateTime()
+ collection = section.SubSectionCollection
+ |}
+ )
[]
static member ToMarkdown(subsections: ChangelogSubSectionCollection) =
@@ -62,12 +66,13 @@ type ChangelogExtensions =
subsections
|> Seq.fold
(fun (builder: StringBuilder) subsection ->
- let state = builder.AppendLine $"### {subsection.Type}"
- |> (fun x -> x.AppendLine "")
+ let state =
+ builder.AppendLine $"### {subsection.Type}" |> (fun x -> x.AppendLine "")
subsection.ItemCollection
|> Seq.fold (fun (builder: StringBuilder) line -> builder.AppendLine $"- {line.MarkdownText}") state
- |> (fun x -> x.AppendLine ""))
+ |> (fun x -> x.AppendLine "")
+ )
builder
|> _.ToString()
|> _.Trim()
@@ -146,7 +151,8 @@ type ParseChangeLogs() =
for (key, value) in x.collection.ToTaskItemMetadata() do
taskItem.SetMetadata(key, value)
- taskItem :> ITaskItem)
+ taskItem :> ITaskItem
+ )
this.CurrentReleaseChangelog <- mapped[0]
this.AllReleasedChangelogs <- mapped
diff --git a/src/Log.fs b/src/Log.fs
index 0a12007..042d64f 100644
--- a/src/Log.fs
+++ b/src/Log.fs
@@ -19,10 +19,7 @@ let changelogFileNotFound (filePath: string) =
ErrorCode = "IKC0001"
HelpKeyword = "Missing Changelog file"
Message = "The Changelog file {0} was not found."
- MessageArgs =
- [|
- box filePath
- |]
+ MessageArgs = [| box filePath |]
}
let invalidChangelog (filePath: string) (error: string) =
@@ -30,9 +27,5 @@ let invalidChangelog (filePath: string) (error: string) =
ErrorCode = "IKC0002"
HelpKeyword = "Invalid Changelog file"
Message = "The Changelog file {0} is invalid. The error was: {1}"
- MessageArgs =
- [|
- box filePath
- box error
- |]
+ MessageArgs = [| box filePath; box error |]
}
diff --git a/tests/IntegrationTests.fs b/tests/IntegrationTests.fs
index f4fbdcf..a1184db 100644
--- a/tests/IntegrationTests.fs
+++ b/tests/IntegrationTests.fs
@@ -9,13 +9,15 @@ open Faqt
open SimpleExec
open Workspace
-
module Utils =
let packAndGetPackageProperties projectName =
let packageCache = VirtualWorkspace.``test-package-cache``.``.``
+
if Directory.Exists packageCache then
Directory.Delete(packageCache, true)
+
Directory.CreateDirectory packageCache |> ignore
+
Command.Run(
"dotnet",
CmdLine.empty
@@ -24,6 +26,7 @@ module Utils =
|> CmdLine.toString,
workingDirectory = Workspace.fixtures.``.``
)
+
Command.ReadAsync(
"dotnet",
CmdLine.empty
@@ -39,8 +42,8 @@ module Utils =
type StringHelper =
[]
- static member ReplaceEscapedNewLines (s: string) =
- s.ReplaceLineEndings().Replace("\\r\\n","\\n")
+ static member ReplaceEscapedNewLines(s: string) =
+ s.ReplaceLineEndings().Replace("\\r\\n", "\\n")
[]
type IntegrationTests() =
@@ -52,7 +55,6 @@ type IntegrationTests() =
this.testPackageVersion <- $"0.0.1-test-{suffix}"
-
// Create a package to be used in the tests
// I didn't find a way to test the MSBuild tasks execution using MSBuild only
// So each fsproj, will use a package reference to the package created here
@@ -78,7 +80,6 @@ type IntegrationTests() =
workingDirectory = Workspace.fixtures.``.``
)
-
[]
member this.``works for absolute path with keep a changelog``() : Task =
task {
diff --git a/tests/UnitTests.fs b/tests/UnitTests.fs
index 32b328f..b66825b 100644
--- a/tests/UnitTests.fs
+++ b/tests/UnitTests.fs
@@ -8,25 +8,25 @@ open Faqt.Operators
open Microsoft.VisualStudio.TestTools.UnitTesting
open Workspace
-type TestContext =
- {
- BuildEngine: Mock
- Errors: ResizeArray
- }
+type TestContext = {
+ BuildEngine: Mock
+ Errors: ResizeArray
+} with
member this.PrintErrors() =
this.Errors |> Seq.iter (fun error -> printfn "Error: %s" error.Message)
+
[]
type UnitTests() =
member val context = Unchecked.defaultof with get, set
+
[]
member this.Initialize() =
- this.context <-
- {
- BuildEngine = Mock()
- Errors = ResizeArray()
- }
+ this.context <- {
+ BuildEngine = Mock()
+ Errors = ResizeArray()
+ }
this.context.BuildEngine
.Setup(fun engine -> engine.LogErrorEvent(It.IsAny()))
@@ -34,7 +34,7 @@ type UnitTests() =
|> ignore
[]
- member this.``task fails when changelog file does not exist`` () =
+ member this.``task fails when changelog file does not exist``() =
let myTask = ParseChangeLogs(ChangelogFile = "ThisFileDoesNotExist.md")
myTask.BuildEngine <- this.context.BuildEngine.Object
@@ -46,7 +46,7 @@ type UnitTests() =
%this.context.Errors.[0].Code.Should().Be("IKC0001")
[]
- member this.``task succeeds when changelog file exists (relative path)`` () =
+ member this.``task succeeds when changelog file exists (relative path)``() =
// When running tests, the working directory is where the dll is located
let myTask = ParseChangeLogs(ChangelogFile = "../../../changelogs/CHANGELOG.md")
@@ -60,7 +60,7 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(0)
[]
- member this.``task succeeds when changelog file exists (absolute path)`` () =
+ member this.``task succeeds when changelog file exists (absolute path)``() =
let myTask = ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG.md``)
myTask.BuildEngine <- this.context.BuildEngine.Object
@@ -70,7 +70,7 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(0)
[]
- member this.``task fails when changelog file is invalid`` () =
+ member this.``task fails when changelog file is invalid``() =
let myTask =
ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG_invalid.md``)
@@ -82,9 +82,8 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(1)
%this.context.Errors.[0].Code.Should().Be("IKC0002")
-
[]
- member this.``task correctly parses details from changelog file`` () =
+ member this.``task correctly parses details from changelog file``() =
let myTask =
ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG_detailed.md``)
@@ -93,26 +92,42 @@ type UnitTests() =
let success = myTask.Execute()
%success.Should().BeTrue "Should have successfully parsed the changelog data"
%myTask.AllReleasedChangelogs.Length.Should().Be(9, "Should have 9 versions")
- %myTask.CurrentReleaseChangelog.ItemSpec.Should().Be("0.1.8", "Should have the most recent version")
- %myTask.CurrentReleaseChangelog.GetMetadata("Date").Should().Be("2022-03-31", "Should have the most recent version's date")
- %(myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.Should().Contain("Changed", "Should have changed metadata"))
- %(myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.Should().Contain("Date", "Should have date metadata"))
+
+ %myTask.CurrentReleaseChangelog.ItemSpec
+ .Should()
+ .Be("0.1.8", "Should have the most recent version")
+
+ %myTask.CurrentReleaseChangelog
+ .GetMetadata("Date")
+ .Should()
+ .Be("2022-03-31", "Should have the most recent version's date")
+
+ %(myTask.CurrentReleaseChangelog.MetadataNames
+ |> Seq.cast
+ |> _.Should().Contain("Changed", "Should have changed metadata"))
+
+ %(myTask.CurrentReleaseChangelog.MetadataNames
+ |> Seq.cast
+ |> _.Should().Contain("Date", "Should have date metadata"))
[]
- member this.``task produces expected markdown`` () =
- let myTask =
- ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG.md``)
+ member this.``task produces expected markdown``() =
+ let myTask = ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG.md``)
myTask.BuildEngine <- this.context.BuildEngine.Object
let success = myTask.Execute()
%success.Should().BeTrue "Should have successfully parsed the changelog data"
- %myTask.LatestReleaseNotes.Should().Be("""### Added
+
+ %myTask.LatestReleaseNotes
+ .Should()
+ .Be(
+ """### Added
- Created the package
### Changed
- Changed something in the package
-- Updated the target framework""")
-
+- Updated the target framework"""
+ )