I have been struggling with a test case failure on my Mac today and finally asked Hongbing to take a look, which was a good move because he figured out the problem in about 10 seconds. I wanted to explain the situation to everyone in case others run into this situation and also so that we have a record in the email archives to look up in future.

The problem was a test case failure in hackyApp_BuildAnalysis, in which there was an assert clause similar to:

 assertEquals("... Foo.java ....", analysis.getDetails());

This was failing on Unix with the error that basically indicated that the expected value was "Foo.java", but the actual value was "c:\bar\Foo.java". On Windows, the test passes fine: both expected and actual values are "Foo.java".

Inside the getDetails() method is code similar to this:

 buffer.append(new File(fileName).getName()).append(", ");

What's happening is that this code is using test data in the testdataset user, in which almost all files are Windows style such as c:\bar\Foo.java. On Windows, new File("c:\bar\Foo.java").getName() returns "Foo.java" because Windows understand that "c:\bar\Foo.java" is a path. On Unix, "c:\bar\Foo.java" is just a file name, so new File("c:\bar\Foo.java").getName() returns "c:\bar\Foo.java".

Because hackyApp_BuildAnalysis is a UH-specific module, we've not built it on Unix and so this hasn't been an issue before.

If you run into this situation, there are at least the following remedies:

(a) See if you can test appropriately without referring to the file name in the 
test.

(b) Don't call the File "getName()" method in Hackystat code, since it will do the Wrong Thing when dealing with Windows file paths on a Unix platformm.

(c) Use WorkspaceCache.getInstance().getWorkspaceFile(user, rawFilePath) to convert a rawFilePath to a canonical version that outputs the same string on any platform.

Cheers,
Philip

Reply via email to