dharmatech
dharmatech

Reputation: 9527

Running only certain canopy tests as specified on command line

Let's say I have the following simple Canopy test program:

open System
open canopy.runner.classic
open canopy.configuration
open canopy.classic

canopy.configuration.chromeDir <- System.AppContext.BaseDirectory

start chrome

"test 1" &&& fun _ ->

    ...

"test 2" &&& fun _ ->

    ...

"test 3" &&& fun _ ->

    ...

[<EntryPoint>]
let main args =
    
    run()

    quit()

    0

When I run this program:

dotnet run

All three tests are run.

Let's say that by default, I want to run test 1 and test 2. But sometimes, I'd like to only run test 3.

What's the recommended way to set this up in Canopy?

Something like passing command line options would be fine:

dotnet run               # Run the default tests

dotnet run -- test-3     # Run test 3

Alternatively, I guess I could have test 3 be in a whole separate project. But that seems like alot of overhead just to have a separate test.

Thanks for any suggestions!

Upvotes: 0

Views: 67

Answers (1)

Brian Berns
Brian Berns

Reputation: 17038

I don't think there's any built-in way to do this, but it seems pretty easy to manage manually:

let defaultTests () =
    "test 1" &&& fun _ -> ()
    "test 2" &&& fun _ -> ()

let test3 () =
    "test 3" &&& fun _ -> ()

[<EntryPoint>]
let main (args : _[]) =
    let arg =
        if args.Length = 0 then "default"
        else args.[0]
    match arg with
        | "default" -> defaultTests ()
        | "test-3" -> test3 ()
        | _ -> failwith $"Unknown arg: {arg}"
    run()
    quit()
    0

The trick is to make sure that only the tests you want to run actually get defined at run-time.

Upvotes: 1

Related Questions