haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

FS0001: The type 'TestDir' does not have 'null' as a proper value when using `use` in TestCaseBuilder #341

Closed matthid closed 4 years ago

matthid commented 4 years ago

Example:

type TestDir =
    { Dir : string }
    interface System.IDisposable with
        member x.Dispose() =
            try
                Directory.Delete(x.Dir, true)
            with e ->
                eprintf "Failed to delete '%s': %O" x.Dir e
                ()

let createTestDir () =
    let testFile = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ())
    Directory.CreateDirectory(testFile)
        |> ignore<DirectoryInfo>
    { Dir = testFile }

[<Tests>]
let tests =
  testList "Tests" [
    test "test" {
      use testDir = createTestDir() // <- FS0001
      ()
    }
  ]

Workaround use testCase "test" <| fun _ -> instead

haf commented 4 years ago

@matthid This has been fixed now!

matthid commented 4 years ago

@haf Thanks!