diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index a135a9b4..08722b16 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -1,12 +1,18 @@ { - "version": 1, - "isRoot": true, - "tools": { - "paket": { - "version": "6.2.1", - "commands": [ - "paket" - ] - } + "version": 1, + "isRoot": true, + "tools": { + "paket": { + "version": "6.2.1", + "commands": [ + "paket" + ] + }, + "fantomas": { + "version": "5.0.0", + "commands": [ + "fantomas" + ] } -} + } +} \ No newline at end of file diff --git a/.editorconfig b/.editorconfig index 97a7a04a..0cb1545c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,8 +14,17 @@ indent_size = 4 trim_trailing_whitespace = true [*.{fs,fsi,fsx,config}] +# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html charset = utf-8 trim_trailing_whitespace = true +max_line_length=100 +fsharp_multiline_block_brackets_on_same_column=true +fsharp_experimental_stroustrup_style=true +fsharp_keep_max_number_of_blank_lines=2 +fsharp_max_array_or_list_number_of_items=1 +fsharp_array_or_list_multiline_formatter=number_of_items +fsharp_max_infix_operator_expression=10 +fsharp_multi_line_lambda_closing_newline=true [paket.*] trim_trailing_whitespace = true diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000..8aefea14 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Formatting commits +2f707976bda8f82d181866b4246f90361153302f diff --git a/Content/Console/.config/dotnet-tools.json b/Content/Console/.config/dotnet-tools.json index a9995f46..41475d48 100644 --- a/Content/Console/.config/dotnet-tools.json +++ b/Content/Console/.config/dotnet-tools.json @@ -26,11 +26,11 @@ "fsharp-analyzers" ] }, - "fantomas-tool": { - "version": "4.6.1", + "fantomas": { + "version": "5.0.0", "commands": [ "fantomas" ] } } -} \ No newline at end of file +} diff --git a/Content/Console/.editorconfig b/Content/Console/.editorconfig index 304fc051..ec844b36 100644 --- a/Content/Console/.editorconfig +++ b/Content/Console/.editorconfig @@ -14,8 +14,17 @@ indent_size = 4 end_of_line = lf [*.{fs,fsi,fsx,config}] +# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html charset = utf-8 trim_trailing_whitespace = true +max_line_length=100 +fsharp_multiline_block_brackets_on_same_column=true +fsharp_experimental_stroustrup_style=true +fsharp_keep_max_number_of_blank_lines=2 +fsharp_max_array_or_list_number_of_items=1 +fsharp_array_or_list_multiline_formatter=number_of_items +fsharp_max_infix_operator_expression=10 +fsharp_multi_line_lambda_closing_newline=true [paket.*] trim_trailing_whitespace = true diff --git a/Content/Console/.git-blame-ignore-revs b/Content/Console/.git-blame-ignore-revs new file mode 100644 index 00000000..9c8817e4 --- /dev/null +++ b/Content/Console/.git-blame-ignore-revs @@ -0,0 +1,6 @@ +# This file contains a list of git hashes of revisions to be ignored by git +# These revisions are considered "unimportant" in +# that they are unlikely to be what you are interested in when blaming. +# Like formatting with Fantomas +# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view +# Add formatting commits here diff --git a/Content/Console/src/MyLib.1/Main.fs b/Content/Console/src/MyLib.1/Main.fs index 38b21e4b..7483ef0c 100644 --- a/Content/Console/src/MyLib.1/Main.fs +++ b/Content/Console/src/MyLib.1/Main.fs @@ -43,7 +43,9 @@ module AssemblyInfo = module Say = open System - let nothing name = name |> ignore + let nothing name = + name + |> ignore let hello name = sprintf "Hello %s" name @@ -61,6 +63,7 @@ module Main = | Version | Favorite_Color of string // Look in App.config | [] Hello of string + interface IArgParserTemplate with member s.Usage = match s with @@ -82,9 +85,14 @@ module Main = match results.TryGetResult Hello with | Some v -> let color = results.GetResult Favorite_Color - Say.hello v |> Say.colorizeIn color - | None -> parser.PrintUsage() |> printfn "%s" + + Say.hello v + |> Say.colorizeIn color + | None -> + parser.PrintUsage() + |> printfn "%s" else - parser.PrintUsage() |> printfn "%s" + parser.PrintUsage() + |> printfn "%s" 0 diff --git a/Content/Console/tests/MyLib.1.Tests/Tests.fs b/Content/Console/tests/MyLib.1.Tests/Tests.fs index 6ec2a60d..4b83cd9f 100644 --- a/Content/Console/tests/MyLib.1.Tests/Tests.fs +++ b/Content/Console/tests/MyLib.1.Tests/Tests.fs @@ -6,13 +6,13 @@ open MyLib._1 module SayTests = [] let tests = - testList - "samples" - [ testCase "Say nothing" - <| fun _ -> - let subject = Say.nothing () - Expect.equal subject () "Not an absolute unit" - testCase "Say hello all" - <| fun _ -> - let subject = Say.hello "all" - Expect.equal subject "Hello all" "You didn't say hello" ] + testList "samples" [ + testCase "Say nothing" + <| fun _ -> + let subject = Say.nothing () + Expect.equal subject () "Not an absolute unit" + testCase "Say hello all" + <| fun _ -> + let subject = Say.hello "all" + Expect.equal subject "Hello all" "You didn't say hello" + ] diff --git a/Content/Library/.config/dotnet-tools.json b/Content/Library/.config/dotnet-tools.json index dac43984..590e36fc 100644 --- a/Content/Library/.config/dotnet-tools.json +++ b/Content/Library/.config/dotnet-tools.json @@ -26,11 +26,11 @@ "fsharp-analyzers" ] }, - "fantomas-tool": { - "version": "4.6.1", + "fantomas": { + "version": "5.0.0", "commands": [ "fantomas" ] } } -} \ No newline at end of file +} diff --git a/Content/Library/.editorconfig b/Content/Library/.editorconfig index 304fc051..ec844b36 100644 --- a/Content/Library/.editorconfig +++ b/Content/Library/.editorconfig @@ -14,8 +14,17 @@ indent_size = 4 end_of_line = lf [*.{fs,fsi,fsx,config}] +# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html charset = utf-8 trim_trailing_whitespace = true +max_line_length=100 +fsharp_multiline_block_brackets_on_same_column=true +fsharp_experimental_stroustrup_style=true +fsharp_keep_max_number_of_blank_lines=2 +fsharp_max_array_or_list_number_of_items=1 +fsharp_array_or_list_multiline_formatter=number_of_items +fsharp_max_infix_operator_expression=10 +fsharp_multi_line_lambda_closing_newline=true [paket.*] trim_trailing_whitespace = true diff --git a/Content/Library/.git-blame-ignore-revs b/Content/Library/.git-blame-ignore-revs new file mode 100644 index 00000000..9c8817e4 --- /dev/null +++ b/Content/Library/.git-blame-ignore-revs @@ -0,0 +1,6 @@ +# This file contains a list of git hashes of revisions to be ignored by git +# These revisions are considered "unimportant" in +# that they are unlikely to be what you are interested in when blaming. +# Like formatting with Fantomas +# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view +# Add formatting commits here diff --git a/Content/Library/src/MyLib.1/Library.fs b/Content/Library/src/MyLib.1/Library.fs index 900e72a6..a01616bd 100644 --- a/Content/Library/src/MyLib.1/Library.fs +++ b/Content/Library/src/MyLib.1/Library.fs @@ -14,11 +14,12 @@ module Say = | Blue /// A person with many different field types - type Person = - { Name: string - FavoriteNumber: int - FavoriteColor: FavoriteColor - DateOfBirth: DateTimeOffset } + type Person = { + Name: string + FavoriteNumber: int + FavoriteColor: FavoriteColor + DateOfBirth: DateTimeOffset + } /// Says hello to a specific person let helloPerson (person: Person) = @@ -50,4 +51,6 @@ module Say = /// I do nothing - let nothing name = name |> ignore + let nothing name = + name + |> ignore diff --git a/Content/Library/tests/MyLib.1.Tests/Tests.fs b/Content/Library/tests/MyLib.1.Tests/Tests.fs index dd977060..8c217709 100644 --- a/Content/Library/tests/MyLib.1.Tests/Tests.fs +++ b/Content/Library/tests/MyLib.1.Tests/Tests.fs @@ -8,27 +8,28 @@ open MyLib._1.Say module SayTests = [] let tests = - testList - "samples" - [ testCase "Add two integers" - <| fun _ -> - let subject = Say.add 1 2 - Expect.equal subject 3 "Addition works" - testCase "Say nothing" - <| fun _ -> - let subject = Say.nothing () - Expect.equal subject () "Not an absolute unit" - testCase "Say hello all" - <| fun _ -> - let person = - { Name = "Jean-Luc Picard" - FavoriteNumber = 4 - FavoriteColor = Red - DateOfBirth = DateTimeOffset.Parse("July 13, 2305") } + testList "samples" [ + testCase "Add two integers" + <| fun _ -> + let subject = Say.add 1 2 + Expect.equal subject 3 "Addition works" + testCase "Say nothing" + <| fun _ -> + let subject = Say.nothing () + Expect.equal subject () "Not an absolute unit" + testCase "Say hello all" + <| fun _ -> + let person = { + Name = "Jean-Luc Picard" + FavoriteNumber = 4 + FavoriteColor = Red + DateOfBirth = DateTimeOffset.Parse("July 13, 2305") + } - let subject = Say.helloPerson person + let subject = Say.helloPerson person - Expect.equal - subject - "Hello Jean-Luc Picard. You were born on 2305/07/13 and your favorite number is 4. You like Red." - "You didn't say hello" ] + Expect.equal + subject + "Hello Jean-Luc Picard. You were born on 2305/07/13 and your favorite number is 4. You like Red." + "You didn't say hello" + ] diff --git a/build/build.fs b/build/build.fs index 0e150d4c..90cb9ed9 100644 --- a/build/build.fs +++ b/build/build.fs @@ -16,7 +16,12 @@ open Fake.BuildServer let srcGlob = "*.csproj" -let testsGlob = __SOURCE_DIRECTORY__ ".." "tests/**/*.??proj" +let testsCodeGlob = + !! (__SOURCE_DIRECTORY__ ".." "tests/**/*.fs") + ++ (__SOURCE_DIRECTORY__ ".." "tests/**/*.fsx") + -- (__SOURCE_DIRECTORY__ ".." "tests/**/obj/**/*.fs") + +let testsGlob = !! (__SOURCE_DIRECTORY__ ".." "tests/**/*.??proj") let distDir = __SOURCE_DIRECTORY__ ".." "dist" let distGlob = distDir "*.nupkg" @@ -182,6 +187,9 @@ module dotnet = let run cmdParam args = DotNet.exec cmdParam "run" args + let fantomas args = + DotNet.exec id "fantomas" args + module DocsTool = open Argu let buildparser = ArgumentParser.Create(programName = "docstool") @@ -319,6 +327,39 @@ let ``update changelog`` ctx = // If build fails after this point but before we push the release out, undo our modifications Target.activateBuildFailure "RevertChangelog" +let formatCode _ = + let result = + [ + testsCodeGlob + ] + |> Seq.collect id + // Ignore AssemblyInfo + |> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not) + |> String.concat " " + |> dotnet.fantomas + + if not result.OK then + printfn "Errors while formatting all files: %A" result.Messages + +let checkFormatCode _ = + let result = + [ + testsCodeGlob + ] + |> Seq.collect id + // Ignore AssemblyInfo + |> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not) + |> String.concat " " + |> sprintf "%s --check" + |> dotnet.fantomas + + if result.ExitCode = 0 then + Trace.log "No files need formatting" + elif result.ExitCode = 99 then + failwith "Some files need formatting, check output for more info" + else + Trace.logf "Errors while formatting: %A" result.Errors + let ``dotnet pack`` ctx = !! srcGlob @@ -345,7 +386,7 @@ let getPkgPath () = |> Seq.head let ``integration tests`` ctx = - !! testsGlob + testsGlob |> Seq.iter (fun proj -> dotnet.run(fun c -> @@ -467,7 +508,8 @@ let initTargets () = Target.create "BuildDocs" ``build docs`` Target.create "WatchDocs" ``watch docs`` Target.create "ReleaseDocs" ``release docs`` - + Target.create "FormatCode" formatCode + Target.create "CheckFormatCode" checkFormatCode //----------------------------------------------------------------------------- // Target Dependencies //----------------------------------------------------------------------------- @@ -487,6 +529,7 @@ let initTargets () = "Clean" ==> "DotnetRestore" ==> "DotnetPack" + =?> ("CheckFormatCode", isCI) =?> ("IntegrationTests", isCI) ==> "PublishToNuGet" ==> "GitRelease" diff --git a/tests/MiniScaffold.Tests/Asserts.fs b/tests/MiniScaffold.Tests/Asserts.fs index 7f1742c2..3c0bf280 100644 --- a/tests/MiniScaffold.Tests/Asserts.fs +++ b/tests/MiniScaffold.Tests/Asserts.fs @@ -1,23 +1,42 @@ namespace MiniScaffold.Tests + open System.IO open Expecto open Infrastructure open Fake.IO.FileSystemOperators + module Array = - let insert v i (l : 'a array) = - let newArray = Array.zeroCreate (l.Length + 1) + let insert v i (l: 'a array) = + let newArray = + Array.zeroCreate ( + l.Length + + 1 + ) + let mutable newPointer = 0 + l - |> Array.iteri(fun j y -> + |> Array.iteri (fun j y -> if i = j then newArray.[newPointer] <- v - newPointer <- newPointer + 1 + + newPointer <- + newPointer + + 1 + newArray.[newPointer] <- y - newPointer <- newPointer + 1 + + newPointer <- + newPointer + + 1 else newArray.[newPointer] <- y - newPointer <- newPointer + 1 + + newPointer <- + newPointer + + 1 ) + newArray module Assert = @@ -28,40 +47,63 @@ module Assert = | Some _ -> () | None -> failtest msg - let private tryFindFile file (d : DirectoryInfo) = + let private tryFindFile file (d: DirectoryInfo) = let filepath = Path.Combine(d.FullName, file) - if filepath |> File.Exists |> not then - let message = sprintf "Could not find %s, all files currently in folder are:" filepath - let message = (message, d.EnumerateFiles()) ||> Seq.fold(fun state next -> - sprintf "%s%s%s" state Environment.NewLine next.FullName - ) + + if + filepath + |> File.Exists + |> not + then + let message = + sprintf "Could not find %s, all files currently in folder are:" filepath + + let message = + (message, d.EnumerateFiles()) + ||> Seq.fold (fun state next -> + sprintf "%s%s%s" state Environment.NewLine next.FullName + ) + failtest message - let ``project can build target`` target (d : DirectoryInfo) = + let ``project can build target`` target (d: DirectoryInfo) = Builds.executeBuild d.FullName target - let ``build target with failure expected`` target (d : DirectoryInfo) = + let ``build target with failure expected`` target (d: DirectoryInfo) = let failed = try Builds.executeBuild d.FullName target false with _ -> true - Expect.isTrue failed (sprintf "Building target %s succeeded when it should have failed" target) - let ``CHANGELOG exists`` = - tryFindFile "CHANGELOG.md" + Expect.isTrue + failed + (sprintf "Building target %s succeeded when it should have failed" target) + + let ``CHANGELOG exists`` = tryFindFile "CHANGELOG.md" - let ``CHANGELOG contains Unreleased section`` (d : DirectoryInfo) = - let changelogContents = Path.Combine(d.FullName, "CHANGELOG.md") |> File.ReadAllLines - Expect.contains changelogContents "## [Unreleased]" "Changelog should contain Unreleased section" + let ``CHANGELOG contains Unreleased section`` (d: DirectoryInfo) = + let changelogContents = + Path.Combine(d.FullName, "CHANGELOG.md") + |> File.ReadAllLines - let ``CHANGELOG does not contain Unreleased section`` (d : DirectoryInfo) = - let changelogContents = Path.Combine(d.FullName, "CHANGELOG.md") |> File.ReadAllLines - Expect.isFalse (changelogContents |> Array.contains "## [Unreleased]") "Changelog should not contain Unreleased section" + Expect.contains + changelogContents + "## [Unreleased]" + "Changelog should contain Unreleased section" - let ``.config/dotnet-tools.json exists`` = - tryFindFile ".config/dotnet-tools.json" + let ``CHANGELOG does not contain Unreleased section`` (d: DirectoryInfo) = + let changelogContents = + Path.Combine(d.FullName, "CHANGELOG.md") + |> File.ReadAllLines + + Expect.isFalse + (changelogContents + |> Array.contains "## [Unreleased]") + "Changelog should not contain Unreleased section" + + let ``.config/dotnet-tools.json exists`` = tryFindFile ".config/dotnet-tools.json" let ``.github ISSUE_TEMPLATE bug_report exists`` = tryFindFile ".github/ISSUE_TEMPLATE/bug_report.md" @@ -69,210 +111,333 @@ module Assert = let ``.github ISSUE_TEMPLATE feature_request exists`` = tryFindFile ".github/ISSUE_TEMPLATE/feature_request.md" - let ``.github workflows build exists`` = - tryFindFile ".github/workflows/build.yml" + let ``.github workflows build exists`` = tryFindFile ".github/workflows/build.yml" - let ``.github ISSUE_TEMPLATE exists`` = - tryFindFile ".github/ISSUE_TEMPLATE.md" + let ``.github ISSUE_TEMPLATE exists`` = tryFindFile ".github/ISSUE_TEMPLATE.md" let ``.github PULL_REQUEST_TEMPLATE exists`` = tryFindFile ".github/PULL_REQUEST_TEMPLATE.md" - let ``.editorconfig exists`` = - tryFindFile ".editorconfig" + let ``.editorconfig exists`` = tryFindFile ".editorconfig" - let ``.gitattributes exists`` = - tryFindFile ".gitattributes" + let ``.gitattributes exists`` = tryFindFile ".gitattributes" - let ``.gitignore exists`` = - tryFindFile ".gitignore" + let ``.gitignore exists`` = tryFindFile ".gitignore" - let ``LICENSE exists`` = - tryFindFile "LICENSE.md" + let ``LICENSE exists`` = tryFindFile "LICENSE.md" - let ``paket.lock exists`` = - tryFindFile "paket.lock" + let ``paket.lock exists`` = tryFindFile "paket.lock" - let ``paket.dependencies exists`` = - tryFindFile "paket.dependencies" + let ``paket.dependencies exists`` = tryFindFile "paket.dependencies" - let ``README exists`` = - tryFindFile "README.md" + let ``README exists`` = tryFindFile "README.md" module Effect = open System open Fake.IO open Fake.Tools - let ``replace section with`` startIdx endIdx replace (data : string array) = + let ``replace section with`` startIdx endIdx replace (data: string array) = printfn "replacing lines %i to %i with %s" startIdx endIdx replace + for i = startIdx to endIdx do data.[i] <- sprintf "// %s" data.[i] + Array.insert replace (endIdx + 1) data let ``find section`` startPredicate endPredicate data = - let datai = data |> Array.indexed - match datai |> Array.tryFind (startPredicate) with + let datai = + data + |> Array.indexed + + match + datai + |> Array.tryFind (startPredicate) + with | None -> None - | Some (startIdx, _ ) -> + | Some (startIdx, _) -> let (endIdx, _) = datai - |> Array.skip (startIdx + 1) + |> Array.skip ( + startIdx + + 1 + ) |> Array.takeWhile (endPredicate) |> Array.last - Some (startIdx, endIdx) - let ``get build.fs`` (d : DirectoryInfo) = - d.FullName "build" "build.fs" + Some(startIdx, endIdx) + + let ``get build.fs`` (d: DirectoryInfo) = + d.FullName + "build" + "build.fs" - let ``transform build script with`` (replaceFn : string -> string) (d : DirectoryInfo) = + let ``transform build script with`` (replaceFn: string -> string) (d: DirectoryInfo) = let buildScript = ``get build.fs`` d - buildScript |> File.applyReplace replaceFn - let ``disable restore`` (d : DirectoryInfo) = + buildScript + |> File.applyReplace replaceFn + + let ``disable restore`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let startPred = (fun (idx, line : string) -> line.Contains "let dotnetRestore") - let endPred = (snd >> (fun (x : string) -> x.StartsWith "let ") >> not) + let startPred = (fun (idx, line: string) -> line.Contains "let dotnetRestore") + + let endPred = + (snd + >> (fun (x: string) -> x.StartsWith "let ") + >> not) + match ``find section`` startPred endPred lines with | None -> () - | Some (startIdx, endIdx ) -> - ``replace section with`` (startIdx + 1) endIdx " ()" lines + | Some (startIdx, endIdx) -> + ``replace section with`` + (startIdx + + 1) + endIdx + " ()" + lines |> File.writeNew buildScript - let ``disable build`` (d : DirectoryInfo) = + let ``disable build`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let startPred = (fun (idx, line : string) -> line.Contains "let dotnetBuild") - let endPred = (snd >> (fun (x : string) -> x.StartsWith "let ") >> not) + let startPred = (fun (idx, line: string) -> line.Contains "let dotnetBuild") + + let endPred = + (snd + >> (fun (x: string) -> x.StartsWith "let ") + >> not) + match ``find section`` startPred endPred lines with | None -> () - | Some (startIdx, endIdx ) -> - ``replace section with`` (startIdx + 1) endIdx " ()" lines + | Some (startIdx, endIdx) -> + ``replace section with`` + (startIdx + + 1) + endIdx + " ()" + lines |> File.writeNew buildScript - let ``disable fsharpAnalyzers`` (d : DirectoryInfo) = + let ``disable fsharpAnalyzers`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let startPred = (fun (idx, line : string) -> line.Contains "let fsharpAnalyzers") - let endPred = (snd >> (fun (x : string) -> x.StartsWith "let ") >> not) + let startPred = (fun (idx, line: string) -> line.Contains "let fsharpAnalyzers") + + let endPred = + (snd + >> (fun (x: string) -> x.StartsWith "let ") + >> not) + match ``find section`` startPred endPred lines with | None -> () - | Some (startIdx, endIdx ) -> - ``replace section with`` (startIdx + 1) endIdx " ()" lines + | Some (startIdx, endIdx) -> + ``replace section with`` + (startIdx + + 1) + endIdx + " ()" + lines |> File.writeNew buildScript - let ``disable tests`` (d : DirectoryInfo) = + let ``disable tests`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let startPred = (fun (idx, line : string) -> line.Contains "let dotnetTest") - let endPred = (snd >> (fun (x : string) -> x.StartsWith "let ") >> not) + let startPred = (fun (idx, line: string) -> line.Contains "let dotnetTest") + + let endPred = + (snd + >> (fun (x: string) -> x.StartsWith "let ") + >> not) + match ``find section`` startPred endPred lines with | None -> () - | Some (startIdx, endIdx ) -> - ``replace section with`` (startIdx + 1) endIdx " ()" lines + | Some (startIdx, endIdx) -> + ``replace section with`` + (startIdx + + 1) + endIdx + " ()" + lines |> File.writeNew buildScript - - let ``disable generateCoverage`` (d : DirectoryInfo) = + let ``disable generateCoverage`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let startPred = (fun (idx, line : string) -> line.Contains "let generateCoverageReport") - let endPred = (snd >> (fun (x : string) -> x.StartsWith "let ") >> not) + + let startPred = + (fun (idx, line: string) -> line.Contains "let generateCoverageReport") + + let endPred = + (snd + >> (fun (x: string) -> x.StartsWith "let ") + >> not) + match ``find section`` startPred endPred lines with | None -> () - | Some (startIdx, endIdx ) -> - ``replace section with`` (startIdx + 1) endIdx " ()" lines + | Some (startIdx, endIdx) -> + ``replace section with`` + (startIdx + + 1) + endIdx + " ()" + lines |> File.writeNew buildScript - let ``disable createPackages`` (d : DirectoryInfo) = + let ``disable createPackages`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let startPred = (fun (idx, line : string) -> line.Contains "let createPackages") - let endPred = (snd >> (fun (x : string) -> x.StartsWith "let ") >> not) + let startPred = (fun (idx, line: string) -> line.Contains "let createPackages") + + let endPred = + (snd + >> (fun (x: string) -> x.StartsWith "let ") + >> not) + match ``find section`` startPred endPred lines with | None -> () - | Some (startIdx, endIdx ) -> - ``replace section with`` (startIdx + 1) endIdx " ()" lines + | Some (startIdx, endIdx) -> + ``replace section with`` + (startIdx + + 1) + endIdx + " ()" + lines |> File.writeNew buildScript - let ``disable dotnetPack`` (d : DirectoryInfo) = + let ``disable dotnetPack`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let startPred = (fun (idx, line : string) -> line.Contains "let dotnetPack") - let endPred = (snd >> (fun (x : string) -> x.StartsWith "let ") >> not) + let startPred = (fun (idx, line: string) -> line.Contains "let dotnetPack") + + let endPred = + (snd + >> (fun (x: string) -> x.StartsWith "let ") + >> not) + match ``find section`` startPred endPred lines with | None -> () - | Some (startIdx, endIdx ) -> - ``replace section with`` (startIdx + 1) endIdx " ()" lines + | Some (startIdx, endIdx) -> + ``replace section with`` + (startIdx + + 1) + endIdx + " ()" + lines |> File.writeNew buildScript - let ``disable sourceLinkTest function`` (d : DirectoryInfo) = + let ``disable sourceLinkTest function`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - match lines |> Array.tryFindIndex (fun line -> line.Contains "let sourceLinkTest") with + + match + lines + |> Array.tryFindIndex (fun line -> line.Contains "let sourceLinkTest") + with | None -> () | Some startIdx -> - let mutable i = startIdx+1 + let mutable i = + startIdx + + 1 + let mutable keepGoing = true - while keepGoing && i < Array.length lines do + + while keepGoing + && i < Array.length lines do if String.IsNullOrWhiteSpace lines.[i] then lines.[i] <- " ()" keepGoing <- false else - lines.[i] <- "// " + lines.[i] + lines.[i] <- + "// " + + lines.[i] + i <- i + 1 - lines |> File.writeNew buildScript - let ``disable publishToNuget function`` (d : DirectoryInfo) = + lines + |> File.writeNew buildScript + + let ``disable publishToNuget function`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - match lines |> Array.tryFindIndex (fun line -> line.Contains "Paket.push(") with + + match + lines + |> Array.tryFindIndex (fun line -> line.Contains "Paket.push(") + with | None -> () | Some startIdx -> let mutable i = startIdx let mutable keepGoing = true - while keepGoing && i < Array.length lines do + + while keepGoing + && i < Array.length lines do if lines.[i].Trim() = ")" then keepGoing <- false - // Then fall through to comment out this line, too - lines.[i] <- "// " + lines.[i] + // Then fall through to comment out this line, too + lines.[i] <- + "// " + + lines.[i] + i <- i + 1 - lines |> File.writeNew buildScript - let ``disable pushing in gitRelease function`` (d : DirectoryInfo) = + lines + |> File.writeNew buildScript + + let ``disable pushing in gitRelease function`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - match lines |> Array.tryFindIndex (fun line -> line.Contains "let gitRelease") with + + match + lines + |> Array.tryFindIndex (fun line -> line.Contains "let gitRelease") + with | None -> () | Some startIdx -> - let mutable i = startIdx + 1 + let mutable i = + startIdx + + 1 + let mutable keepGoing = true - while keepGoing && i < Array.length lines do + + while keepGoing + && i < Array.length lines do if lines.[i].StartsWith("let githubRelease") then keepGoing <- false - else - if lines.[i].Trim().StartsWith("Git.Branches.push") then - lines.[i] <- "// " + lines.[i] + else if lines.[i].Trim().StartsWith("Git.Branches.push") then + lines.[i] <- + "// " + + lines.[i] + i <- i + 1 - lines |> File.writeNew buildScript - let ``change githubRelease function to only run release checks`` (d : DirectoryInfo) = + lines + |> File.writeNew buildScript + + let ``change githubRelease function to only run release checks`` (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let githubReleaseStartIndexOpt = lines |> Array.tryFindIndex (fun line -> line.Contains "let githubRelease") + + let githubReleaseStartIndexOpt = + lines + |> Array.tryFindIndex (fun line -> line.Contains "let githubRelease") + let githubReleaseEndIndexOpt = githubReleaseStartIndexOpt |> Option.bind (fun startIndex -> lines |> Array.skip startIndex |> Array.tryFindIndex (fun line -> line.Contains "|> Async.RunSynchronously") - |> Option.map (fun endIndex -> endIndex + startIndex) + |> Option.map (fun endIndex -> + endIndex + + startIndex + ) ) match (githubReleaseStartIndexOpt, githubReleaseEndIndexOpt) with @@ -282,41 +447,64 @@ module Effect = |> File.writeNew buildScript | _ -> failwith "couldn't find bounds of `let githubRelease` function in build.fs" - let ``git init`` (d : DirectoryInfo) (branchName : string) = - Git.CommandHelper.runGitCommand d.FullName $"init --initial-branch={branchName}" |> ignore - Git.CommandHelper.runGitCommand d.FullName "config --local user.email nobody@example.org" |> ignore - Git.CommandHelper.runGitCommand d.FullName "config --local user.name TestUser" |> ignore + let ``git init`` (d: DirectoryInfo) (branchName: string) = + Git.CommandHelper.runGitCommand d.FullName $"init --initial-branch={branchName}" + |> ignore + + Git.CommandHelper.runGitCommand d.FullName "config --local user.email nobody@example.org" + |> ignore + + Git.CommandHelper.runGitCommand d.FullName "config --local user.name TestUser" + |> ignore - let ``git commit all`` message (d : DirectoryInfo) = + let ``git commit all`` message (d: DirectoryInfo) = Git.Staging.stageAll d.FullName Git.Commit.exec d.FullName message - let ``make build function fail`` (failureFunction : string) (d : DirectoryInfo) = + let ``make build function fail`` (failureFunction: string) (d: DirectoryInfo) = let buildScript = ``get build.fs`` d let lines = File.ReadAllLines buildScript - let idx = lines |> Array.findIndex (fun line -> line.Contains failureFunction) - let msg = sprintf " failwith \"Deliberate failure in unit test for %s\"\n" failureFunction - Array.insert msg (idx + 1) lines + + let idx = + lines + |> Array.findIndex (fun line -> line.Contains failureFunction) + + let msg = + sprintf " failwith \"Deliberate failure in unit test for %s\"\n" failureFunction + + Array.insert msg (idx + 1) lines // |> fun lines -> lines |> Seq.iter(printfn "%s") ; lines |> File.writeNew buildScript - let ``set environment variable`` name value (d : DirectoryInfo) = + let ``set environment variable`` name value (d: DirectoryInfo) = Environment.SetEnvironmentVariable(name, value) - let ``add change to CHANGELOG`` (d : DirectoryInfo) = + let ``add change to CHANGELOG`` (d: DirectoryInfo) = let changelog = Path.combine d.FullName "CHANGELOG.md" let lines = File.ReadAllLines changelog - match lines |> Array.tryFindIndex (fun line -> line.Contains "## [Unreleased]") with + + match + lines + |> Array.tryFindIndex (fun line -> line.Contains "## [Unreleased]") + with | None -> () | Some startIdx -> let newLines = lines - |> Array.insert "### Changed" (startIdx + 1) - |> Array.insert "- This is a test change from (@TheAngryByrd)" (startIdx + 2) - newLines |> File.writeNew changelog - - let private ``internal setup for release tests`` (branchName : string) (d : DirectoryInfo) = + |> Array.insert + "### Changed" + (startIdx + + 1) + |> Array.insert + "- This is a test change from (@TheAngryByrd)" + (startIdx + + 2) + + newLines + |> File.writeNew changelog + + let private ``internal setup for release tests`` (branchName: string) (d: DirectoryInfo) = ``git init`` d branchName ``disable restore`` d ``disable build`` d @@ -334,8 +522,8 @@ module Effect = ``set environment variable`` "GITHUB_TOKEN" "" d ``add change to CHANGELOG`` d - let ``setup for release tests`` (d : DirectoryInfo) = + let ``setup for release tests`` (d: DirectoryInfo) = ``internal setup for release tests`` "main" d - let ``setup for branch tests`` (branchName : string) (d : DirectoryInfo) = + let ``setup for branch tests`` (branchName: string) (d: DirectoryInfo) = ``internal setup for release tests`` branchName d diff --git a/tests/MiniScaffold.Tests/Infrastructure.fs b/tests/MiniScaffold.Tests/Infrastructure.fs index 6773897e..a49c78a4 100644 --- a/tests/MiniScaffold.Tests/Infrastructure.fs +++ b/tests/MiniScaffold.Tests/Infrastructure.fs @@ -1,52 +1,67 @@ namespace Infrastructure - module Dotnet = open Fake.Core open Fake.DotNet - let failOnBadExitAndPrint (p : ProcessResult) = - if p.ExitCode <> 0 then - p.Errors |> Seq.iter Trace.traceError + + let failOnBadExitAndPrint (p: ProcessResult) = + if + p.ExitCode + <> 0 + then + p.Errors + |> Seq.iter Trace.traceError + failwithf "failed with exitcode %d" p.ExitCode module New = - let cmd (opt : DotNet.Options -> DotNet.Options) args = + let cmd (opt: DotNet.Options -> DotNet.Options) args = printfn "dotnet new %s" args // let args = args |> String.concat " " DotNet.exec opt "new" args |> failOnBadExitAndPrint + let install name = let args = Arguments.Empty |> Arguments.appendNotEmpty "-i" name - // |> Arguments.appendRaw "--dev:install" + // |> Arguments.appendRaw "--dev:install" // |> // let args = [ // sprintf "-i \"%s\"" name // ] cmd id args.ToStartInfo + let uninstall name = let args = Arguments.Empty |> Arguments.appendNotEmpty "-u" name + cmd id args.ToStartInfo module Disposables = open System - let dispose (disposable : #IDisposable) = disposable.Dispose() + let dispose (disposable: #IDisposable) = disposable.Dispose() [] - type DisposableDirectory (directory : string) = + type DisposableDirectory(directory: string) = static member Create() = - let tempPath = IO.Path.Combine(IO.Path.GetTempPath(), IO.Path.GetFileNameWithoutExtension(IO.Path.GetTempFileName())) - IO.Directory.CreateDirectory tempPath |> ignore + let tempPath = + IO.Path.Combine( + IO.Path.GetTempPath(), + IO.Path.GetFileNameWithoutExtension(IO.Path.GetTempFileName()) + ) + + IO.Directory.CreateDirectory tempPath + |> ignore new DisposableDirectory(tempPath) + member x.Directory = directory member x.DirectoryInfo = IO.DirectoryInfo(directory) @@ -54,20 +69,27 @@ module Disposables = member x.Dispose() = // Git objects are created read-only, so on Windows we have to mark them read-write before deleting them x.DirectoryInfo.EnumerateFiles("*", IO.SearchOption.AllDirectories) - |> Seq.iter (fun fileInfo -> if fileInfo.IsReadOnly then fileInfo.IsReadOnly <- false) + |> Seq.iter (fun fileInfo -> + if fileInfo.IsReadOnly then + fileInfo.IsReadOnly <- false + ) + IO.Directory.Delete(x.Directory, true) module Builds = open Fake.Core + let executeBuild workingDir testTarget = let cmd, args = if Environment.isUnix then - "bash", [ + "bash", + [ sprintf "./build.sh" testTarget ] else - "cmd.exe", [ + "cmd.exe", + [ "/c" ".\\build.cmd" testTarget @@ -78,4 +100,5 @@ module Builds = |> CreateProcess.withWorkingDirectory workingDir |> CreateProcess.ensureExitCode |> Proc.run + () diff --git a/tests/MiniScaffold.Tests/Tests.fs b/tests/MiniScaffold.Tests/Tests.fs index 91119837..ac89054d 100755 --- a/tests/MiniScaffold.Tests/Tests.fs +++ b/tests/MiniScaffold.Tests/Tests.fs @@ -1,34 +1,41 @@ namespace MiniScaffold.Tests - module Tests = open System open Fake.Core open Expecto open Infrastructure - let ptestCase (reason : string) name test = Expecto.Tests.ptestCase name test + let ptestCase (reason: string) name test = Expecto.Tests.ptestCase name test let logger = Expecto.Logging.Log.create "setup" - let nugetPkgName = "MiniScaffold" + let nugetPkgName = "MiniScaffold" let templateName = "mini-scaffold" + let nugetPkgPath = match Environment.environVarOrNone "MINISCAFFOLD_NUPKG_LOCATION" with | Some v -> printfn "using MINISCAFFOLD_NUPKG_LOCATION" v | None -> - let dist = IO.Path.Combine(__SOURCE_DIRECTORY__, "../../dist") |> IO.DirectoryInfo + let dist = + IO.Path.Combine(__SOURCE_DIRECTORY__, "../../dist") + |> IO.DirectoryInfo + dist.EnumerateFiles("*.nupkg") |> Seq.head |> fun fi -> fi.FullName let debug () = - if not(System.Diagnostics.Debugger.IsAttached) then - printfn "Please attach a debugger, PID: %d" (System.Diagnostics.Process.GetCurrentProcess().Id) - while not(System.Diagnostics.Debugger.IsAttached) do + if not (System.Diagnostics.Debugger.IsAttached) then + printfn + "Please attach a debugger, PID: %d" + (System.Diagnostics.Process.GetCurrentProcess().Id) + + while not (System.Diagnostics.Debugger.IsAttached) do System.Threading.Thread.Sleep(100) + System.Diagnostics.Debugger.Break() () @@ -39,20 +46,34 @@ module Tests = templateName "--help" ] + let opts = match directory with - | Some d -> (fun (opt : Fake.DotNet.DotNet.Options) -> { opt with WorkingDirectory = d}) + | Some d -> (fun (opt: Fake.DotNet.DotNet.Options) -> { opt with WorkingDirectory = d }) | None -> id - Fake.DotNet.DotNet.getVersion (fun vOpt -> vOpt.WithCommon opts) |> printfn "dotnet --version %s" + + Fake.DotNet.DotNet.getVersion (fun vOpt -> vOpt.WithCommon opts) + |> printfn "dotnet --version %s" + Dotnet.New.cmd opts newArgs.ToStartInfo + let setup () = // debug () // ensure we're installing the one from our dist folder printfn "nugetPkgPath %s" nugetPkgPath - Fake.DotNet.DotNet.getSDKVersionFromGlobalJson () |> printfn "dotnet global.json version %s" - Fake.DotNet.DotNet.getVersion id |> printfn "dotnet --version %s" + + Fake.DotNet.DotNet.getSDKVersionFromGlobalJson () + |> printfn "dotnet global.json version %s" + + Fake.DotNet.DotNet.getVersion id + |> printfn "dotnet --version %s" + printfn "Uninstalling template..." - try Dotnet.New.uninstall nugetPkgName with e -> printfn "Uninstall failing is fine: %A" e + + try + Dotnet.New.uninstall nugetPkgName + with e -> + printfn "Uninstall failing is fine: %A" e printfn "Installing template..." Dotnet.New.install nugetPkgPath @@ -63,15 +84,19 @@ module Tests = let runTemplate (directory) args = let newArgs = Arguments.Empty - |> Arguments.append [ - templateName - ] + |> Arguments.append [ templateName ] // |> Arguments.appendNotEmpty "-lang" "F#" |> Arguments.appendRaw args - Dotnet.New.cmd (fun opt -> { opt with WorkingDirectory = directory}) newArgs.ToStartInfo + Dotnet.New.cmd + (fun opt -> + { opt with + WorkingDirectory = directory + } + ) + newArgs.ToStartInfo - let copyGlobalJson (directory : IO.DirectoryInfo) = + let copyGlobalJson (directory: IO.DirectoryInfo) = let globalJson = IO.Path.Join(__SOURCE_DIRECTORY__, "../../global.json") let destination = IO.Path.Join(directory.FullName, "global.json") IO.File.Copy(globalJson, destination) @@ -95,202 +120,258 @@ module Tests = [] let tests = - testSequenced <| // uncomment to get better logs + testSequenced + <| // uncomment to get better logs testList "samples" [ do setup () - yield! [ - testCase, "-n MyCoolLib --githubUsername CoolPersonNo2", [ - yield! projectStructureAsserts - Assert.``project can build target`` "DotnetPack" - Assert.``project can build target`` "BuildDocs" + yield! + [ + testCase, + "-n MyCoolLib --githubUsername CoolPersonNo2", + [ + yield! projectStructureAsserts + Assert.``project can build target`` "DotnetPack" + Assert.``project can build target`` "BuildDocs" ] - // test for dashes in name https://github.com/dotnet/templating/issues/1168#issuecomment-364592031 - testCase, "-n fsharp-data-sample --githubUsername CoolPersonNo2", [ - yield! projectStructureAsserts - Assert.``project can build target`` "DotnetPack" + // test for dashes in name https://github.com/dotnet/templating/issues/1168#issuecomment-364592031 + testCase, + "-n fsharp-data-sample --githubUsername CoolPersonNo2", + [ + yield! projectStructureAsserts + Assert.``project can build target`` "DotnetPack" ] - testCase, "-n MyCoolApp --githubUsername CoolPersonNo2 --outputType Console", [ - yield! projectStructureAsserts - Assert.``project can build target`` "CreatePackages" + testCase, + "-n MyCoolApp --githubUsername CoolPersonNo2 --outputType Console", + [ + yield! projectStructureAsserts + Assert.``project can build target`` "CreatePackages" ] - // Test that CHANGELOG.md is not modified during build failures, - // *unless* at least one step has pushed a release to the outside world. - testCase, "-n DotnetRestoreFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let dotnetRestore" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + // Test that CHANGELOG.md is not modified during build failures, + // *unless* at least one step has pushed a release to the outside world. + testCase, + "-n DotnetRestoreFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let dotnetRestore" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n AssemblyInfoFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let generateAssemblyInfo" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n AssemblyInfoFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let generateAssemblyInfo" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n DotnetBuildFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let dotnetBuild" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n DotnetBuildFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let dotnetBuild" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n DotnetTestFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let dotnetTest" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n DotnetTestFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let dotnetTest" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n CoverageReportFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let generateCoverageReport" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n CoverageReportFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let generateCoverageReport" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n DotnetPackFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let dotnetPack" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n DotnetPackFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let dotnetPack" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - ptestCase "SourceLinkTests aren't working since the testing tool is very out of date", "-n SourceLinkTestFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let sourceLinkTest" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + ptestCase + "SourceLinkTests aren't working since the testing tool is very out of date", + "-n SourceLinkTestFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let sourceLinkTest" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n PublishToNugetFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let publishToNuget" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n PublishToNugetFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let publishToNuget" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase ,"-n PublishToNugetSuccess --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset - Assert.``CHANGELOG contains Unreleased section`` - Assert.``project can build target`` "PublishToNuget" - // Since the PublishToNuget step "succeeded", we no longer revert the changelog from that point on - Assert.``CHANGELOG does not contain Unreleased section`` + testCase, + "-n PublishToNugetSuccess --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset + Assert.``CHANGELOG contains Unreleased section`` + Assert.``project can build target`` "PublishToNuget" + // Since the PublishToNuget step "succeeded", we no longer revert the changelog from that point on + Assert.``CHANGELOG does not contain Unreleased section`` ] - testCase ,"-n GitReleaseFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset - Effect.``make build function fail`` "gitRelease" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - // Since the PublishToNuget step "succeeded", we no longer revert the changelog from that point on - Assert.``CHANGELOG does not contain Unreleased section`` + testCase, + "-n GitReleaseFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset + Effect.``make build function fail`` "gitRelease" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + // Since the PublishToNuget step "succeeded", we no longer revert the changelog from that point on + Assert.``CHANGELOG does not contain Unreleased section`` ] - testCase, "-n GitHubReleaseFail --githubUsername TestAccount", [ - Effect.``setup for release tests`` - Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset - Effect.``make build function fail`` "githubRelease" - Effect.``disable pushing in gitRelease function`` - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - // Since the PublishToNuget step "succeeded", we no longer revert the changelog from that point on - Assert.``CHANGELOG does not contain Unreleased section`` + testCase, + "-n GitHubReleaseFail --githubUsername TestAccount", + [ + Effect.``setup for release tests`` + Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset + Effect.``make build function fail`` "githubRelease" + Effect.``disable pushing in gitRelease function`` + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + // Since the PublishToNuget step "succeeded", we no longer revert the changelog from that point on + Assert.``CHANGELOG does not contain Unreleased section`` ] - testCase, "-n DotnetRestoreFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let dotnetRestore" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n DotnetRestoreFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let dotnetRestore" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n AssemblyInfoFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let generateAssemblyInfo" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n AssemblyInfoFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let generateAssemblyInfo" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n DotnetBuildFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let dotnetBuild" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n DotnetBuildFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let dotnetBuild" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n DotnetTestFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let dotnetTest" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n DotnetTestFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let dotnetTest" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase,"-n CoverageReportFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let generateCoverageReport" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n CoverageReportFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let generateCoverageReport" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n CreatePackagesFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let createPackages" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n CreatePackagesFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let createPackages" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n GitReleaseFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let gitRelease" - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - Assert.``CHANGELOG contains Unreleased section`` + testCase, + "-n GitReleaseFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let gitRelease" + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + Assert.``CHANGELOG contains Unreleased section`` ] - testCase, "-n GitHubReleaseFail --githubUsername TestAccount --outputType Console", [ - Effect.``setup for release tests`` - Effect.``make build function fail`` "let githubRelease" - Effect.``disable pushing in gitRelease function`` - Assert.``CHANGELOG contains Unreleased section`` - Assert.``build target with failure expected`` "Release" - // Since the GitRelease step "succeeded", we no longer revert the changelog from that point on - Assert.``CHANGELOG does not contain Unreleased section`` + testCase, + "-n GitHubReleaseFail --githubUsername TestAccount --outputType Console", + [ + Effect.``setup for release tests`` + Effect.``make build function fail`` "let githubRelease" + Effect.``disable pushing in gitRelease function`` + Assert.``CHANGELOG contains Unreleased section`` + Assert.``build target with failure expected`` "Release" + // Since the GitRelease step "succeeded", we no longer revert the changelog from that point on + Assert.``CHANGELOG does not contain Unreleased section`` ] - // Try to run a release on an alternate release branch name. - testCase, "-n AlternateReleaseBranch --githubUsername TestAccount --releaseBranch alternateBranch", [ - Effect.``setup for branch tests`` "alternateBranch" - Effect.``disable pushing in gitRelease function`` - Effect.``change githubRelease function to only run release checks`` - Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset - Assert.``project can build target`` "Release" - ] + // Try to run a release on an alternate release branch name. + testCase, + "-n AlternateReleaseBranch --githubUsername TestAccount --releaseBranch alternateBranch", + [ + Effect.``setup for branch tests`` "alternateBranch" + Effect.``disable pushing in gitRelease function`` + Effect.``change githubRelease function to only run release checks`` + Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset + Assert.``project can build target`` "Release" + ] + + // This should fail since the release branch specified in the build script doesn't match the + // branch from which the script is executed. + testCase, + "-n ReleaseBranchMissingFailure --githubUsername TestAccount --releaseBranch notExist", + [ + Effect.``setup for branch tests`` "anotherBranch" + Effect.``disable pushing in gitRelease function`` + Effect.``change githubRelease function to only run release checks`` + Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset + Assert.``build target with failure expected`` "Release" + ] - // This should fail since the release branch specified in the build script doesn't match the - // branch from which the script is executed. - testCase, "-n ReleaseBranchMissingFailure --githubUsername TestAccount --releaseBranch notExist", [ - Effect.``setup for branch tests`` "anotherBranch" - Effect.``disable pushing in gitRelease function`` - Effect.``change githubRelease function to only run release checks`` - Effect.``disable publishToNuget function`` // Simulates success, since it would fail due to NUGET_API being unset - Assert.``build target with failure expected`` "Release" ] + |> Seq.map (fun (testCase, args, additionalAsserts) -> + testCase args + <| fun _ -> + use d = Disposables.DisposableDirectory.Create() + copyGlobalJson d.DirectoryInfo - ] |> Seq.map(fun (testCase, args, additionalAsserts) -> testCase args <| fun _ -> - use d = Disposables.DisposableDirectory.Create() - copyGlobalJson d.DirectoryInfo - showTemplateHelp <| Some d.Directory + showTemplateHelp + <| Some d.Directory - runTemplate d.Directory args + runTemplate d.Directory args - // The project we just generated is the only one in here - let projectDir = - d.DirectoryInfo.GetDirectories () - |> Seq.head + // The project we just generated is the only one in here + let projectDir = + d.DirectoryInfo.GetDirectories() + |> Seq.head - additionalAsserts - |> Seq.iter(fun asserter -> asserter projectDir) - ) + additionalAsserts + |> Seq.iter (fun asserter -> asserter projectDir) + ) ]