C# 2.0 yield keyword causes InvalidProgramException

C# 2.0 yield keyword causes InvalidProgramException

Hi,

First off, thanks a lot for NCover, it works great!

We've run into a little problem, though, with code using the new yield keyword in C# 2.0.

This little program:

using System;
using System.Collections;
using System.Text;

namespace ncover_yield
{
  public class MyEnumerable : IEnumerable
  {
    int counter = 0;

    public IEnumerator GetEnumerator()
    {
      while (true)
      {
        yield return ++counter;
      }
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      MyEnumerable myEnum = new MyEnumerable();
      foreach (int i in myEnum)
      {
        Console.WriteLine("i = {0}", i);

        if (i > 100)
          break;
      }
    }
  }
}

causes NCover to go belly-up with an InvalidProgramException.

Is there a chance of getting that fixed? It can see that it's probably pretty hard to see through the stuff generated by yield, but then again, it should be fairly boilerplate. Not sure how it mixes in with your existing framework for auto-reverse-engineering...

Let me know if I can help.

- Kim


Re: NCover shows bracket at end of method as "unvisited"

Are you able to post a small repro case (and please state your TD.Net version)? I don't experience that problem (although I am running later builds at the moment than what you would have). I have heard of people having it in the past on NUnit tests using [ExpectedException] where of course the exception gets thrown and the last line never reached. You will also see posts in this forum of people experiencing similar issues on properties in their classes (prior to NCover 1.5.5 anyways).

I appreciate the following doesn't "solve" the problem but imho any problems with coverage of the test fixture itself don't bother or impact us at all. The reason? We always use the NCoverExplorer coverage exclusion feature (and/or the //a with NCover if using the command line) to exclude unit test assemblies fom the results.

For me personally I am interested in the coverage of the application executable code that will be deployed. After all what real value does coverage of the test fixture itself show? Surely if all your tests passed you always expect 100% coverage of them?

I would also argue including the test coverage statistics "weights" the overall coverage results unfairly, skewing the overall percentage in a misleading way in favour of the developer.

The only situation I can think of where your test coverage will be less than 100% is if you have explicit or ignored tests. However as these are all reported in the NUnit output anyway again it seems fairly pointless to try to infer anything from the test fixture coverage about those.

All just my opinions of course...


Re: NCover shows bracket at end of method as "unvisited"

Agreed, I could just suppress displaying the coverage on the unit tests, but I'm curious as to why the problem exists at all.  I'm blocked from ftp-ing stuff at work, unfortunately.  I'm using TD.NET version 2.0.1605_Personal, if that helps.  Thanks for the tip.


Re: NCover shows bracket at end of method as "unvisited"

I would recommend pulling down a later version of TestDriven.Net - I'm not exactly sure what the latest version is that Jamie publicly makes available (he is releasing his RTM version shortly) but I know it is at least 2.0.1761. It fixes quite a few bugs so I would give that a go regardless and see if that makes a difference.


Re: NCover shows bracket at end of method as "unvisited"

I downloaded the most recent copy of TD.NET and the problem is worse now.  It is showing two instances of my unit tests, one with 100% coverage and one with 0%, which then displays a 50% coverage figure on the report.  What a mess!


Re: NCover shows bracket at end of method as "unvisited"

Yeah, that mess is caused by NCover 1.5.5 - which is why I've left messages all over the forum saying "please don't use it" ;-)  I would rather Peter had retracted the release completely given all the problems it has but we just have to wait for 1.5.6 to hopefully sort it all out...

NCover 1.5.4 doesn't suffer from this particular problem.

What version of TD.Net was it off Jamie's site - 2.0.1761 or a later one? I'm guess 1761 - which was before I introduced a "hack" in NCoverExplorer to try to workaround the 1.5.5 problem. If you download the latest NCoverExplorer 1.3.5 beta from this thread and overwrite the version in the TestDriven.Net 2.0 subfolder then that "doubling up" should hopefully disappear.