-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fake.DotNet.Testing.Expecto #1871
Changes from 4 commits
a0913ac
8405a16
4e1d06b
9325320
9244db3
4be412a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Auto-Generated by FAKE; do not edit | ||
namespace System | ||
open System.Reflection | ||
|
||
[<assembly: AssemblyTitleAttribute("FAKE - F# Make Running Expecto test runner")>] | ||
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>] | ||
[<assembly: AssemblyVersionAttribute("5.0.0")>] | ||
[<assembly: AssemblyInformationalVersionAttribute("5.0.0-beta025")>] | ||
[<assembly: AssemblyFileVersionAttribute("5.0.0")>] | ||
do () | ||
|
||
module internal AssemblyVersionInformation = | ||
let [<Literal>] AssemblyTitle = "FAKE - F# Make Running Expecto test runner" | ||
let [<Literal>] AssemblyProduct = "FAKE - F# Make" | ||
let [<Literal>] AssemblyVersion = "5.0.0" | ||
let [<Literal>] AssemblyInformationalVersion = "5.0.0-beta025" | ||
let [<Literal>] AssemblyFileVersion = "5.0.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/// Contains tasks to run [Expecto](https://github.com/haf/expecto) unit tests. | ||
module Fake.DotNet.Testing.Expecto | ||
|
||
open Fake.Core | ||
open Fake.Core.Environment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think more than happened to I now get this runtime error
I had to change env variable handling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was introduced somewhere in the beta phase. This will prevent incorrect usage of the API. Basically you almost always want to inherit the default environment variables, but you replaced them with your own map -> this error occurs. |
||
open Fake.Core.StringBuilder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
open Fake.Testing.Common | ||
open System | ||
|
||
/// CLI parameters available if you use Tests.runTestsInAssembly defaultConfig argv in your code: | ||
type ExpectoParams = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it is part of the
What do you think? We probably even should have some guideline around this and make it more uniform in fake 6 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shortening to Params. |
||
{ | ||
/// Extra verbose output for your tests. | ||
Debug : bool | ||
/// Run all tests in parallel. Default is true. | ||
Parallel : bool | ||
/// Number of parallel workers (defaults to the number of logical processors). | ||
ParallelWorkers : int | ||
/// Prints out summary after all tests are finished. | ||
Summary : bool | ||
/// Prints out summary after all tests are finished including their source code location. | ||
SummaryLocation : bool | ||
/// Fails the build if focused tests exist. Default is true | ||
FailOnFocusedTests : bool | ||
/// Filter a specific hierarchy to run. | ||
Filter : string | ||
/// Filter a specific test case to run. | ||
FilterTestCase : string | ||
/// Filter a specific test list to run. | ||
FilterTestList : string | ||
/// Run only provided tests. | ||
Run : string list | ||
/// Doesn't run tests, print out list of tests instead. | ||
ListTests : bool | ||
/// Custom arguments to use in the case the helper not yet supports them | ||
CustomArgs: string list | ||
/// Prints the version on startup. Default is true | ||
PrintVersion : bool | ||
/// Working directory | ||
WorkingDirectory : string | ||
} | ||
|
||
override this.ToString() = | ||
let append (s: string) (sb: StringBuilder) = sb.Append s | ||
let appendIfTrue value s sb = | ||
if value then append s sb else sb | ||
let appendIfNotNullOrWhiteSpace value s (sb: StringBuilder) = | ||
if String.IsNullOrWhiteSpace value |> not | ||
then sprintf "%s%s " s value |> sb.Append | ||
else sb | ||
let appendIfNotEqual other value s (sb: StringBuilder) = | ||
if other = value | ||
then sprintf "%s%A " s value |> sb.Append | ||
else sb | ||
let appendList list s (sb: StringBuilder) = | ||
let filtered = list |> List.filter (String.IsNullOrWhiteSpace >> not) | ||
if List.isEmpty filtered then sb | ||
else | ||
filtered |> String.separated " " |> sprintf "%s%s " s |> sb.Append | ||
StringBuilder() | ||
|> appendIfTrue this.Debug "--debug " | ||
|> appendIfTrue this.Parallel "--parallel " | ||
|> appendIfNotEqual 0 this.ParallelWorkers "--parallel-workers " | ||
|> appendIfTrue this.FailOnFocusedTests "--fail-on-focused-tests " | ||
|> appendIfTrue this.Summary "--summary " | ||
|> appendIfTrue this.SummaryLocation "--summary-location " | ||
|> appendIfTrue (not this.Parallel) "--sequenced " | ||
|> appendIfTrue this.PrintVersion "--version " | ||
|> appendIfTrue this.ListTests "--list-tests " | ||
|> appendIfNotNullOrWhiteSpace this.Filter "--filter " | ||
|> appendIfNotNullOrWhiteSpace this.FilterTestCase "--filter-test-case " | ||
|> appendIfNotNullOrWhiteSpace this.FilterTestList "--filter-test-list " | ||
|> appendList this.Run "--run " | ||
|> appendList this.CustomArgs "" | ||
|> toText | ||
|
||
static member DefaultParams = | ||
{ | ||
Debug = false | ||
Parallel = true | ||
ParallelWorkers = 0 | ||
Filter = "" | ||
FilterTestCase = "" | ||
FailOnFocusedTests = true | ||
FilterTestList = "" | ||
PrintVersion = true | ||
Run = [] | ||
ListTests = false | ||
// Summary = true somehow breakes Expecto TeamCity printer | ||
Summary = false | ||
SummaryLocation = false | ||
CustomArgs = [] | ||
WorkingDirectory = "" | ||
} | ||
|
||
let run (setParams : ExpectoParams -> ExpectoParams) (assemblies : string seq) = | ||
let details = assemblies |> String.separated ", " | ||
use __ = Trace.traceTask "Expecto" details | ||
|
||
let runAssembly testAssembly = | ||
let exitCode = | ||
let fakeStartInfo testAssembly args = | ||
let workingDir = | ||
if String.isNotNullOrEmpty args.WorkingDirectory | ||
then args.WorkingDirectory else Fake.IO.Path.getDirectory testAssembly | ||
(fun (info: ProcStartInfo) -> | ||
{ info with | ||
FileName = testAssembly | ||
Arguments = string args | ||
WorkingDirectory = workingDir | ||
UseShellExecute = false | ||
// Pass environment variables to the expecto console process in order to let it detect it's running on TeamCity | ||
// (it checks TEAMCITY_PROJECT_NAME <> null specifically). | ||
Environment = environVars() |> Map } ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just leave it out? I think this is the default. |
||
|
||
let execWithExitCode testAssembly argsString timeout = | ||
Process.execSimple (fakeStartInfo testAssembly argsString) timeout | ||
|
||
execWithExitCode testAssembly (setParams ExpectoParams.DefaultParams) TimeSpan.MaxValue | ||
|
||
testAssembly, exitCode | ||
|
||
let res = | ||
assemblies | ||
|> Seq.map runAssembly | ||
|> Seq.filter( snd >> (<>) 0) | ||
|> Seq.toList | ||
|
||
match res with | ||
| [] -> () | ||
| failedAssemblies -> | ||
failedAssemblies | ||
|> List.map (fun (testAssembly,exitCode) -> sprintf "Expecto test of assembly '%s' failed. Process finished with exit code %d." testAssembly exitCode) | ||
|> String.concat System.Environment.NewLine | ||
|> FailedTestsException |> raise |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks> | ||
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants> | ||
<AssemblyName>Fake.DotNet.Testing.Expecto</AssemblyName> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DefineConstants>$(DefineConstants);NETSTANDARD;USE_HTTPCLIENT</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="Expecto.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Trace\Fake.Core.Trace.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" /> | ||
<ProjectReference Include="..\Fake.Core.String\Fake.Core.String.fsproj" /> | ||
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" /> | ||
<ProjectReference Include="..\Fake.Testing.Common\Fake.Testing.Common.fsproj"> | ||
<FromP2P>true</FromP2P> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj"> | ||
<FromP2P>true</FromP2P> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="..\..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
group netcore | ||
|
||
FSharp.Core | ||
NETStandard.Library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add
RequireQualifiedAccess
here