Skip to content

Commit

Permalink
Apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tboby committed Oct 24, 2024
1 parent 0ed5731 commit d1ea73b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 48 deletions.
22 changes: 14 additions & 8 deletions src/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type ChangelogExtensions =
(string section.Type,
section.ItemCollection
|> Seq.map _.MarkdownText
|> String.concat Environment.NewLine))
|> String.concat Environment.NewLine)
)

[<Extension>]
static member ToTaskItem(unreleased: ChangelogSectionUnreleased) =
Expand All @@ -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
|}
)

[<Extension>]
static member ToMarkdown(subsections: ChangelogSubSectionCollection) =
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions src/Log.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,13 @@ 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) =
{
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 |]
}
11 changes: 6 additions & 5 deletions tests/IntegrationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +26,7 @@ module Utils =
|> CmdLine.toString,
workingDirectory = Workspace.fixtures.``.``
)

Command.ReadAsync(
"dotnet",
CmdLine.empty
Expand All @@ -39,8 +42,8 @@ module Utils =

type StringHelper =
[<Extension>]
static member ReplaceEscapedNewLines (s: string) =
s.ReplaceLineEndings().Replace("\\r\\n","\\n")
static member ReplaceEscapedNewLines(s: string) =
s.ReplaceLineEndings().Replace("\\r\\n", "\\n")

[<TestClass>]
type IntegrationTests() =
Expand All @@ -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
Expand All @@ -78,7 +80,6 @@ type IntegrationTests() =
workingDirectory = Workspace.fixtures.``.``
)


[<TestMethod>]
member this.``works for absolute path with keep a changelog``() : Task =
task {
Expand Down
67 changes: 41 additions & 26 deletions tests/UnitTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ open Faqt.Operators
open Microsoft.VisualStudio.TestTools.UnitTesting
open Workspace

type TestContext =
{
BuildEngine: Mock<IBuildEngine>
Errors: ResizeArray<BuildErrorEventArgs>
}
type TestContext = {
BuildEngine: Mock<IBuildEngine>
Errors: ResizeArray<BuildErrorEventArgs>
} with

member this.PrintErrors() =
this.Errors |> Seq.iter (fun error -> printfn "Error: %s" error.Message)

[<TestClass>]
type UnitTests() =

member val context = Unchecked.defaultof<TestContext> with get, set

[<TestInitialize>]
member this.Initialize() =
this.context <-
{
BuildEngine = Mock<IBuildEngine>()
Errors = ResizeArray<BuildErrorEventArgs>()
}
this.context <- {
BuildEngine = Mock<IBuildEngine>()
Errors = ResizeArray<BuildErrorEventArgs>()
}

this.context.BuildEngine
.Setup(fun engine -> engine.LogErrorEvent(It.IsAny<BuildErrorEventArgs>()))
.Callback(fun (args: BuildErrorEventArgs) -> this.context.Errors.Add(args))
|> ignore

[<TestMethod>]
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
Expand All @@ -46,7 +46,7 @@ type UnitTests() =
%this.context.Errors.[0].Code.Should().Be("IKC0001")

[<TestMethod>]
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")

Expand All @@ -60,7 +60,7 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(0)

[<TestMethod>]
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

Expand All @@ -70,7 +70,7 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(0)

[<TestMethod>]
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``)

Expand All @@ -82,9 +82,8 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(1)
%this.context.Errors.[0].Code.Should().Be("IKC0002")


[<TestMethod>]
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``)

Expand All @@ -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"))

[<TestMethod>]
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"""
)

0 comments on commit d1ea73b

Please sign in to comment.