nunit-core team mailing list archive
-
nunit-core team
-
Mailing list archive
-
Message #00388
[Bug 495987] Re: PathUtils.RelativePath and problems with Project Save behaviour under Windows
** Changed in: nunitv2
Status: Fix Committed => Fix Released
--
PathUtils.RelativePath and problems with Project Save behaviour under Windows
https://bugs.launchpad.net/bugs/495987
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
Status in NUnit V2 Test Framework: Fix Released
Bug description:
I found some issues with PathUtils.RelativePath under Windows, which lead to
some strangenesses and bugs when saving projects (from the GUI or using NUnitProject.Save method).
Attached is a patch (based on NUnit-2.5.2.9222) fixing them (at least for me, I tested it under Windows
and .NET framework 3.5) and extending the PathUtils tests.
(1) If the first path is a root path, RelativePath generates an extra "..\"
at the beginning of the result. E.g.
PathUtils.RelativePath(@"C:\", @"C:\folder1\folder2")
yields "..\folder1\folder2" instead of "folder1\folder2".
Load e.g. following project with a root path as appbase:
<NUnitProject>
<Settings activeconfig="Laptop" appbase="C:\" />
<Config name="Laptop" binpath="C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\framework;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\lib;C:\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\NUnit25Try\bin\Debug">
<assembly path="C:\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\NUnit25Try\bin\Debug\NUnit25Try.dll" />
</Config>
</NUnitProject>
and save it, which yields a strange assembly path (but functionally still correct, AFAICS):
<NUnitProject>
<Settings activeconfig="Laptop" appbase="C:\" />
<Config name="Laptop" binpath="C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\framework;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\lib;C:\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\NUnit25Try\bin\Debug">
<assembly path="..\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\NUnit25Try\bin\Debug\NUnit25Try.dll" />
</Config>
</NUnitProject>
And every subsequent save operation adds one more "..\", like:
<NUnitProject>
<Settings activeconfig="Laptop" appbase="C:\" />
<Config name="Laptop" binpath="C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\framework;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\lib;C:\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\NUnit25Try\bin\Debug">
<assembly path="..\..\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\NUnit25Try\bin\Debug\NUnit25Try.dll" />
</Config>
</NUnitProject>
(2) A trailing directory separator leads to an additional "..\", e.g.
PathUtils.RelativePath(@"c:\folder1\", @"c:\folder1\folder2\folder3")
yields "..\folder2\folder3" instead of "folder2\folder3".
So, if you load a project file where the appbase has a trailing separator like:
<NUnitProject>
<Settings activeconfig="Laptop" appbase="C:\Programme\" />
<Config name="Laptop" binpath="C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\framework;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\lib;C:\Programme\NUnit-2.5\NUnit25Try\bin\Debug">
<assembly path="C:\Programme\NUnit-2.5\NUnit25Try\bin\Debug\NUnit25Try.dll" />
</Config>
</NUnitProject>
and save it, the assembly path becomes wrong:
<NUnitProject>
<Settings activeconfig="Laptop" appbase="C:\Programme\" />
<Config name="Laptop" binpath="C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\framework;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\lib;C:\Programme\NUnit-2.5\NUnit25Try\bin\Debug">
<assembly path="..\NUnit-2.5\NUnit25Try\bin\Debug\NUnit25Try.dll" />
</Config>
</NUnitProject>
(3) RelativePath operates case-sensitively even on Windows, so that
PathUtils.RelativePath(@"C:\folder1", @"c:\folder1\folder2\folder3")
yields null instead of @"folder2\folder3".
So, if one loads a project where the appbase drive letter is in a different case than the drive letter in the assembly path:
<NUnitProject>
<Settings activeconfig="Laptop" appbase="c:\Programme" />
<Config name="Laptop" binpath="C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\framework;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\lib;C:\Programme\NUnit-2.5\NUnit25Try\bin\Debug">
<assembly path="C:\Programme\NUnit-2.5\NUnit25Try\bin\Debug\NUnit25Try.dll" />
</Config>
</NUnitProject>
and saves the project, the assembly path is deleted:
<NUnitProject>
<Settings activeconfig="Laptop" appbase="c:\Programme" />
<Config name="Laptop" binpath="C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\framework;C:\Programme\NUnit-2.5\solutions\vs2008\bin\Debug\lib;C:\Programme\NUnit-2.5\NUnit25Try\bin\Debug">
<assembly path="" />
</Config>
</NUnitProject>
Best regards,
Peter