Skip to content
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

Feature - Run tests from many assemblies #423

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Expecto/Expecto.Impl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,17 +1026,31 @@ module Impl =
SourceLocation.empty

/// Scan filtered tests marked with TestsAttribute from an assembly
let testFromAssemblyWithFilter typeFilter (a: Assembly) =
let testListFromAssemblyWithFilter typeFilter (a : Assembly) =
a.GetExportedTypes()
|> Seq.filter typeFilter
|> Seq.choose testFromType
|> Seq.toList

/// Scan filtered tests marked with TestsAttribute from an assembly
let testFromAssemblyWithFilter typeFilter =
testListFromAssemblyWithFilter typeFilter >> listToTestListOption

/// Scan filtered tests marked with TestsAttribute from multiple assemblies
let testFromAssembliesWithFilter typeFilter (assemblies : Assembly seq) =
assemblies
|> Seq.map (testListFromAssemblyWithFilter typeFilter)
|> List.concat
|> listToTestListOption

/// Scan tests marked with TestsAttribute from an assembly
let testFromAssembly = testFromAssemblyWithFilter (fun _ -> true)
// TODO v10 eta expansion: let testFromAssembly asm = testFromAssemblyWithFilter (fun _ -> true) asm

/// Scan tests marked with TestsAttribute from multiple assemblies
let testFromAssemblies assemblies = testFromAssembliesWithFilter (fun _ -> true) assemblies
// TODO v10 eta expansion: let testFromAssemblies assemblies asm = testFromAssembliesWithFilter (fun _ -> true) assemblies asm

/// Scan tests marked with TestsAttribute from entry assembly
let testFromThisAssembly () = testFromAssembly (Assembly.GetEntryAssembly())

Expand Down
9 changes: 9 additions & 0 deletions Expecto/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,15 @@ module Tests =
let tests = testFromThisAssembly() |> Option.orDefault (TestList ([], Normal))
runTestsWithArgsAndCancel ct config args tests

/// Runs tests in the specified assemblies with the supplied command-line options.
/// Returns 0 if all tests passed, otherwise 1
let runTestsInAssembliesWithCLIArgsAndCancel (ct:CancellationToken) cliArgs args assemblies =
Copy link
Collaborator

@ratsclub ratsclub Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly a style-related comment. 😜

The other functions are written as let foo (bar : baz) = .... Should this one follow the same style?

let config = { ExpectoConfig.defaultConfig
with locate = getLocation (Assembly.GetEntryAssembly()) }
let config = Seq.fold (fun s a -> foldCLIArgumentToConfig a s) config cliArgs
let tests = testFromAssemblies assemblies |> Option.orDefault (TestList ([], Normal))
runTestsWithArgsAndCancel ct config args tests

/// Runs tests in this assembly with the supplied command-line options.
/// Returns 0 if all tests passed, otherwise 1
/// Deprecated: please use runTestsInAssemblyWithCLIArgs
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ Signature `CancellationToken -> CLIArguments seq -> string[] -> int`. Runs the t
assembly and also overrides the passed `CLIArguments` with the command line
parameters. All tests need to be marked with the `[<Tests>]` attribute.

### `runTestsInAssembliesWithCLIArgsAndCancel`

Signature `CancellationToken -> CLIArguments seq -> string[] -> seq<Assembly> -> int`. Runs the
tests in all the specified assemblies and also overrides the passed `CLIArguments` with the
command line parameters. All tests need to be marked with the `[<Tests>]` attribute.

### Filtering with `filter`

You can single out tests by filtering them by name (e.g. in the
Expand Down