Additional Test methods

Jan 12, 2010 at 4:03 AM

I'd like to suggest adding a couple of methods:


let fail_with (msg:string) (error:Lazy<_>) =
    let mutable threw = false
    try
        try 
            error.Force() |> ignore
        with
        | Failure message -> 
            threw <- true
    //            Assert.Contains(msg,message)
            if not <| message.Contains(msg) then
                raise <| Xunit.Sdk.AssertActualExpectedException(msg,message,"Failure should contain:")
        | e -> 
            threw <- true
            raise <| Xunit.Sdk.ThrowsException(typeof<System.Exception>,e)
    finally 
        if not threw then
            raise <| Xunit.Sdk.ThrowsException(typeof<System.Exception>)
        
let fail_withi (msg:string) (error:Lazy<_>) =
    let mutable threw = false
    try
        try 
            error.Force() |> ignore
        with
        | Failure message -> 
            threw <- true
//            Assert.Contains(msg,message)
            if message.IndexOf(msg,System.StringComparison.OrdinalIgnoreCase) >= 0 then
                raise <| Xunit.Sdk.AssertActualExpectedException(msg,message,"Failure should contain:")
        | e -> 
            threw <- true
            raise <| Xunit.Sdk.ThrowsException(typeof<System.Exception>,e)
    finally 
        if not threw then
            raise <| Xunit.Sdk.ThrowsException(typeof<System.Exception>)

let match' regexp result =
    Assert.True(System.Text.RegularExpressions.Regex.IsMatch(result,regexp),sprintf "Result: %s should match %s" result regexp)

let not_match regexp result = 
    Assert.False(System.Text.RegularExpressions.Regex.IsMatch(result,regexp),sprintf "Result: %s should not match %s" result regexp)