Skip to content

Commit

Permalink
Merge branch 'release/next' into sonarscanner
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid authored Dec 17, 2019
2 parents f2c33da + b5622f7 commit 06d7e74
Show file tree
Hide file tree
Showing 14 changed files with 1,556 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mono:

script:
- dotnet tool restore
- dotnet fake build
- dotnet fake build --parallel 3

branches:
except:
Expand Down
5 changes: 4 additions & 1 deletion Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{03CB61B6-EBB8-4C4A-B6A3-0D84D1F78A92}"
ProjectSection(SolutionItems) = preProject
.gitlab-ci.yml = .gitlab-ci.yml
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
build.fsx = build.fsx
global.json = global.json
legacy-build.fsx = legacy-build.fsx
paket.dependencies = paket.dependencies
paket.lock = paket.lock
Expand Down Expand Up @@ -181,7 +184,7 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.Xdt", "src\app\
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.Testing.Coverlet", "src\app\Fake.DotNet.Testing.Coverlet\Fake.DotNet.Testing.Coverlet.fsproj", "{664A121E-17A2-453E-BC2E-1C59A67875D2}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.ExpectoSupport", "src\test\Fake.ExpectoSupport\Fake.ExpectoSupport.fsproj", "{D063FC91-8F84-406D-AA48-9E946B7E4323}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.ExpectoSupport", "src\test\Fake.ExpectoSupport\Fake.ExpectoSupport.fsproj", "{D063FC91-8F84-406D-AA48-9E946B7E4323}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion help/content/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ a i.fa {

footer {
position: relative;
z-index: 99;
z-index: 98;
}

footer ul li {
Expand Down
8 changes: 5 additions & 3 deletions help/content/assets/js/bulma.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ function generateTableOfContent() {
menuHtml += `<ul class="menu-list"><li><a href="${href}">${heading.innerText}</a>`;
levels++;
} else if (currentHeadingCount < headingNumber) {
// decrease level
menuHtml += `</li></ul><li><a href="${href}">${heading.innerText}</a>`;
levels--;
// decrease level, could go down more than one level (say a previous section ends with h4 and a new section starts with h2)
let headingNumDif = headingNumber - currentHeadingCount;
for (let d = 0; d < headingNumDif; d++) { menuHtml += "</li></ul>" }
menuHtml += `<li><a href="${href}">${heading.innerText}</a>`;
levels-=headingNumDif;
} else if (currentHeadingCount == headingNumber) {
// same level
menuHtml += `</li><li><a href="${href}">${heading.innerText}</a>`;
Expand Down
2 changes: 1 addition & 1 deletion help/markdown/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ For FAKE development, [Visual Studio Code](https://code.visualstudio.com/Downloa

- JetBrains Rider [[download](https://www.jetbrains.com/rider/download)]
- Visual Studio for Mac [[download](https://visualstudio.microsoft.com/vs/mac/)]
- Visual Studio for Windows [[download](https://www.jetbrains.com/rider/download)]
- Visual Studio for Windows [[download](https://visualstudio.microsoft.com/vs/)]


### Install FAKE
Expand Down
38 changes: 29 additions & 9 deletions src/app/Fake.Core.Target/Target.fs
Original file line number Diff line number Diff line change
Expand Up @@ -748,14 +748,18 @@ module Target =
waitList <- []
reply.Reply (async.Return(ctx, None))
else
let isRunnable (t:Target) =
not (known.ContainsKey (String.toLower t.Name)) && // not already finised
not (runningTasks |> Seq.exists (fun r -> String.toLower r.Name = String.toLower t.Name)) && // not already running
t.Dependencies @ List.filter inResolution t.SoftDependencies // all dependencies finished
|> Seq.forall (String.toLower >> known.ContainsKey)
let runnable =
let calculateOpenTargets() =
let isOpen (t:Target) =
not (known.ContainsKey (String.toLower t.Name)) && // not already finised
not (runningTasks |> Seq.exists (fun r -> String.toLower r.Name = String.toLower t.Name)) // not already running
order
|> Seq.concat
|> Seq.filter isOpen
let runnable =
let isRunnable (t:Target) =
t.Dependencies @ List.filter inResolution t.SoftDependencies // all dependencies finished
|> Seq.forall (String.toLower >> known.ContainsKey)
calculateOpenTargets()
|> Seq.filter isRunnable
|> Seq.toList

Expand Down Expand Up @@ -784,9 +788,25 @@ module Target =
// queue work
let tcs = new TaskCompletionSource<TargetContext * Target option>()
let running = System.String.Join(", ", runningTasks |> Seq.map (fun t -> sprintf "'%s'" t.Name))
let openList = System.String.Join(", ", runnable |> Seq.map (fun t -> sprintf "'%s'" t.Name))
Trace.tracefn "FAKE worker idle because %d Targets (%s) are still running and all open targets (%s) depend on those. You might improve performance by splitting targets or removing dependencies."
runningTasks.Length running openList
// recalculate openTargets as getNextFreeRunableTarget could change runningTasks
let openTargets = calculateOpenTargets() |> Seq.toList
let orderedOpen =
let isDependencyResolved =
String.toLower >> known.ContainsKey
let isDependencyRunning t =
runningTasks
|> Seq.exists (fun running -> String.toLower running.Name = t)
let isDependencyResolvedOrRunning t = isDependencyResolved t || isDependencyRunning t
openTargets
|> List.sortBy (fun t ->
t.Dependencies @ List.filter inResolution t.SoftDependencies // Order by unresolved dependencies
|> Seq.filter (isDependencyResolvedOrRunning >> not)
|> Seq.length)
let openList =
System.String.Join(", ", orderedOpen :> seq<_> |> (if orderedOpen.Length > 3 then Seq.take 3 else id) |> Seq.map (fun t -> sprintf "'%s'" t.Name))
+ (if orderedOpen.Length > 3 then ", ..." else "")
Trace.tracefn "FAKE worker idle because '%d' targets (%s) are still running and all ('%d') open targets (%s) depend on those. You might improve performance by splitting targets or removing dependencies."
runningTasks.Length running openTargets.Length openList
waitList <- waitList @ [ tcs ]
reply.Reply (tcs.Task |> Async.AwaitTask)
with e ->
Expand Down
6 changes: 4 additions & 2 deletions src/test/Fake.Core.CommandLine.UnitTests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ open System
let main argv =
let writeResults = TestResults.writeNUnitSummary ("Fake_Core_CommandLine_UnitTests.TestResults.xml", "Fake.Core.CommandLine.UnitTests")
let config =
defaultConfig.appendSummaryHandler writeResults
defaultConfig
|> ExpectoHelpers.addTimeout (TimeSpan.FromMinutes(20.))
|> ExpectoHelpers.setFakePrinter
|> ExpectoHelpers.appendSummaryHandler writeResults

Tests.runTestsInAssembly { config with parallel = false } argv
Expecto.Tests.runTestsInAssembly { config with parallel = false } argv
7 changes: 5 additions & 2 deletions src/test/Fake.Core.IntegrationTests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ open System
let main argv =
let writeResults = TestResults.writeNUnitSummary ("Fake_Core_IntegrationTests.TestResults.xml", "Fake.Core.IntegrationTests")
let config =
defaultConfig.appendSummaryHandler writeResults
defaultConfig
|> ExpectoHelpers.addTimeout (TimeSpan.FromMinutes(20.))
Tests.runTestsInAssembly { config with parallel = false } argv
|> ExpectoHelpers.setFakePrinter
|> ExpectoHelpers.appendSummaryHandler writeResults

Expecto.Tests.runTestsInAssembly { config with parallel = false } argv
1 change: 1 addition & 0 deletions src/test/Fake.Core.UnitTests/Fake.Core.UnitTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<ProjectReference Include="..\Fake.ExpectoSupport\Fake.ExpectoSupport.fsproj" />
</ItemGroup>
<ItemGroup>
<Content Include="runtimeconfig.template.json" />
<None Include="paket.references" />
<Compile Include="Fake.ContextHelper.fs" />
<Compile Include="Fake.Testing.ArgumentHelper.fs" />
Expand Down
6 changes: 4 additions & 2 deletions src/test/Fake.Core.UnitTests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ open Fake.ExpectoSupport
let main argv =
let writeResults = TestResults.writeNUnitSummary ("Fake_Core_UnitTests.TestResults.xml", "Fake.Core.UnitTests")
let config =
defaultConfig.appendSummaryHandler writeResults
defaultConfig
|> ExpectoHelpers.addTimeout (TimeSpan.FromMinutes(20.))
Tests.runTestsInAssembly config argv
|> ExpectoHelpers.setFakePrinter
|> ExpectoHelpers.appendSummaryHandler writeResults
Expecto.Tests.runTestsInAssembly config argv
7 changes: 5 additions & 2 deletions src/test/Fake.DotNet.Cli.IntegrationTests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ open System
let main argv =
let writeResults = TestResults.writeNUnitSummary ("Fake_DotNet_Cli_IntegrationTests.TestResults.xml", "Fake.DotNet.Cli.IntegrationTests")
let config =
defaultConfig.appendSummaryHandler writeResults
defaultConfig
|> ExpectoHelpers.addTimeout (TimeSpan.FromMinutes(20.))
Tests.runTestsInAssembly { config with parallel = false } argv
|> ExpectoHelpers.setFakePrinter
|> ExpectoHelpers.appendSummaryHandler writeResults

Expecto.Tests.runTestsInAssembly { config with parallel = false } argv
116 changes: 98 additions & 18 deletions src/test/Fake.ExpectoSupport/ExpectoHelpers.fs
Original file line number Diff line number Diff line change
@@ -1,47 +1,127 @@
namespace Fake.ExpectoSupport
open Expecto

open System
open System.Threading
open System.Threading.Tasks

module ExpectoHelpers =
let addFilter f (config:Impl.ExpectoConfig) =

let inline internal commaString (i:int) = i.ToString("#,##0")
// because of https://github.com/haf/expecto/issues/367
let fakeDefaultPrinter : Expecto.Impl.TestPrinters =
{ beforeRun = fun _tests ->
printfn "EXPECTO? Running tests..."
async.Zero()

beforeEach = fun n ->
printfn "EXPECTO? %s starting..." n
async.Zero()

info = fun s ->
printfn "EXPECTO? %s" s
async.Zero()

passed = fun n d ->
printfn "EXPECTO? %s passed in %O." n d
async.Zero()

ignored = fun n m ->
printfn "EXPECTO? %s was ignored. %s" n m
async.Zero()

failed = fun n m d ->
printfn "EXPECTO? %s failed in %O. %s" n d m
async.Zero()

exn = fun n e d ->
printfn "EXPECTO? %s errored in %O: %O" n d e
async.Zero()

summary = fun _config summary ->
let spirit =
if summary.successful then "Success!" else String.Empty
let commonAncestor =
let rec loop ancestor (descendants : string list) =
match descendants with
| [] -> ancestor
| hd::tl when hd.StartsWith(ancestor)->
loop ancestor tl
| _ ->
if ancestor.Contains("/") then
loop (ancestor.Substring(0, ancestor.LastIndexOf "/")) descendants
else
"miscellaneous"

let parentNames =
summary.results
|> List.map (fun (flatTest, _) ->
if flatTest.name.Contains("/") then
flatTest.name.Substring(0, flatTest.name.LastIndexOf "/")
else
flatTest.name )

match parentNames with
| [x] -> x
| hd::tl ->
loop hd tl
| _ -> "miscellaneous" //we can't get here
printfn "EXPECTO! %s tests run in %O for %s%s passed, %s ignored, %s failed, %s errored. %s"
(summary.results |> List.sumBy (fun (_,r) -> if r.result.isIgnored then 0 else r.count) |> commaString)
summary.duration
commonAncestor
(summary.passed |> List.sumBy (fun (_,r) -> r.count) |> commaString)
(summary.ignored |> List.sumBy (fun (_,r) -> r.count) |> commaString)
(summary.failed |> List.sumBy (fun (_,r) -> r.count) |> commaString)
(summary.errored |> List.sumBy (fun (_,r) -> r.count) |> commaString)
spirit
async.Zero()
}

let setPrinter printer (config:Expecto.Impl.ExpectoConfig) =
{ config with printer = printer }
let setFakePrinter (config:Expecto.Impl.ExpectoConfig) =
setPrinter fakeDefaultPrinter config

let appendSummaryHandler summaryPrinter (config:Expecto.Impl.ExpectoConfig) =
config.appendSummaryHandler summaryPrinter

let addFilter f (config:Expecto.Impl.ExpectoConfig) =
{ config with
filter = fun test ->
let filteredTests = config.filter test
f filteredTests }

let withTimeout (timeout:TimeSpan) (labelPath:string) (test: TestCode) : TestCode =
let withTimeout (timeout:TimeSpan) (labelPath:string) (test: Expecto.TestCode) : Expecto.TestCode =
let timeoutAsync testAsync =
async {
let t = Async.StartAsTask(testAsync)
let delay = Task.Delay(timeout)
let! result = Task.WhenAny(t, delay) |> Async.AwaitTask
if result = delay then
Tests.failtestf "Test '%s' timed out" labelPath
Expecto.Tests.failtestf "Test '%s' timed out" labelPath
}

match test with
| Sync test -> async { test() } |> timeoutAsync |> Async
| SyncWithCancel test ->
SyncWithCancel (fun ct ->
| Expecto.Sync test -> async { test() } |> timeoutAsync |> Expecto.Async
| Expecto.SyncWithCancel test ->
Expecto.SyncWithCancel (fun ct ->
Async.StartImmediate(async { test ct } |> timeoutAsync)
)
| Async test -> timeoutAsync test |> Async
| AsyncFsCheck (testConfig, stressConfig, test) ->
AsyncFsCheck (testConfig, stressConfig, test >> timeoutAsync)
| Expecto.Async test -> timeoutAsync test |> Expecto.Async
| Expecto.AsyncFsCheck (testConfig, stressConfig, test) ->
Expecto.AsyncFsCheck (testConfig, stressConfig, test >> timeoutAsync)

let mapTest f test =
let rec recMapping labelPath test =
match test with
| TestCase (code:TestCode, state:FocusState) ->
TestCase(f labelPath code, state)
| TestList (tests:Test list, state:FocusState) ->
TestList (tests |> List.map (recMapping labelPath), state)
| TestLabel (label:string, test:Test, state:FocusState) ->
TestLabel(label, recMapping (labelPath + "/" + label) test, state)
| Test.Sequenced (sequenceMethod, test) ->
Test.Sequenced(sequenceMethod, recMapping labelPath test)
| Expecto.TestCase (code:Expecto.TestCode, state:Expecto.FocusState) ->
Expecto.TestCase(f labelPath code, state)
| Expecto.TestList (tests:Expecto.Test list, state:Expecto.FocusState) ->
Expecto.TestList (tests |> List.map (recMapping labelPath), state)
| Expecto.TestLabel (label:string, test:Expecto.Test, state:Expecto.FocusState) ->
Expecto.TestLabel(label, recMapping (labelPath + "/" + label) test, state)
| Expecto.Test.Sequenced (sequenceMethod, test) ->
Expecto.Test.Sequenced(sequenceMethod, recMapping labelPath test)

recMapping "" test

Expand Down
4 changes: 2 additions & 2 deletions src/test/Fake.ExpectoSupport/Fake.ExpectoSupport.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="FakeExpecto.fs" />
<None Include="paket.references" />
<Compile Include="ExpectoHelpers.fs" />
<Compile Include="FakeExpecto.fs" />
</ItemGroup>

<ItemGroup />
<Import Project="..\..\..\.paket\Paket.Restore.targets" />

</Project>
Loading

0 comments on commit 06d7e74

Please sign in to comment.