diff --git a/Expecto/Expecto.Impl.fs b/Expecto/Expecto.Impl.fs index 510001c9..a014c74e 100644 --- a/Expecto/Expecto.Impl.fs +++ b/Expecto/Expecto.Impl.fs @@ -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()) diff --git a/Expecto/Expecto.fs b/Expecto/Expecto.fs index d23e175d..52dbff47 100644 --- a/Expecto/Expecto.fs +++ b/Expecto/Expecto.fs @@ -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 = + 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 diff --git a/README.md b/README.md index 91ae97a4..a8d7e4e3 100644 --- a/README.md +++ b/README.md @@ -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 `[]` attribute. +### `runTestsInAssembliesWithCLIArgsAndCancel` + +Signature `CancellationToken -> CLIArguments seq -> string[] -> seq -> 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 `[]` attribute. + ### Filtering with `filter` You can single out tests by filtering them by name (e.g. in the