masghar / mb-unit

Automatically exported from code.google.com/p/mb-unit
0 stars 0 forks source link

Default Sandbox in TestContext #915

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

This function throws a NullReferenceException because certain parts of 
TestContext assume a non-null sandbox, but the constructor doesn't enforce it:

{{{
let run tests = 
    let codeElemInfo = 
        { new ICodeElementInfo with
            member x.Name = "F# test" 
            member x.Kind = CodeElementKind.Method
            member x.CodeReference = CodeReference.Unknown
            member x.GetAttributeInfos(attributeType, inheritt) = Seq.empty
            member x.HasAttribute(attributeType, inheritt) = false
            member x.GetAttributes(attributeType, inheritt) = Seq.empty
            member x.GetXmlDocumentation() = ""
            member x.GetCodeLocation() = CodeLocation.Unknown
            member x.ReflectionPolicy = null
            member x.Equals y = true }

    let noAction = Gallio.Common.Action ignore

    Test.RunDynamicTests(tests, codeElemInfo, noAction, noAction)
}}}

Methods that assume a non-null sandbox in TestContext: RunStep, StartChildStep.

The fix is trivial: in the TestContext constructor, replace:

{{{
this.sandbox = sandbox;
}}}

with

{{{
this.sandbox = sandbox ?? new Sandbox();
}}}

Original issue reported on code.google.com by mauricio...@gmail.com on 27 Mar 2013 at 6:28