C#, .NET, and Unit Testing

M

Mike Schilling

Arne said:
Peter said:
Arne Vajhøj wrote:
[...]
That's mostly true. However, note that the .NET 3.0 and 3.5 SDKs
were usable with VS2005.

Officially supported?

The 3.0 one was for sure.

3.0 was an odd release, in that it consisted of some new libraries
that got added on to the 2.0 libraries and compiler. 3.5, on the
other hand, was a complete replacement of everything that went
before.

3.5 still uses 2.0 CLR.

But creates a new directory tree and populates it with a new C# compiler,
IIRC.
 
A

Arne Vajhøj

Arne said:
Peter Duniho wrote:
Arne Vajhøj wrote:
[...]
That's mostly true. However, note that the .NET 3.0 and 3.5 SDKs
were usable with VS2005.

Officially supported?

The 3.0 one was for sure.

3.0 was an odd release, in that it consisted of some new libraries
that got added on to the 2.0 libraries and compiler. 3.5, on the
other hand, was a complete replacement of everything that went
before.

3.5 still uses 2.0 CLR.

But creates a new directory tree and populates it with a new C# compiler,
IIRC.

New libraries and new compilers, but still the same CLR.

Framework libs C# CLR
2.0 2.0 2.0 2.0
3.0 3.0 2.0 2.0
3.5 3.5 3.0 2.0
4.0 4.0 4.0 4.0

Arne
 
M

Mike Schilling

Arne said:
How do you do the conversion?

I wrote a Java program to do it, because, at the time, all the publicly
available ones that claimed to do it were crap, especially Microsoft's JLCA.
The syntax conversion was straightforward, since C# 1.1 and Java 1.4 were,
roughly speaking, the same language with slight variants in syntax. (They
have to some extent grown apart, but those were the current versions when I
did this work.) The procedure was, roughly,

1. Use ANTLR to compile a Java source file into an AST
2. Walk the AST creating a tree of objects corresponding to language
features: classes, methods, various kinds of statement, various kinds of
expression, etc.
3. Transform this object graph as necessary for places where C# and Java
differ: e.g., make the hidden "outer this" parameter to an inner class
constructor explicit. At the same time, detect untranslatable code, e.g. a
return from a finally block.
4. Serialize the transformed graph into C#. This includes mapping JDK
classes and members into their .NET equivalents, e.g. org.w3c.dom.Element
into System.Xml.XmlElement, and of course, detecting classes and methods did
not (yet) have a .NET equivalent.

A necessary part of this is translating JUnit tests into NUnit tests, so you
have immediate confirmation that nothing got broken along the way. Which is
why it was so handy that every step from Java compilation through running
both sets of tests could be done by the same ANT script.
 
A

Arne Vajhøj

I wrote a Java program to do it, because, at the time, all the publicly
available ones that claimed to do it were crap, especially Microsoft's JLCA.
The syntax conversion was straightforward, since C# 1.1 and Java 1.4 were,
roughly speaking, the same language with slight variants in syntax. (They
have to some extent grown apart, but those were the current versions when I
did this work.) The procedure was, roughly,

1. Use ANTLR to compile a Java source file into an AST
2. Walk the AST creating a tree of objects corresponding to language
features: classes, methods, various kinds of statement, various kinds of
expression, etc.
3. Transform this object graph as necessary for places where C# and Java
differ: e.g., make the hidden "outer this" parameter to an inner class
constructor explicit. At the same time, detect untranslatable code, e.g. a
return from a finally block.
4. Serialize the transformed graph into C#. This includes mapping JDK
classes and members into their .NET equivalents, e.g. org.w3c.dom.Element
into System.Xml.XmlElement, and of course, detecting classes and methods did
not (yet) have a .NET equivalent.

A necessary part of this is translating JUnit tests into NUnit tests, so you
have immediate confirmation that nothing got broken along the way. Which is
why it was so handy that every step from Java compilation through running
both sets of tests could be done by the same ANT script.

Very interesting.

If you ever decide to open source the tool, then please announce it.

Arne
 
M

Mike Schilling

Arne said:
Very interesting.

If you ever decide to open source the tool, then please announce it.

I recently severed connections with the company that still owns it, so it
wouldn't be my decision.
 
M

Mike Amling

Mike said:
I wrote a Java program to do it, because, at the time, all the publicly
available ones that claimed to do it were crap, especially Microsoft's JLCA.
The syntax conversion was straightforward, since C# 1.1 and Java 1.4 were,
roughly speaking, the same language with slight variants in syntax. (They
have to some extent grown apart, but those were the current versions when I
did this work.) The procedure was, roughly,

1. Use ANTLR to compile a Java source file into an AST
2. Walk the AST creating a tree of objects corresponding to language
features: classes, methods, various kinds of statement, various kinds of
expression, etc.
3. Transform this object graph as necessary for places where C# and Java
differ: e.g., make the hidden "outer this" parameter to an inner class
constructor explicit. At the same time, detect untranslatable code, e.g. a
return from a finally block.
4. Serialize the transformed graph into C#. This includes mapping JDK
classes and members into their .NET equivalents, e.g. org.w3c.dom.Element
into System.Xml.XmlElement, and of course, detecting classes and methods did
not (yet) have a .NET equivalent.

A necessary part of this is translating JUnit tests into NUnit tests, so you
have immediate confirmation that nothing got broken along the way. Which is
why it was so handy that every step from Java compilation through running
both sets of tests could be done by the same ANT script.

I'm impressed.

--Mike Amling
 
A

Arne Vajhøj

Exactly.

Of course, to further confuse the issue, even within the CLR version,
there have been minor updates in the service packs. The CLR 2.0 that
came with .NET 2.0 isn't precisely the same as the CLR 2.0 that you get
with .NET 3.5.

Yep.

The infamous red bits.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top