[Mono-devel-list] Detecting Mono

Ben Maurer bmaurer at users.sourceforge.net
Mon Feb 16 13:23:03 EST 2004


I really, really dont think this is the way to go.

Software should not work like this:
"if you are running on windows, pressing `foo' will result in blah. As
an exception, on windows 98, nothing will happen. On linux, it will do
bar if it is running on RedHat 9 or Fedora, but will do baz if it is
running on any other linux system."

You might have a feature that is implemented in different ways on
different systems -- for example, maybe on Windows you store a key in
the registry, but on Linux you store it in a dot file.

In the above case, your test should *not* look like this:

[Test] [Platform ("!linux")]
public void TestWinSettings ()
{
    Settings.Store (foo, bar);
    AssertEquals (Registry.Get (foo), bar);
}


[Test] [Platform ("linux")]
public void TestLinuxSettings ()
{
    Settings.Store (foo, bar);
    AssertEquals (GConf.Get (foo), bar);
}

Rather, you should write your test like:

[Test]
public void TestSettings ()
{
    Setttings.Store (foo, bar);
    AssertEquals (Settings.Get (foo), bar);
}

You should be running the tests on the *result* not the implementation.

Now, I realize some platforms will not support something specifc. Lets
say you want to make NUnit runnable as a service (eg, so that you could
run tests in the background). Right now, Mono does not really support
this (you can work around it via some command line stuff, but we do not
support the api). Rather then testing for *mono* you should test for the
*feature*. In your code, you should write something like:

#if CAN_RUN_AS_SERVICE
   // APIs for running as service
#endif

In your tests, you can write:

#if CAN_RUN_AS_SERVICE
  // my service test suite
#endif

You could even have these tests in a special assembly that you only used
if the service feature was enabled.

One other problem I realize exists is that you might know a specific
feature fails right now under mono. Rather than not running the test, I
would rather see a feature where you could write:

[Test]
[Note ("This test fails on Mono, see Ximian bugzilla #12345")]
public void MyTest ()
{
}

You could allow someone to also annotate that with:
[KnownFailSet ("MONO_FAILURES")]

Then, when run under Mono you can do:

nunit-however-you-invoke-the-thing /knownfailset:MONO_FAILURES

The program could then still give you the nice Red/Green light.

This actually has nice uses for normal usage. For example, lets say I am
programming feature `Foo'. What I can do is to add 20 tests that I know
will fail. Then I can build up the Foo feature. As I am writing code, I
can test to make sure I did not cause any regressions. Before, without
this annotation, I would have to count the number of failures, and make
sure no regressions were happening. With this sort of markup, I could
avoid that and just get a red/green. As I am going, i can remove the tag
from sub-components that I have implemented, to make sure I am not
regressing on my newly written code.

Having different tests for different platforms implies that you intend
for the program to work differently in each platform. This isnt really
consistant with having a program that is really cross platform.

On Mon, 2004-02-16 at 12:52, Charlie Poole wrote:
> Hi Jarek,
> 
> Elaborating on my earlier reply to Nick - Nunit itself /is/ one of those
> apps that runs on multiple platforms and needs this facility. Currently,
> we detect Win98 /in/ the test for AssemblyWatcher and just pass it if we
> are on that platform. This seems better to me than ignoring, as yellow
> is just another kind of red to me. :-)
> 
> That's where the logic comes from for simply leaving things out of the
> test tree if they are for some other platform: they can never be run,
> and none of the three colors really makes sense.
> 
> Now that I think of it, an ignore type check is probably at least as
> common as a positive check. The syntax I was imagining was something
> like:
> 
> 	[Platform("net-1.0,net-1.1")]
> 
> Perhaps an alternative would be to also support
> 
> 	[Platform( Exclude="mono" )]
> 
> Charlie Poole
> cpoole at pooleconsulting.com
> 
> 
> 
> > -----Original Message-----
> > From: mono-devel-list-admin at lists.ximian.com 
> > [mailto:mono-devel-list-admin at lists.ximian.com] On Behalf Of 
> > Jaroslaw Kowalski
> > Sent: Monday, February 16, 2004 9:09 AM
> > To: Nick Drochak; 'Charlie Poole'; mono-devel-list at lists.ximian.com
> > Cc: ! nant
> > Subject: Re: [Mono-devel-list] Detecting Mono
> > 
> > 
> > > It'd be great if we had some attributes like "IgnoreDotNet" and
> > "IgnoreMono"
> > > with which we could decorate a test to avoid running tests 
> > on specific 
> > > CLR's.  My quick hack to the code would be to change
> > > TestCaseBuilder.HasIgnoreAttribute() check for the full 
> > Ignore, or see
> > what
> > > runtime we are on and check for the specific attributes accordingly.
> > 
> > How about using a textual name of the plaftorm for this 
> > purpose? The naming schema could be adopted from NAnt, e.g:
> > 
> > net-1.0
> > net-1.1
> > net-1.2
> > netcf-1.0
> > sscli-1.0
> > mono-1.0
> > 
> > This way we could even employ some wildcards. Like "mono-1.*" 
> > to represent any mono v1.x.
> > 
> > Same thing should apply to OSes ("platforms" in NAnt 
> > terminology). One should be able to run the test on a 
> > particular OS or platform. For example if your test uses 
> > filesystemwatcher it shouldn't be ran on Win95.
> > 
> > Some ideas below:
> > 
> > [Test]
> > [IgnoreOnFramework("net-1.0")]
> > void A()
> > {
> > }
> > 
> > [Test]
> > [IgnoreOnFramework("net-1.1")] // this would not run on .NET 
> > 1.1 void B() { }
> > 
> > [Test]
> > [IgnoreOnFramework("net-1.*")]    // this would not run on ALL .NET
> > platforms
> > void C()
> > {
> > }
> > 
> > [Test]
> > [IgnoreOnPlatform(Platform.Win32)]    // this would not run on Win32
> > platforms
> > void D()
> > {
> > }
> > 
> > [Test]
> > [IgnoreOnPlatform(Platform.Unix)]    // this would not run on 
> > Unix platforms
> > void E()
> > {
> > }
> > 
> > [Test]
> > [RunOnPlatform(Platform.Win32)]    // this would run only on 
> > Win32 platforms
> > void F()
> > {
> > }
> > 
> > [Test]
> > [RunOnFramework("mono-1.*")]    // this would run only on Mono
> > void G()
> > {
> > }
> > 
> > There are more (open source) tools that target multiple 
> > platforms/oses. I think it would be great to have some 
> > agreement on this attribute usage. For example in NAnt we're 
> > discussing the possibility of implementing os-specific or 
> > platform-specific tasks,types or functions in a single 
> > codebase. We've tentatively decided that using such 
> > attributes is a way to go.
> > 
> > BTW. I think that the "excluded because of the framework/os" 
> > status shouldn't be the same thing as "ignored" in NUnit. 
> > Tests are "ignored" because they are known to temporarily 
> > fail, while RunOn... and IgnoreOn... means something different here.
> > 
> > Jarek
> > 
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com 
> > http://lists.ximian.com/mailman/listinfo/mono-> devel-list
> > 
> 
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list