F # NUnit test sets value to null

I have 2 files: Asm.fs, AsmTest.fs

Asm.fs

namespace Assembler

[<Measure>] type ln
[<Measure>] type col
[<Measure>] type port

type Addr = int<ln> * int<col> * int<port>

module Asm = 
    let emptyAddr : Addr = (-1<ln>, -1<col>, -1<port>)

      

AsmTest.fs

module Assembler.Tests

[<Test>]
let someTest() = 
    let x = Asm.emptyAddr

      

When I debug someTest () code, I get that x = null, what am I doing wrong?

PS files in visual studio projects projects. Asm.fs in the Assembler project and AsmTest.fs in the AssemblerTest project.

I found some interesting behavior. My problem is solved if I add some file (even empty) to the Assembler project. Can anyone explain this behavior?

+3


source to share


1 answer


The debugger sometimes has trouble specifying the correct values. For me, however, having exactly the same Asm.fs and AsmTest.fs like this:

module Assembler.Tests

open NUnit.Framework

[<Test>]
let someTest() = 
    let x = Asm.emptyAddr
    Assert.IsNotNull x

      

the test passes, and if I set a breakpoint on assertion, it x

displays correctly as{(-1, -1, -1)}



Since the code you show does not compile as it is (blocking after this let is unfinished. C someTest

), can you try my test above and / or show the complete test method?

Using your code I can reproduce the behavior. If I install my projects to console apps, my test will fail as well. So it looks like for console projects the absence of some other file or [<EntryPoint>]

unexpectedly skips the initialization of the module values. For me, the compiler at least issues a warning Main module of program is empty

, where I use x

in the test. Hence the solution to the problem:

  • make sure you treat warnings as errors.
  • have [<EntryPoint>]

    for console applications
  • use project libraries for libraries
+2


source







All Articles