From 0423a72f871af354a20746e4cb80cf3f0b7ab718 Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Tue, 22 Oct 2024 18:34:37 +0100 Subject: [PATCH 1/9] Port tests from EasyBuild.PackageReleaseNotes.Tasks --- Directory.Packages.props | 7 +- src/Directory.Build.props | 2 +- tests/IntegrationTests.fs | 205 ++++++++++++++++-- tests/Ionide.KeepAChangelog.Tasks.Test.fsproj | 9 +- tests/Setup.fs | 27 --- tests/UnitTests.fs | 127 +++++------ tests/Workspace.fs | 8 + tests/fixtures/CHANGELOG_KeepAChangelog.md | 13 ++ .../DefaultToChangelogIfNotSpecified.fsproj | 15 ++ tests/fixtures/Directory.Build.props | 5 +- tests/fixtures/Directory.Packages.props | 3 + tests/fixtures/NuGet.config | 8 + ...ksForAbsolutePathWithKeepAChangelog.fsproj | 19 ++ ...ksForRelativePathWithKeepAChangelog.fsproj | 19 ++ tests/packages.lock.json | 176 ++++++++++++--- 15 files changed, 495 insertions(+), 148 deletions(-) delete mode 100644 tests/Setup.fs create mode 100644 tests/fixtures/CHANGELOG_KeepAChangelog.md create mode 100644 tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj create mode 100644 tests/fixtures/Directory.Packages.props create mode 100644 tests/fixtures/NuGet.config create mode 100644 tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj create mode 100644 tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj diff --git a/Directory.Packages.props b/Directory.Packages.props index 506f00f..60a0da1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,7 +5,9 @@ false + + @@ -13,10 +15,13 @@ + + + - + \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index ad20c70..53b352e 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -9,4 +9,4 @@ - \ No newline at end of file + diff --git a/tests/IntegrationTests.fs b/tests/IntegrationTests.fs index 6852950..1cf26bb 100644 --- a/tests/IntegrationTests.fs +++ b/tests/IntegrationTests.fs @@ -1,27 +1,202 @@ module Tests.IntegrationTests -open Tests.Setup +open System.Runtime.CompilerServices +open System.Threading.Tasks +open Microsoft.VisualStudio.TestTools.UnitTesting open Moq open Microsoft.Build.Framework open Ionide.KeepAChangelog.Tasks open Shouldly +open BlackFox.CommandLine +open Faqt +open SimpleExec +open Workspace -// [] -// let ``works for 'ci' type with default config`` () = -// let buildEngine = Mock() -// let errors = ResizeArray() -// buildEngine -// .Setup(fun x -> x.LogErrorEvent(It.IsAny())) -// .Callback(fun args -> errors.Add(args)) -// |> ignore +module Utils = -// let item = Mock() -// item.Setup(fun x -> x.GetMetadata("MaximeTest")).Returns("test") |> ignore + let getPackageProperties projectName = + Command.ReadAsync( + "dotnet", + CmdLine.empty + |> CmdLine.appendPrefix "pack" projectName + |> CmdLine.appendPrefix "-c" "Release" + |> CmdLine.appendRaw "--getProperty:Version" + |> CmdLine.appendRaw "--getProperty:PackageVersion" + |> CmdLine.appendRaw "--getProperty:PackageReleaseNotes" + |> CmdLine.toString, + workingDirectory = Workspace.fixtures.``.`` + ) -// let myTask = ParseChangelog(ChangelogFile = "MyChangelog.md") -// myTask.BuildEngine <- buildEngine.Object +[] +type StringHelper = + [] + static member ReplaceEscapedNewLines (s: string) = + s.ReplaceLineEndings().Replace("\\r\\n","\\n") -// let success = myTask.Execute() +[] +type IntegrationTests() = -// success.ShouldBeTrue() + member val testPackageVersion = null with get, set + + member this.AddPackageReference(projectName: string) = + let suffix = projectName.Replace(".fsproj", "") + + 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 + Command.Run( + "dotnet", + CmdLine.empty + |> CmdLine.appendPrefix "pack" "src" + |> CmdLine.appendPrefix "-c" "Release" + |> CmdLine.appendPrefix "-o" VirtualWorkspace.packages.``.`` + |> CmdLine.appendRaw $"-p:PackageVersion=%s{this.testPackageVersion}" + |> CmdLine.toString, + workingDirectory = Workspace.``..``.``.`` + ) + + Command.Run( + "dotnet", + CmdLine.empty + |> CmdLine.appendPrefix "add" projectName + |> CmdLine.appendPrefix "package" "Ionide.KeepAChangelog.Tasks" + // |> CmdLine.appendPrefix "--source" VirtualWorkspace.packages.``.`` + |> CmdLine.appendPrefix "--version" $"[{this.testPackageVersion}]" + |> CmdLine.toString, + workingDirectory = Workspace.fixtures.``.`` + ) + + [] + member this.``works for absolute path with conventional commits changelog``() : Task = + task { + let projectName = "WorksForAbsolutePathWithConventionalCommitsChangelog.fsproj" + + this.AddPackageReference projectName + + let! struct (stdout, _) = Utils.getPackageProperties projectName + + stdout + .ReplaceEscapedNewLines() + .Should() + .Be( + """{ + "Properties": { + "Version": "0.10.0", + "PackageVersion": "0.10.0", + "PackageReleaseNotes": "### \uD83D\uDE80 Features\n\n* Feature 1\n\n### \uD83D\uDC1E Bug Fixes\n\n* Bug fix 1\n* Bug fix 2" + } +} +""" + ) + |> ignore + } + + [] + member this.``works for relative path with conventional commits changelog``() : Task = + task { + let projectName = "WorksForRelativePathWithConventionalCommitsChangelog.fsproj" + + this.AddPackageReference projectName + + let! struct (stdout, _) = Utils.getPackageProperties projectName + + stdout + .ReplaceEscapedNewLines() + .Should() + .Be( + """{ + "Properties": { + "Version": "0.10.0", + "PackageVersion": "0.10.0", + "PackageReleaseNotes": "### \uD83D\uDE80 Features\n\n* Feature 1\n\n### \uD83D\uDC1E Bug Fixes\n\n* Bug fix 1\n* Bug fix 2" + } +} +""" + ) + |> ignore + } + + [] + member this.``works for absolute path with keep a changelog``() : Task = + task { + let projectName = "WorksForAbsolutePathWithKeepAChangelog.fsproj" + + this.AddPackageReference projectName + + let! struct (stdout, _) = Utils.getPackageProperties projectName + + stdout + .ReplaceEscapedNewLines() + .Should() + .Be( + """{ + "Properties": { + "Version": "0.1.0", + "PackageVersion": "0.1.0", + "PackageReleaseNotes": "### Added + + - Created the package + + ### Changed + + - Updated the package" + } +} +""" + ) + |> ignore + } + + [] + member this.``works for relative path with keep a changelog``() : Task = + task { + let projectName = "WorksForRelativePathWithKeepAChangelog.fsproj" + + this.AddPackageReference projectName + + let! struct (stdout, _) = Utils.getPackageProperties projectName + + stdout + .ReplaceEscapedNewLines() + .Should() + .Be( + """{ + "Properties": { + "Version": "0.1.0", + "PackageVersion": "0.1.0", + "PackageReleaseNotes": "### Added\n\n- Created the package\n\n### Changed\n\n- Updated the package" + } +} +""" + ) + |> ignore + } + + [] + member this.``works with default CHANGELOG.md if no changelog is specified``() : Task = + task { + let projectName = "DefaultToChangelogIfNotSpecified.fsproj" + + this.AddPackageReference projectName + + let! struct (stdout, _) = Utils.getPackageProperties projectName + + stdout + .ReplaceEscapedNewLines() + .Should() + .Be( + """{ + "Properties": { + "Version": "0.1.0", + "PackageVersion": "0.1.0", + "PackageReleaseNotes": "### Added\n\n- Created the package\n\n### Changed\n\n- Updated the package" + } +} +""" + + ) + |> ignore + } diff --git a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj index 2e03bf3..f48d687 100644 --- a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj +++ b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj @@ -7,18 +7,21 @@ - + - + - + + + + diff --git a/tests/Setup.fs b/tests/Setup.fs deleted file mode 100644 index bb6f1b1..0000000 --- a/tests/Setup.fs +++ /dev/null @@ -1,27 +0,0 @@ -module Tests.Setup - -open Fixie -open System -open System.Collections.Generic -open System.Reflection - -[] -type TestAttribute() = - inherit Attribute() - -type TestModuleDiscovery() = - interface IDiscovery with - member _.TestClasses(concreteClasses: IEnumerable) = - concreteClasses - |> Seq.filter (fun cls -> - cls.GetMembers() |> Seq.exists (fun m -> m.Has()) - ) - - member _.TestMethods(publicMethods: IEnumerable) = - publicMethods |> Seq.filter (fun x -> x.Has() && x.IsStatic) - -type TestProject() = - interface ITestProject with - member _.Configure(configuration: TestConfiguration, environment: TestEnvironment) = - configuration.Conventions.Add() - \ No newline at end of file diff --git a/tests/UnitTests.fs b/tests/UnitTests.fs index 0bf664f..de82269 100644 --- a/tests/UnitTests.fs +++ b/tests/UnitTests.fs @@ -1,10 +1,10 @@ module Tests.UnitTests -open Tests.Setup open Moq open Microsoft.Build.Framework open Ionide.KeepAChangelog.Tasks open Shouldly +open Microsoft.VisualStudio.TestTools.UnitTesting open Workspace type TestContext = @@ -15,91 +15,84 @@ type TestContext = member this.PrintErrors() = this.Errors |> Seq.iter (fun error -> printfn "Error: %s" error.Message) +[] +type UnitTests() = -let private setupBuildEngine () = - let context = - { - BuildEngine = Mock() - Errors = ResizeArray() - } + member val context = Unchecked.defaultof with get, set + [] + member this.Initialize() = + this.context <- + { + BuildEngine = Mock() + Errors = ResizeArray() + } - context.BuildEngine - .Setup(fun engine -> engine.LogErrorEvent(It.IsAny())) - .Callback(fun (args: BuildErrorEventArgs) -> context.Errors.Add(args)) - |> ignore + this.context.BuildEngine + .Setup(fun engine -> engine.LogErrorEvent(It.IsAny())) + .Callback(fun (args: BuildErrorEventArgs) -> this.context.Errors.Add(args)) + |> ignore - context + [] + member this.``task fails when changelog file does not exist`` () = -[] -let ``task fails when changelog file does not exist`` () = - let context = setupBuildEngine () + let myTask = ParseChangeLogs(ChangelogFile = "ThisFileDoesNotExist.md") + myTask.BuildEngine <- this.context.BuildEngine.Object - let myTask = ParseChangeLogs(ChangelogFile = "ThisFileDoesNotExist.md") - myTask.BuildEngine <- context.BuildEngine.Object + let success = myTask.Execute() - let success = myTask.Execute() + success.ShouldBeFalse() + this.context.Errors.Count.ShouldBe(1) + this.context.Errors.[0].Code.ShouldBe("IKC0001") - success.ShouldBeFalse() - context.Errors.Count.ShouldBe(1) - context.Errors.[0].Code.ShouldBe("IKC0001") + [] + 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 = "../../../fixtures/CHANGELOG.md") -[] -let ``task succeeds when changelog file exists (relative path)`` () = - let context = setupBuildEngine () + myTask.BuildEngine <- this.context.BuildEngine.Object - // When running tests, the working directory is where the dll is located - let myTask = ParseChangeLogs(ChangelogFile = "../../../fixtures/CHANGELOG.md") + let success = myTask.Execute() - myTask.BuildEngine <- context.BuildEngine.Object + this.context.PrintErrors() - let success = myTask.Execute() + success.ShouldBeTrue() + this.context.Errors.Count.ShouldBe(0) - context.PrintErrors() + [] + member this.``task succeeds when changelog file exists (absolute path)`` () = + let myTask = ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG.md``) + myTask.BuildEngine <- this.context.BuildEngine.Object - success.ShouldBeTrue() - context.Errors.Count.ShouldBe(0) + let success = myTask.Execute() -[] -let ``task succeeds when changelog file exists (absolute path)`` () = - let context = setupBuildEngine () + success.ShouldBeTrue() + this.context.Errors.Count.ShouldBe(0) - let myTask = ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG.md``) - myTask.BuildEngine <- context.BuildEngine.Object + [] + member this.``task fails when changelog file is invalid`` () = + let myTask = + ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG_invalid.md``) - let success = myTask.Execute() + myTask.BuildEngine <- this.context.BuildEngine.Object - success.ShouldBeTrue() - context.Errors.Count.ShouldBe(0) + let success = myTask.Execute() -[] -let ``task fails when changelog file is invalid`` () = - let context = setupBuildEngine () + success.ShouldBeFalse() + this.context.Errors.Count.ShouldBe(1) + this.context.Errors.[0].Code.ShouldBe("IKC0002") - let myTask = - ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG_invalid.md``) - myTask.BuildEngine <- context.BuildEngine.Object + [] + member this.``task correctly parses detailes from changelog file`` () = + let myTask = + ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG_detailed.md``) - let success = myTask.Execute() - - success.ShouldBeFalse() - context.Errors.Count.ShouldBe(1) - context.Errors.[0].Code.ShouldBe("IKC0002") - - -[] -let ``task correctly parses detailes from changelog file`` () = - let context = setupBuildEngine () - let myTask = - ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG_detailed.md``) - - myTask.BuildEngine <- context.BuildEngine.Object - - let success = myTask.Execute() - success.ShouldBeTrue "Should have successfully parsed the changelog data" - myTask.AllReleasedChangelogs.Length.ShouldBe(9, "Should have 9 versions") - myTask.CurrentReleaseChangelog.ItemSpec.ShouldBe("0.1.8", "Should have the most recent version") - myTask.CurrentReleaseChangelog.GetMetadata("Date").ShouldBe("2022-03-31", "Should have the most recent version's date") - myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.ShouldContain("Changed", "Should have changed metadata") - myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.ShouldContain("Date", "Should have date metadata") + myTask.BuildEngine <- this.context.BuildEngine.Object + let success = myTask.Execute() + success.ShouldBeTrue "Should have successfully parsed the changelog data" + myTask.AllReleasedChangelogs.Length.ShouldBe(9, "Should have 9 versions") + myTask.CurrentReleaseChangelog.ItemSpec.ShouldBe("0.1.8", "Should have the most recent version") + myTask.CurrentReleaseChangelog.GetMetadata("Date").ShouldBe("2022-03-31", "Should have the most recent version's date") + myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.ShouldContain("Changed", "Should have changed metadata") + myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.ShouldContain("Date", "Should have date metadata") diff --git a/tests/Workspace.fs b/tests/Workspace.fs index 111d882..5b1a135 100644 --- a/tests/Workspace.fs +++ b/tests/Workspace.fs @@ -3,3 +3,11 @@ module Workspace open EasyBuild.FileSystemProvider type Workspace = RelativeFileSystem<"."> + +type VirtualWorkspace = + VirtualFileSystem< + ".", + """ +packages/ +""" + > diff --git a/tests/fixtures/CHANGELOG_KeepAChangelog.md b/tests/fixtures/CHANGELOG_KeepAChangelog.md new file mode 100644 index 0000000..7bbd1f0 --- /dev/null +++ b/tests/fixtures/CHANGELOG_KeepAChangelog.md @@ -0,0 +1,13 @@ +# Changelog + +## [Unreleased] + +## [0.1.0] - 2022-01-13 + +### Added + +- Created the package + +### Changed + +- Updated the package diff --git a/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj b/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj new file mode 100644 index 0000000..3affeda --- /dev/null +++ b/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj @@ -0,0 +1,15 @@ + + + + + net6.0 + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/tests/fixtures/Directory.Build.props b/tests/fixtures/Directory.Build.props index 51207d2..324349b 100644 --- a/tests/fixtures/Directory.Build.props +++ b/tests/fixtures/Directory.Build.props @@ -1,3 +1,6 @@ - + + false + + \ No newline at end of file diff --git a/tests/fixtures/Directory.Packages.props b/tests/fixtures/Directory.Packages.props new file mode 100644 index 0000000..4862603 --- /dev/null +++ b/tests/fixtures/Directory.Packages.props @@ -0,0 +1,3 @@ + + + diff --git a/tests/fixtures/NuGet.config b/tests/fixtures/NuGet.config new file mode 100644 index 0000000..e162f35 --- /dev/null +++ b/tests/fixtures/NuGet.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj b/tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj new file mode 100644 index 0000000..fd22b74 --- /dev/null +++ b/tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj @@ -0,0 +1,19 @@ + + + + + net6.0 + + + + $(MSBuildThisFileDirectory)CHANGELOG_KeepAChangelog.md + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj b/tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj new file mode 100644 index 0000000..ef42f4b --- /dev/null +++ b/tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj @@ -0,0 +1,19 @@ + + + + + net6.0 + + + + CHANGELOG_KeepAChangelog.md + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/tests/packages.lock.json b/tests/packages.lock.json index 6e34b1a..633a06c 100644 --- a/tests/packages.lock.json +++ b/tests/packages.lock.json @@ -2,6 +2,15 @@ "version": 2, "dependencies": { "net8.0": { + "BlackFox.CommandLine": { + "type": "Direct", + "requested": "[1.0.0, )", + "resolved": "1.0.0", + "contentHash": "dSW7uLetl021HQXKcZd1xrXPjhsXgaJ5U4tFe64DLja1KZ2Ce6QeugHvZDvLfcPkEc1ZPRF7fWv5/T+X3ThWTA==", + "dependencies": { + "FSharp.Core": "4.2.3" + } + }, "DotNet.ReproducibleBuilds": { "type": "Direct", "requested": "[1.2.25, )", @@ -14,15 +23,16 @@ "resolved": "0.3.0", "contentHash": "gdVJpqcMDJm4IfmITy3MtpEn/lo9pH8PirVlENtXGX9Sdw3rCgoo9ch1TAthUseh28RcUGWwza9BmEWlrQX/Aw==" }, - "Fixie.TestAdapter": { + "Faqt": { "type": "Direct", - "requested": "[3.4.0, )", - "resolved": "3.4.0", - "contentHash": "KQBF/t82Ax/09CuF4GuYOCshfA72YGvMh3t8EGLeqsCLdZmWhR6Lz0IIsbDkS9DrECK7l03WTufHe0D7Mq6WBw==", + "requested": "[4.2.1, )", + "resolved": "4.2.1", + "contentHash": "kB0fWnhJO+rMwrgdBWanb0dipU9dvUa3agglUeP0dDr1LRr952HkaA7vgrJPVFmp5/XmgD0JMbyg028AFesG4A==", "dependencies": { - "Fixie": "[3.4.0]", - "Microsoft.NET.Test.Sdk": "17.8.0", - "Mono.Cecil": "0.11.5" + "FSharp.Core": "5.0.2", + "FSharp.SystemTextJson": "1.3.13", + "FracturedJson": "4.0.3", + "YamlDotNet": "16.1.3" } }, "FSharp.Core": { @@ -54,6 +64,16 @@ "System.Configuration.ConfigurationManager": "7.0.0" } }, + "Microsoft.NET.Test.Sdk": { + "type": "Direct", + "requested": "[17.11.1, )", + "resolved": "17.11.1", + "contentHash": "U3Ty4BaGoEu+T2bwSko9tWqWUOU16WzSFkq6U8zve75oRBMSLTBdMAZrVNNz1Tq12aCdDom9fcOcM9QZaFHqFg==", + "dependencies": { + "Microsoft.CodeCoverage": "17.11.1", + "Microsoft.TestPlatform.TestHost": "17.11.1" + } + }, "Moq": { "type": "Direct", "requested": "[4.20.72, )", @@ -63,6 +83,22 @@ "Castle.Core": "5.1.1" } }, + "MSTest.TestAdapter": { + "type": "Direct", + "requested": "[3.6.1, )", + "resolved": "3.6.1", + "contentHash": "wgeZ8g4N75iksyrESdIGV46AxYqLvy1cRwyXCWfpA77huSPWCx89QsgZe3tg9k+OYx71v46aRVFZKT6gqCrarw==", + "dependencies": { + "Microsoft.Testing.Extensions.VSTestBridge": "1.4.1", + "Microsoft.Testing.Platform.MSBuild": "1.4.1" + } + }, + "MSTest.TestFramework": { + "type": "Direct", + "requested": "[3.6.1, )", + "resolved": "3.6.1", + "contentHash": "ugHS5Bz+hlLBd7FSS9JokRrzjmlmDQIx0Hxj6LTJztH/CRkuzNM+hK9Zoa53DR/B4BysEpu16ZXnm6KLH6Vrzg==" + }, "Semver": { "type": "Direct", "requested": "[2.3.0, )", @@ -112,10 +148,30 @@ "resolved": "4.4.0", "contentHash": "gwJEfIGS7FhykvtZoscwXj/XwW+mJY6UbAZk+qtLKFUGWC95kfKXnj8VkxsZQnWBxJemM/q664rGLN5nf+OHZw==" }, - "Fixie": { + "FracturedJson": { + "type": "Transitive", + "resolved": "4.0.3", + "contentHash": "pemUqqLxxpcw8aWUmc+8j40CKMeVvne6M/44pRnRan5s2G/8VET41U0a4Fc9YAQrd0QwaTwdj/51RmUtzZwPzw==", + "dependencies": { + "System.Text.Json": "6.0.10" + } + }, + "FSharp.SystemTextJson": { "type": "Transitive", - "resolved": "3.4.0", - "contentHash": "Rn+KhQIobYpMC8+S3Fk48wgpo8zljYsgT+M84q5csNJM5AzyVebcIIPAv5DXb+lJuKaOCG3ntpTdTEUPOJAHOA==" + "resolved": "1.3.13", + "contentHash": "znp8odpdkVGKVX0AvbhiXdmeMi0KJ+A4AyAQWSkfAEAe4Z4clRE+rVhrLnAGrFD1VEIUX2lsQ4o84ywpWZUSGw==", + "dependencies": { + "FSharp.Core": "4.7.0", + "System.Text.Json": "6.0.0" + } + }, + "Microsoft.ApplicationInsights": { + "type": "Transitive", + "resolved": "2.22.0", + "contentHash": "3AOM9bZtku7RQwHyMEY3tQMrHIgjcfRDa6YQpd/QG2LDGvMydSlL9Di+8LLMt7J2RDdfJ7/2jdYv6yHcMJAnNw==", + "dependencies": { + "System.Diagnostics.DiagnosticSource": "5.0.0" + } }, "Microsoft.Build.Framework": { "type": "Transitive", @@ -124,38 +180,70 @@ }, "Microsoft.CodeCoverage": { "type": "Transitive", - "resolved": "17.8.0", - "contentHash": "KC8SXWbGIdoFVdlxKk9WHccm0llm9HypcHMLUUFabRiTS3SO2fQXNZfdiF3qkEdTJhbRrxhdRxjL4jbtwPq4Ew==" + "resolved": "17.11.1", + "contentHash": "nPJqrcA5iX+Y0kqoT3a+pD/8lrW/V7ayqnEJQsTonSoPz59J8bmoQhcSN4G8+UJ64Hkuf0zuxnfuj2lkHOq4cA==" }, "Microsoft.NET.StringTools": { "type": "Transitive", "resolved": "17.8.3", "contentHash": "y6DiuacjlIfXH3XVQG5htf+4oheinZAo7sHbITB3z7yCXQec48f9ZhGSXkr+xn1bfl73Yc3ZQEW2peJ5X68AvQ==" }, - "Microsoft.NET.Test.Sdk": { + "Microsoft.Testing.Extensions.Telemetry": { + "type": "Transitive", + "resolved": "1.4.1", + "contentHash": "Li2CRKPN8LExJRakkaUV9Xq/VeezAkTG1Vp+bcuonES6VoCIKufnc9f5GwxYX5I9DIWWxwgR0UeowlkpOIKxiA==", + "dependencies": { + "Microsoft.ApplicationInsights": "2.22.0", + "Microsoft.Testing.Platform": "1.4.1" + } + }, + "Microsoft.Testing.Extensions.TrxReport.Abstractions": { + "type": "Transitive", + "resolved": "1.4.1", + "contentHash": "FJRIgh2cWPQmAmfWDkdROW94LjFCaRrcnBa6uX2xkcXL3SXqJN43RfbP5xMDCE7FyXXHBFBLyfKhIZ1L2lh9FA==", + "dependencies": { + "Microsoft.Testing.Platform": "1.4.1" + } + }, + "Microsoft.Testing.Extensions.VSTestBridge": { + "type": "Transitive", + "resolved": "1.4.1", + "contentHash": "57U75DJEpN+JMJUfyEef57KlXfwtNMHuFd2j5+7VIiwli4oDCwGCZfSNLY/mQ1NcVPTdsLvW2awwMLdxiV7Ysg==", + "dependencies": { + "Microsoft.ApplicationInsights": "2.22.0", + "Microsoft.TestPlatform.ObjectModel": "17.11.1", + "Microsoft.Testing.Extensions.Telemetry": "1.4.1", + "Microsoft.Testing.Extensions.TrxReport.Abstractions": "1.4.1", + "Microsoft.Testing.Platform": "1.4.1" + } + }, + "Microsoft.Testing.Platform": { + "type": "Transitive", + "resolved": "1.4.1", + "contentHash": "LT+DsDCtQL0x8tuClGk5mkBfeSdBuCgMX7UCE44H0JoayvOHhnbKCT5DElo2XNPclCbgm1PsPvePNPYQxV+X9w==" + }, + "Microsoft.Testing.Platform.MSBuild": { "type": "Transitive", - "resolved": "17.8.0", - "contentHash": "BmTYGbD/YuDHmApIENdoyN1jCk0Rj1fJB0+B/fVekyTdVidr91IlzhqzytiUgaEAzL1ZJcYCme0MeBMYvJVzvw==", + "resolved": "1.4.1", + "contentHash": "2Vct6WOIUxJJy64srxB2uhZCe6ZxPVlA43VNdJJjvO8oSyy+vLCW4Vv37LNLnnj+XFq3QVo0KOOaVAtLgbnGGg==", "dependencies": { - "Microsoft.CodeCoverage": "17.8.0", - "Microsoft.TestPlatform.TestHost": "17.8.0" + "Microsoft.Testing.Platform": "1.4.1" } }, "Microsoft.TestPlatform.ObjectModel": { "type": "Transitive", - "resolved": "17.8.0", - "contentHash": "AYy6vlpGMfz5kOFq99L93RGbqftW/8eQTqjT9iGXW6s9MRP3UdtY8idJ8rJcjeSja8A18IhIro5YnH3uv1nz4g==", + "resolved": "17.11.1", + "contentHash": "E2jZqAU6JeWEVsyOEOrSW1o1bpHLgb25ypvKNB/moBXPVsFYBPd/Jwi7OrYahG50J83LfHzezYI+GaEkpAotiA==", "dependencies": { - "NuGet.Frameworks": "6.5.0", "System.Reflection.Metadata": "1.6.0" } }, "Microsoft.TestPlatform.TestHost": { "type": "Transitive", - "resolved": "17.8.0", - "contentHash": "9ivcl/7SGRmOT0YYrHQGohWiT5YCpkmy/UEzldfVisLm6QxbLaK3FAJqZXI34rnRLmqqDCeMQxKINwmKwAPiDw==", + "resolved": "17.11.1", + "contentHash": "DnG+GOqJXO/CkoqlJWeDFTgPhqD/V6VqUIL3vINizCWZ3X+HshCtbbyDdSHQQEjrc2Sl/K3yaxX6s+5LFEdYuw==", "dependencies": { - "Microsoft.TestPlatform.ObjectModel": "17.8.0", + "Microsoft.TestPlatform.ObjectModel": "17.11.1", "Newtonsoft.Json": "13.0.1" } }, @@ -169,21 +257,11 @@ "resolved": "7.0.0", "contentHash": "2nXPrhdAyAzir0gLl8Yy8S5Mnm/uBSQQA7jEsILOS1MTyS7DbmV1NgViMtvV1sfCD1ebITpNwb1NIinKeJgUVQ==" }, - "Mono.Cecil": { - "type": "Transitive", - "resolved": "0.11.5", - "contentHash": "fxfX+0JGTZ8YQeu1MYjbBiK2CYTSzDyEeIixt+yqKKTn7FW8rv7JMY70qevup4ZJfD7Kk/VG/jDzQQTpfch87g==" - }, "Newtonsoft.Json": { "type": "Transitive", "resolved": "13.0.1", "contentHash": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==" }, - "NuGet.Frameworks": { - "type": "Transitive", - "resolved": "6.5.0", - "contentHash": "QWINE2x3MbTODsWT1Gh71GaGb5icBz4chS8VYvTgsBnsi8esgN6wtHhydd7fvToWECYGq7T4cgBBDiKD/363fg==" - }, "Roslynator.Analyzers": { "type": "Transitive", "resolved": "4.12.4", @@ -209,6 +287,11 @@ "System.Security.Permissions": "7.0.0" } }, + "System.Diagnostics.DiagnosticSource": { + "type": "Transitive", + "resolved": "5.0.0", + "contentHash": "tCQTzPsGZh/A9LhhA6zrqCRV4hOHsK90/G7q3Khxmn6tnB1PuNU0cRaKANP2AWcF9bn0zsuOoZOSrHuJk6oNBA==" + }, "System.Diagnostics.EventLog": { "type": "Transitive", "resolved": "7.0.0", @@ -235,6 +318,11 @@ "resolved": "1.6.0", "contentHash": "COC1aiAJjCoA5GBF+QKL2uLqEBew4JsCkQmoHKbN3TlOZKa2fKLz5CpiRQKDz0RsAOEGsVKqOD5bomsXq/4STQ==" }, + "System.Runtime.CompilerServices.Unsafe": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" + }, "System.Security.Cryptography.ProtectedData": { "type": "Transitive", "resolved": "7.0.0", @@ -248,6 +336,23 @@ "System.Windows.Extensions": "7.0.0" } }, + "System.Text.Encodings.Web": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "Vg8eB5Tawm1IFqj4TVK1czJX89rhFxJo9ELqc/Eiq0eXy13RK00eubyU6TJE6y+GQXjyV5gSfiewDUZjQgSE0w==", + "dependencies": { + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + } + }, + "System.Text.Json": { + "type": "Transitive", + "resolved": "6.0.10", + "contentHash": "NSB0kDipxn2ychp88NXWfFRFlmi1bst/xynOutbnpEfRCT9JZkZ7KOmF/I/hNKo2dILiMGnqblm+j1sggdLB9g==", + "dependencies": { + "System.Runtime.CompilerServices.Unsafe": "6.0.0", + "System.Text.Encodings.Web": "6.0.0" + } + }, "System.Windows.Extensions": { "type": "Transitive", "resolved": "7.0.0", @@ -256,6 +361,11 @@ "System.Drawing.Common": "7.0.0" } }, + "YamlDotNet": { + "type": "Transitive", + "resolved": "16.1.3", + "contentHash": "gtHGiDvU9VTtWte8f0thIM38cL1oowOjStKpeAEKKfA+Rc4AvekJzqFDZiiPcc4kw00ZiwR4OTJS56L16q98DQ==" + }, "ionide.keepachangelog.tasks": { "type": "Project" } From 0f5d2c5eb131f9ec23df2096d58c2a419f765418 Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Wed, 23 Oct 2024 17:57:35 +0100 Subject: [PATCH 2/9] Add newlines and hyphens --- src/Library.fs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Library.fs b/src/Library.fs index 9169259..b16c9d2 100644 --- a/src/Library.fs +++ b/src/Library.fs @@ -63,11 +63,14 @@ type ChangelogExtensions = |> Seq.fold (fun (builder: StringBuilder) subsection -> let state = builder.AppendLine $"### {subsection.Type}" + |> (fun x -> x.AppendLine "") subsection.ItemCollection - |> Seq.fold (fun (builder: StringBuilder) line -> builder.AppendLine line.MarkdownText) state) + |> Seq.fold (fun (builder: StringBuilder) line -> builder.AppendLine $"- {line.MarkdownText}") state + |> (fun x -> x.AppendLine "")) builder |> _.ToString() + |> _.Trim() type ParseChangeLogs() = inherit Task() From 61333bd7867693402dc3e70f82623fb90ff93475 Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Wed, 23 Oct 2024 18:12:44 +0100 Subject: [PATCH 3/9] Restore into test folder to force refresh of nuget package Also tidy --- tests/.gitignore | 2 + tests/IntegrationTests.fs | 98 +++++-------------- tests/Ionide.KeepAChangelog.Tasks.Test.fsproj | 8 ++ tests/UnitTests.fs | 8 +- tests/Workspace.fs | 3 +- tests/{fixtures => changelogs}/CHANGELOG.md | 0 .../CHANGELOG_detailed.md | 0 .../CHANGELOG_invalid.md | 0 tests/fixtures/CHANGELOG_KeepAChangelog.md | 1 + .../DefaultToChangelogIfNotSpecified.fsproj | 1 + tests/fixtures/NuGet.config | 4 +- ...ksForAbsolutePathWithKeepAChangelog.fsproj | 1 + ...ksForRelativePathWithKeepAChangelog.fsproj | 1 + tests/fixtures/valid/Simple.fsproj | 9 -- tests/fixtures/valid/packages.lock.json | 13 --- 15 files changed, 49 insertions(+), 100 deletions(-) create mode 100644 tests/.gitignore rename tests/{fixtures => changelogs}/CHANGELOG.md (100%) rename tests/{fixtures => changelogs}/CHANGELOG_detailed.md (100%) rename tests/{fixtures => changelogs}/CHANGELOG_invalid.md (100%) delete mode 100644 tests/fixtures/valid/Simple.fsproj delete mode 100644 tests/fixtures/valid/packages.lock.json diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..e4e5f3e --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +test-package-cache +test-nupkgs diff --git a/tests/IntegrationTests.fs b/tests/IntegrationTests.fs index 1cf26bb..9964014 100644 --- a/tests/IntegrationTests.fs +++ b/tests/IntegrationTests.fs @@ -1,12 +1,9 @@ module Tests.IntegrationTests +open System.IO open System.Runtime.CompilerServices open System.Threading.Tasks open Microsoft.VisualStudio.TestTools.UnitTesting -open Moq -open Microsoft.Build.Framework -open Ionide.KeepAChangelog.Tasks -open Shouldly open BlackFox.CommandLine open Faqt open SimpleExec @@ -15,12 +12,25 @@ open Workspace module Utils = - let getPackageProperties projectName = + 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 + |> CmdLine.appendPrefix "restore" projectName + |> CmdLine.appendPrefix "--packages" VirtualWorkspace.``test-package-cache``.``.`` + |> CmdLine.toString, + workingDirectory = Workspace.fixtures.``.`` + ) Command.ReadAsync( "dotnet", CmdLine.empty |> CmdLine.appendPrefix "pack" projectName |> CmdLine.appendPrefix "-c" "Release" + |> CmdLine.append "--no-restore" |> CmdLine.appendRaw "--getProperty:Version" |> CmdLine.appendRaw "--getProperty:PackageVersion" |> CmdLine.appendRaw "--getProperty:PackageReleaseNotes" @@ -44,6 +54,7 @@ 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 @@ -52,7 +63,7 @@ type IntegrationTests() = CmdLine.empty |> CmdLine.appendPrefix "pack" "src" |> CmdLine.appendPrefix "-c" "Release" - |> CmdLine.appendPrefix "-o" VirtualWorkspace.packages.``.`` + |> CmdLine.appendPrefix "-o" VirtualWorkspace.``test-nupkgs``.``.`` |> CmdLine.appendRaw $"-p:PackageVersion=%s{this.testPackageVersion}" |> CmdLine.toString, workingDirectory = Workspace.``..``.``.`` @@ -63,61 +74,12 @@ type IntegrationTests() = CmdLine.empty |> CmdLine.appendPrefix "add" projectName |> CmdLine.appendPrefix "package" "Ionide.KeepAChangelog.Tasks" - // |> CmdLine.appendPrefix "--source" VirtualWorkspace.packages.``.`` + |> CmdLine.appendPrefix "--source" VirtualWorkspace.``test-nupkgs``.``.`` |> CmdLine.appendPrefix "--version" $"[{this.testPackageVersion}]" |> CmdLine.toString, workingDirectory = Workspace.fixtures.``.`` ) - [] - member this.``works for absolute path with conventional commits changelog``() : Task = - task { - let projectName = "WorksForAbsolutePathWithConventionalCommitsChangelog.fsproj" - - this.AddPackageReference projectName - - let! struct (stdout, _) = Utils.getPackageProperties projectName - - stdout - .ReplaceEscapedNewLines() - .Should() - .Be( - """{ - "Properties": { - "Version": "0.10.0", - "PackageVersion": "0.10.0", - "PackageReleaseNotes": "### \uD83D\uDE80 Features\n\n* Feature 1\n\n### \uD83D\uDC1E Bug Fixes\n\n* Bug fix 1\n* Bug fix 2" - } -} -""" - ) - |> ignore - } - - [] - member this.``works for relative path with conventional commits changelog``() : Task = - task { - let projectName = "WorksForRelativePathWithConventionalCommitsChangelog.fsproj" - - this.AddPackageReference projectName - - let! struct (stdout, _) = Utils.getPackageProperties projectName - - stdout - .ReplaceEscapedNewLines() - .Should() - .Be( - """{ - "Properties": { - "Version": "0.10.0", - "PackageVersion": "0.10.0", - "PackageReleaseNotes": "### \uD83D\uDE80 Features\n\n* Feature 1\n\n### \uD83D\uDC1E Bug Fixes\n\n* Bug fix 1\n* Bug fix 2" - } -} -""" - ) - |> ignore - } [] member this.``works for absolute path with keep a changelog``() : Task = @@ -126,7 +88,7 @@ type IntegrationTests() = this.AddPackageReference projectName - let! struct (stdout, _) = Utils.getPackageProperties projectName + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName stdout .ReplaceEscapedNewLines() @@ -136,13 +98,7 @@ type IntegrationTests() = "Properties": { "Version": "0.1.0", "PackageVersion": "0.1.0", - "PackageReleaseNotes": "### Added - - - Created the package - - ### Changed - - - Updated the package" + "PackageReleaseNotes": "### Added\n\n- Created the package\n- Added a second line\n\n### Changed\n\n- Updated the package" } } """ @@ -157,7 +113,7 @@ type IntegrationTests() = this.AddPackageReference projectName - let! struct (stdout, _) = Utils.getPackageProperties projectName + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName stdout .ReplaceEscapedNewLines() @@ -167,7 +123,7 @@ type IntegrationTests() = "Properties": { "Version": "0.1.0", "PackageVersion": "0.1.0", - "PackageReleaseNotes": "### Added\n\n- Created the package\n\n### Changed\n\n- Updated the package" + "PackageReleaseNotes": "### Added\n\n- Created the package\n- Added a second line\n\n### Changed\n\n- Updated the package" } } """ @@ -176,13 +132,13 @@ type IntegrationTests() = } [] - member this.``works with default CHANGELOG.md if no changelog is specified``() : Task = + member this.``fails with default CHANGELOG.md if no changelog is specified``() : Task = task { let projectName = "DefaultToChangelogIfNotSpecified.fsproj" this.AddPackageReference projectName - let! struct (stdout, _) = Utils.getPackageProperties projectName + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName stdout .ReplaceEscapedNewLines() @@ -190,9 +146,9 @@ type IntegrationTests() = .Be( """{ "Properties": { - "Version": "0.1.0", - "PackageVersion": "0.1.0", - "PackageReleaseNotes": "### Added\n\n- Created the package\n\n### Changed\n\n- Updated the package" + "Version": "1.0.0", + "PackageVersion": "1.0.0", + "PackageReleaseNotes": "" } } """ diff --git a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj index f48d687..feb8389 100644 --- a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj +++ b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj @@ -31,4 +31,12 @@ + + + + + + + + diff --git a/tests/UnitTests.fs b/tests/UnitTests.fs index de82269..6c4989d 100644 --- a/tests/UnitTests.fs +++ b/tests/UnitTests.fs @@ -47,7 +47,7 @@ type UnitTests() = [] 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 = "../../../fixtures/CHANGELOG.md") + let myTask = ParseChangeLogs(ChangelogFile = "../../../changelogs/CHANGELOG.md") myTask.BuildEngine <- this.context.BuildEngine.Object @@ -60,7 +60,7 @@ type UnitTests() = [] member this.``task succeeds when changelog file exists (absolute path)`` () = - let myTask = ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG.md``) + let myTask = ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG.md``) myTask.BuildEngine <- this.context.BuildEngine.Object let success = myTask.Execute() @@ -71,7 +71,7 @@ type UnitTests() = [] member this.``task fails when changelog file is invalid`` () = let myTask = - ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG_invalid.md``) + ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG_invalid.md``) myTask.BuildEngine <- this.context.BuildEngine.Object @@ -85,7 +85,7 @@ type UnitTests() = [] member this.``task correctly parses detailes from changelog file`` () = let myTask = - ParseChangeLogs(ChangelogFile = Workspace.fixtures.``CHANGELOG_detailed.md``) + ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG_detailed.md``) myTask.BuildEngine <- this.context.BuildEngine.Object diff --git a/tests/Workspace.fs b/tests/Workspace.fs index 5b1a135..af668b6 100644 --- a/tests/Workspace.fs +++ b/tests/Workspace.fs @@ -8,6 +8,7 @@ type VirtualWorkspace = VirtualFileSystem< ".", """ -packages/ +test-nupkgs/ +test-package-cache/ """ > diff --git a/tests/fixtures/CHANGELOG.md b/tests/changelogs/CHANGELOG.md similarity index 100% rename from tests/fixtures/CHANGELOG.md rename to tests/changelogs/CHANGELOG.md diff --git a/tests/fixtures/CHANGELOG_detailed.md b/tests/changelogs/CHANGELOG_detailed.md similarity index 100% rename from tests/fixtures/CHANGELOG_detailed.md rename to tests/changelogs/CHANGELOG_detailed.md diff --git a/tests/fixtures/CHANGELOG_invalid.md b/tests/changelogs/CHANGELOG_invalid.md similarity index 100% rename from tests/fixtures/CHANGELOG_invalid.md rename to tests/changelogs/CHANGELOG_invalid.md diff --git a/tests/fixtures/CHANGELOG_KeepAChangelog.md b/tests/fixtures/CHANGELOG_KeepAChangelog.md index 7bbd1f0..5c2288c 100644 --- a/tests/fixtures/CHANGELOG_KeepAChangelog.md +++ b/tests/fixtures/CHANGELOG_KeepAChangelog.md @@ -7,6 +7,7 @@ ### Added - Created the package +- Added a second line ### Changed diff --git a/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj b/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj index 3affeda..fbeb39e 100644 --- a/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj +++ b/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj @@ -6,6 +6,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/fixtures/NuGet.config b/tests/fixtures/NuGet.config index e162f35..f7113cd 100644 --- a/tests/fixtures/NuGet.config +++ b/tests/fixtures/NuGet.config @@ -3,6 +3,6 @@ - + - \ No newline at end of file + diff --git a/tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj b/tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj index fd22b74..41ff699 100644 --- a/tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj +++ b/tests/fixtures/WorksForAbsolutePathWithKeepAChangelog.fsproj @@ -10,6 +10,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj b/tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj index ef42f4b..7e033d0 100644 --- a/tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj +++ b/tests/fixtures/WorksForRelativePathWithKeepAChangelog.fsproj @@ -10,6 +10,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/fixtures/valid/Simple.fsproj b/tests/fixtures/valid/Simple.fsproj deleted file mode 100644 index 7d620c7..0000000 --- a/tests/fixtures/valid/Simple.fsproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - - - - - diff --git a/tests/fixtures/valid/packages.lock.json b/tests/fixtures/valid/packages.lock.json deleted file mode 100644 index e3c801d..0000000 --- a/tests/fixtures/valid/packages.lock.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": 2, - "dependencies": { - "net6.0": { - "Ionide.KeepAChangelog.Tasks": { - "type": "Direct", - "requested": "[1.0.0-test-002, )", - "resolved": "1.0.0-test-002", - "contentHash": "FOf+ufy7DdFURwhkS/d2c51C0CGtBk5zikGnyfoSf+tWvukJeD3xl2I5cXKeX8F1l/bzz8GA1y0FoGT+6pNMAg==" - } - } - } -} \ No newline at end of file From 353d2dc170e0b72557c856b377e94a9b38f38226 Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Thu, 24 Oct 2024 07:39:04 +0100 Subject: [PATCH 4/9] Tidy solution/project --- Ionide.KeepAChangelog.sln | 15 ++++++--------- tests/Ionide.KeepAChangelog.Tasks.Test.fsproj | 6 +----- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Ionide.KeepAChangelog.sln b/Ionide.KeepAChangelog.sln index a63cfdc..3641f27 100644 --- a/Ionide.KeepAChangelog.sln +++ b/Ionide.KeepAChangelog.sln @@ -3,12 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30114.105 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{31D4F8AF-532B-4DDF-BBA3-FD9B4C8FDA73}" -EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ionide.KeepAChangelog.Tasks", "src\Ionide.KeepAChangelog.Tasks.fsproj", "{6CCAEBD2-9EE9-4540-AECF-02F0221B9C87}" -EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ionide.KeepAChangelog.Tasks.Test", "tests\Ionide.KeepAChangelog.Tasks.Test.fsproj", "{6456526B-A0F6-4998-A57A-772A055DF8AD}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ionide.KeepAChangelog.Tasks", "src\Ionide.KeepAChangelog.Tasks.fsproj", "{E2704404-A047-4BAE-8AF9-58DAAFF02952}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,16 +16,15 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6CCAEBD2-9EE9-4540-AECF-02F0221B9C87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6CCAEBD2-9EE9-4540-AECF-02F0221B9C87}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6CCAEBD2-9EE9-4540-AECF-02F0221B9C87}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6CCAEBD2-9EE9-4540-AECF-02F0221B9C87}.Release|Any CPU.Build.0 = Release|Any CPU {6456526B-A0F6-4998-A57A-772A055DF8AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6456526B-A0F6-4998-A57A-772A055DF8AD}.Debug|Any CPU.Build.0 = Debug|Any CPU {6456526B-A0F6-4998-A57A-772A055DF8AD}.Release|Any CPU.ActiveCfg = Release|Any CPU {6456526B-A0F6-4998-A57A-772A055DF8AD}.Release|Any CPU.Build.0 = Release|Any CPU + {E2704404-A047-4BAE-8AF9-58DAAFF02952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E2704404-A047-4BAE-8AF9-58DAAFF02952}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E2704404-A047-4BAE-8AF9-58DAAFF02952}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E2704404-A047-4BAE-8AF9-58DAAFF02952}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution - {6CCAEBD2-9EE9-4540-AECF-02F0221B9C87} = {31D4F8AF-532B-4DDF-BBA3-FD9B4C8FDA73} EndGlobalSection EndGlobal diff --git a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj index feb8389..56d332a 100644 --- a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj +++ b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj @@ -32,11 +32,7 @@ - - - - - + From 66ceb38ff4d8e3eba8d6bc10266bb777586ad4c7 Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Thu, 24 Oct 2024 07:45:30 +0100 Subject: [PATCH 5/9] Add a markdown formatting test, swap to Faqt --- tests/IntegrationTests.fs | 2 -- tests/UnitTests.fs | 56 ++++++++++++++++++++++++----------- tests/changelogs/CHANGELOG.md | 10 +++++++ 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/tests/IntegrationTests.fs b/tests/IntegrationTests.fs index 9964014..d076119 100644 --- a/tests/IntegrationTests.fs +++ b/tests/IntegrationTests.fs @@ -11,7 +11,6 @@ open Workspace module Utils = - let packAndGetPackageProperties projectName = let packageCache = VirtualWorkspace.``test-package-cache``.``.`` if Directory.Exists packageCache then @@ -38,7 +37,6 @@ module Utils = workingDirectory = Workspace.fixtures.``.`` ) -[] type StringHelper = [] static member ReplaceEscapedNewLines (s: string) = diff --git a/tests/UnitTests.fs b/tests/UnitTests.fs index 6c4989d..32b328f 100644 --- a/tests/UnitTests.fs +++ b/tests/UnitTests.fs @@ -3,7 +3,8 @@ module Tests.UnitTests open Moq open Microsoft.Build.Framework open Ionide.KeepAChangelog.Tasks -open Shouldly +open Faqt +open Faqt.Operators open Microsoft.VisualStudio.TestTools.UnitTesting open Workspace @@ -40,9 +41,9 @@ type UnitTests() = let success = myTask.Execute() - success.ShouldBeFalse() - this.context.Errors.Count.ShouldBe(1) - this.context.Errors.[0].Code.ShouldBe("IKC0001") + %success.Should().BeFalse() + %this.context.Errors.Count.Should().Be(1) + %this.context.Errors.[0].Code.Should().Be("IKC0001") [] member this.``task succeeds when changelog file exists (relative path)`` () = @@ -55,8 +56,8 @@ type UnitTests() = this.context.PrintErrors() - success.ShouldBeTrue() - this.context.Errors.Count.ShouldBe(0) + %success.Should().BeTrue() + %this.context.Errors.Count.Should().Be(0) [] member this.``task succeeds when changelog file exists (absolute path)`` () = @@ -65,8 +66,8 @@ type UnitTests() = let success = myTask.Execute() - success.ShouldBeTrue() - this.context.Errors.Count.ShouldBe(0) + %success.Should().BeTrue() + %this.context.Errors.Count.Should().Be(0) [] member this.``task fails when changelog file is invalid`` () = @@ -77,22 +78,41 @@ type UnitTests() = let success = myTask.Execute() - success.ShouldBeFalse() - this.context.Errors.Count.ShouldBe(1) - this.context.Errors.[0].Code.ShouldBe("IKC0002") + %success.Should().BeFalse() + %this.context.Errors.Count.Should().Be(1) + %this.context.Errors.[0].Code.Should().Be("IKC0002") [] - member this.``task correctly parses detailes from changelog file`` () = + member this.``task correctly parses details from changelog file`` () = let myTask = ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG_detailed.md``) myTask.BuildEngine <- this.context.BuildEngine.Object let success = myTask.Execute() - success.ShouldBeTrue "Should have successfully parsed the changelog data" - myTask.AllReleasedChangelogs.Length.ShouldBe(9, "Should have 9 versions") - myTask.CurrentReleaseChangelog.ItemSpec.ShouldBe("0.1.8", "Should have the most recent version") - myTask.CurrentReleaseChangelog.GetMetadata("Date").ShouldBe("2022-03-31", "Should have the most recent version's date") - myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.ShouldContain("Changed", "Should have changed metadata") - myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.ShouldContain("Date", "Should have date metadata") + %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")) + + [] + 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 + +- Created the package + +### Changed + +- Changed something in the package +- Updated the target framework""") + diff --git a/tests/changelogs/CHANGELOG.md b/tests/changelogs/CHANGELOG.md index 417eb98..9d447ad 100644 --- a/tests/changelogs/CHANGELOG.md +++ b/tests/changelogs/CHANGELOG.md @@ -2,8 +2,18 @@ ## [Unreleased] +### Removed + +- A test removal line +- And another removal + ## [0.1.0] - 2022-01-13 ### Added - Created the package + +### Changed + +- Changed something in the package +- Updated the target framework From 0e7ed3f65b9c4433aae3de6a6451c4bf75e36a3c Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Thu, 24 Oct 2024 07:48:13 +0100 Subject: [PATCH 6/9] Remove unused test packages --- Directory.Packages.props | 2 - tests/Ionide.KeepAChangelog.Tasks.Test.fsproj | 1 - tests/packages.lock.json | 37 ------------------- 3 files changed, 40 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 60a0da1..03d8250 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -8,7 +8,6 @@ - @@ -18,7 +17,6 @@ - diff --git a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj index 56d332a..311c781 100644 --- a/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj +++ b/tests/Ionide.KeepAChangelog.Tasks.Test.fsproj @@ -23,7 +23,6 @@ - diff --git a/tests/packages.lock.json b/tests/packages.lock.json index 633a06c..0dcf2b7 100644 --- a/tests/packages.lock.json +++ b/tests/packages.lock.json @@ -105,16 +105,6 @@ "resolved": "2.3.0", "contentHash": "4vYo1zqn6pJ1YrhjuhuOSbIIm0CpM47grbpTJ5ABjOlfGt/EhMEM9ed4MRK5Jr6gVnntWDqOUzGeUJp68PZGjw==" }, - "Shouldly": { - "type": "Direct", - "requested": "[4.2.1, )", - "resolved": "4.2.1", - "contentHash": "dKAKiSuhLKqD2TXwLKtqNg1nwzJcIKOOMncZjk9LYe4W+h+SCftpWdxwR79YZUIHMH+3Vu9s0s0UHNrgICLwRQ==", - "dependencies": { - "DiffEngine": "11.3.0", - "EmptyFiles": "4.4.0" - } - }, "SimpleExec": { "type": "Direct", "requested": "[12.0.0, )", @@ -134,20 +124,6 @@ "resolved": "2.42.5", "contentHash": "Do9Q7Nyfx2G4HRt96aB6yoP5Z9ic3jqBHLrf35tULzsWlFoBlkQZT62aXCiv7UmVmF56OUR+a3JoSSs140hfHQ==" }, - "DiffEngine": { - "type": "Transitive", - "resolved": "11.3.0", - "contentHash": "k0ZgZqd09jLZQjR8FyQbSQE86Q7QZnjEzq1LPHtj1R2AoWO8sjV5x+jlSisL7NZAbUOI4y+7Bog8gkr9WIRBGw==", - "dependencies": { - "EmptyFiles": "4.4.0", - "System.Management": "6.0.1" - } - }, - "EmptyFiles": { - "type": "Transitive", - "resolved": "4.4.0", - "contentHash": "gwJEfIGS7FhykvtZoscwXj/XwW+mJY6UbAZk+qtLKFUGWC95kfKXnj8VkxsZQnWBxJemM/q664rGLN5nf+OHZw==" - }, "FracturedJson": { "type": "Transitive", "resolved": "4.0.3", @@ -267,11 +243,6 @@ "resolved": "4.12.4", "contentHash": "isl8hAh7yFNjyBEC4YlTSi+xGBblqBUC/2MCMmnBPwuXPewb7XYnMRzT3vXbP/gOGwT8hZUOy1g/aRH3lAF/NQ==" }, - "System.CodeDom": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "CPc6tWO1LAer3IzfZufDBRL+UZQcj5uS207NHALQzP84Vp/z6wF0Aa0YZImOQY8iStY0A2zI/e3ihKNPfUm8XA==" - }, "System.Collections.Immutable": { "type": "Transitive", "resolved": "7.0.0", @@ -305,14 +276,6 @@ "Microsoft.Win32.SystemEvents": "7.0.0" } }, - "System.Management": { - "type": "Transitive", - "resolved": "6.0.1", - "contentHash": "10J1D0h/lioojphfJ4Fuh5ZUThT/xOVHdV9roGBittKKNP2PMjrvibEdbVTGZcPra1399Ja3tqIJLyQrc5Wmhg==", - "dependencies": { - "System.CodeDom": "6.0.0" - } - }, "System.Reflection.Metadata": { "type": "Transitive", "resolved": "1.6.0", From 9da516a83ab5d04904cff315fdd10a6947567c5f Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Thu, 24 Oct 2024 07:51:12 +0100 Subject: [PATCH 7/9] Use most tolerant semversion parsing --- src/Library.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library.fs b/src/Library.fs index b16c9d2..07c36a7 100644 --- a/src/Library.fs +++ b/src/Library.fs @@ -47,7 +47,7 @@ type ChangelogExtensions = static member Unwrapped(sections: ChangelogSectionCollection) = sections |> Seq.choose (fun section -> - match SemVersion.TryParse section.MarkdownVersion with + match SemVersion.TryParse(section.MarkdownVersion, SemVersionStyles.Any) with | false, _ -> None | true, version -> Some From e1d82c71c56f8c995787d98017b283aec53a906d Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Thu, 24 Oct 2024 07:57:25 +0100 Subject: [PATCH 8/9] Split test into one for each warning --- tests/IntegrationTests.fs | 28 +++++++++++++++++-- tests/fixtures/CHANGELOG.md | 19 +++++++++++++ .../FailIfChangelogDoesNotExist.fsproj | 20 +++++++++++++ ...roj => FailIfChangelogNotSpecified.fsproj} | 4 +-- 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/CHANGELOG.md create mode 100644 tests/fixtures/FailIfChangelogDoesNotExist.fsproj rename tests/fixtures/{DefaultToChangelogIfNotSpecified.fsproj => FailIfChangelogNotSpecified.fsproj} (86%) diff --git a/tests/IntegrationTests.fs b/tests/IntegrationTests.fs index d076119..9c12f40 100644 --- a/tests/IntegrationTests.fs +++ b/tests/IntegrationTests.fs @@ -130,9 +130,9 @@ type IntegrationTests() = } [] - member this.``fails with default CHANGELOG.md if no changelog is specified``() : Task = + member this.``fails if no changelog is specified``() : Task = task { - let projectName = "DefaultToChangelogIfNotSpecified.fsproj" + let projectName = "FailIfChangelogNotSpecified.fsproj" this.AddPackageReference projectName @@ -150,7 +150,31 @@ type IntegrationTests() = } } """ + ) + |> ignore + } + + [] + member this.``fails if changelog specified doesn't exist``() : Task = + task { + let projectName = "FailIfChangelogDoesNotExist.fsproj" + this.AddPackageReference projectName + + let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName + + stdout + .ReplaceEscapedNewLines() + .Should() + .Be( + """{ + "Properties": { + "Version": "1.0.0", + "PackageVersion": "1.0.0", + "PackageReleaseNotes": "" + } +} +""" ) |> ignore } diff --git a/tests/fixtures/CHANGELOG.md b/tests/fixtures/CHANGELOG.md new file mode 100644 index 0000000..9d447ad --- /dev/null +++ b/tests/fixtures/CHANGELOG.md @@ -0,0 +1,19 @@ +# Changelog + +## [Unreleased] + +### Removed + +- A test removal line +- And another removal + +## [0.1.0] - 2022-01-13 + +### Added + +- Created the package + +### Changed + +- Changed something in the package +- Updated the target framework diff --git a/tests/fixtures/FailIfChangelogDoesNotExist.fsproj b/tests/fixtures/FailIfChangelogDoesNotExist.fsproj new file mode 100644 index 0000000..dd1973a --- /dev/null +++ b/tests/fixtures/FailIfChangelogDoesNotExist.fsproj @@ -0,0 +1,20 @@ + + + + + net6.0 + + + + $(MSBuildThisFileDirectory)CHANGELOG_NotHere.md + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj b/tests/fixtures/FailIfChangelogNotSpecified.fsproj similarity index 86% rename from tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj rename to tests/fixtures/FailIfChangelogNotSpecified.fsproj index fbeb39e..b9a3b85 100644 --- a/tests/fixtures/DefaultToChangelogIfNotSpecified.fsproj +++ b/tests/fixtures/FailIfChangelogNotSpecified.fsproj @@ -6,8 +6,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all From 105cd6c17597f7785b9dd8c318fc5de2927cf661 Mon Sep 17 00:00:00 2001 From: Thomas Boby Date: Thu, 24 Oct 2024 08:25:02 +0100 Subject: [PATCH 9/9] WIP pipeline --- tests/IntegrationTests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/IntegrationTests.fs b/tests/IntegrationTests.fs index 9c12f40..f4fbdcf 100644 --- a/tests/IntegrationTests.fs +++ b/tests/IntegrationTests.fs @@ -72,7 +72,7 @@ type IntegrationTests() = CmdLine.empty |> CmdLine.appendPrefix "add" projectName |> CmdLine.appendPrefix "package" "Ionide.KeepAChangelog.Tasks" - |> CmdLine.appendPrefix "--source" VirtualWorkspace.``test-nupkgs``.``.`` + // |> CmdLine.appendPrefix "--source" VirtualWorkspace.``test-nupkgs``.``.`` |> CmdLine.appendPrefix "--version" $"[{this.testPackageVersion}]" |> CmdLine.toString, workingDirectory = Workspace.fixtures.``.``