-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from tboby/improve-tests
Improve tests, correctly trigger warnings, and fix output markdown format
- Loading branch information
Showing
25 changed files
with
558 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
</PropertyGroup> | ||
|
||
<Import Project="../Directory.Build.props" /> | ||
</Project> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test-package-cache | ||
test-nupkgs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,180 @@ | ||
module Tests.IntegrationTests | ||
|
||
open Tests.Setup | ||
open Moq | ||
open Microsoft.Build.Framework | ||
open Ionide.KeepAChangelog.Tasks | ||
open Shouldly | ||
open System.IO | ||
open System.Runtime.CompilerServices | ||
open System.Threading.Tasks | ||
open Microsoft.VisualStudio.TestTools.UnitTesting | ||
open BlackFox.CommandLine | ||
open Faqt | ||
open SimpleExec | ||
open Workspace | ||
|
||
// [<Test>] | ||
// let ``works for 'ci' type with default config`` () = | ||
// let buildEngine = Mock<IBuildEngine>() | ||
// let errors = ResizeArray<BuildErrorEventArgs>() | ||
|
||
// buildEngine | ||
// .Setup(fun x -> x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())) | ||
// .Callback(fun args -> errors.Add(args)) | ||
// |> ignore | ||
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 | ||
|> 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" | ||
|> CmdLine.toString, | ||
workingDirectory = Workspace.fixtures.``.`` | ||
) | ||
|
||
// let item = Mock<ITaskItem>() | ||
// item.Setup(fun x -> x.GetMetadata("MaximeTest")).Returns("test") |> ignore | ||
type StringHelper = | ||
[<Extension>] | ||
static member ReplaceEscapedNewLines (s: string) = | ||
s.ReplaceLineEndings().Replace("\\r\\n","\\n") | ||
|
||
// let myTask = ParseChangelog(ChangelogFile = "MyChangelog.md") | ||
// myTask.BuildEngine <- buildEngine.Object | ||
[<TestClass>] | ||
type IntegrationTests() = | ||
|
||
// let success = myTask.Execute() | ||
member val testPackageVersion = null with get, set | ||
|
||
// success.ShouldBeTrue() | ||
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.``test-nupkgs``.``.`` | ||
|> 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.``test-nupkgs``.``.`` | ||
|> CmdLine.appendPrefix "--version" $"[{this.testPackageVersion}]" | ||
|> CmdLine.toString, | ||
workingDirectory = Workspace.fixtures.``.`` | ||
) | ||
|
||
|
||
[<TestMethod>] | ||
member this.``works for absolute path with keep a changelog``() : Task = | ||
task { | ||
let projectName = "WorksForAbsolutePathWithKeepAChangelog.fsproj" | ||
|
||
this.AddPackageReference projectName | ||
|
||
let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName | ||
|
||
stdout | ||
.ReplaceEscapedNewLines() | ||
.Should() | ||
.Be( | ||
"""{ | ||
"Properties": { | ||
"Version": "0.1.0", | ||
"PackageVersion": "0.1.0", | ||
"PackageReleaseNotes": "### Added\n\n- Created the package\n- Added a second line\n\n### Changed\n\n- Updated the package" | ||
} | ||
} | ||
""" | ||
) | ||
|> ignore | ||
} | ||
|
||
[<TestMethod>] | ||
member this.``works for relative path with keep a changelog``() : Task = | ||
task { | ||
let projectName = "WorksForRelativePathWithKeepAChangelog.fsproj" | ||
|
||
this.AddPackageReference projectName | ||
|
||
let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName | ||
|
||
stdout | ||
.ReplaceEscapedNewLines() | ||
.Should() | ||
.Be( | ||
"""{ | ||
"Properties": { | ||
"Version": "0.1.0", | ||
"PackageVersion": "0.1.0", | ||
"PackageReleaseNotes": "### Added\n\n- Created the package\n- Added a second line\n\n### Changed\n\n- Updated the package" | ||
} | ||
} | ||
""" | ||
) | ||
|> ignore | ||
} | ||
|
||
[<TestMethod>] | ||
member this.``fails if no changelog is specified``() : Task = | ||
task { | ||
let projectName = "FailIfChangelogNotSpecified.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 | ||
} | ||
|
||
[<TestMethod>] | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.