RE: SPAM-LOW: RE: SPAM-LOW: Re: [Mono-dev] NUnit 2.2.6 Portability Bug

2006-01-31 Thread Charlie Poole
I added Jon's patch and rewrote Canonicalize() - the use of Path.GetFullPath
doesn't work for the cases where NUnit needs to have a canonical relative
path. I've parameterized the tests so they run in both Windows and Unix
modes.

I'm not quite ready to do a full release but you can get the fixed source at
http://nunit.com/downloads/nunit-2.2.6.1-src.zip - sorry, no ftp access at
this site.

Charlie

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf 
 Of Jonathan Pryor
 Sent: Sunday, January 29, 2006 7:11 AM
 To: Charlie Poole
 Cc: mono-devel-list@lists.ximian.com
 Subject: SPAM-LOW: RE: SPAM-LOW: Re: [Mono-dev] NUnit 2.2.6 
 Portability Bug
 
 On Sat, 2006-01-28 at 18:15 -0800, Charlie Poole wrote:
  Hi Jonathan,
  I'll write a test. :-)
   
   PathRelativePathTo: this variation on your PathUtils.RelativePath 
   works for me (minimally tested):
  
  This looks too simple to work, but I'll try it. ;-)
 
 Attached is a better version, complete with test cases.  The 
 previous function was Unix-native -- it didn't care about 
 drives or other such things that I found in PathUtilTests.cs. 
  The attached version is a little smarter, though it means we 
 can't use the same input strings on both Unix and Windows for 
 testing -- we need platform-specific tests. :-(
 
  - Jon
 
 
 



___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


RE: SPAM-LOW: Re: [Mono-dev] NUnit 2.2.6 Portability Bug

2006-01-29 Thread Jonathan Pryor
On Sat, 2006-01-28 at 18:15 -0800, Charlie Poole wrote:
 Hi Jonathan, 
 I'll write a test. :-)
  
  PathRelativePathTo: this variation on your 
  PathUtils.RelativePath works for me (minimally tested):
 
 This looks too simple to work, but I'll try it. ;-)

Attached is a better version, complete with test cases.  The previous
function was Unix-native -- it didn't care about drives or other such
things that I found in PathUtilTests.cs.  The attached version is a
little smarter, though it means we can't use the same input strings on
both Unix and Windows for testing -- we need platform-specific
tests. :-(

 - Jon


// PathRelativePathTo:

using System;
using System.IO;
using System.Text;

/* 
The relative path is relative from: c:\a\b\path
The relative path is relative to: c:\a\x\y\file
The relative path is: ..\..\x\y\file
 */

class Test {
	static string RelativePath (string from, string to)
	{
		if (from == null)
			throw new ArgumentNullException (from);
		if (to == null)
			throw new ArgumentNullException (to);
		if (!Path.IsPathRooted (to))
			return to;
		if (Path.GetPathRoot (from) != Path.GetPathRoot (to))
			return null;

		string[] _from = from.Split (Path.DirectorySeparatorChar, 
Path.AltDirectorySeparatorChar);
		string[] _to   =   to.Split (Path.DirectorySeparatorChar, 
Path.AltDirectorySeparatorChar);

		StringBuilder sb = new StringBuilder (Math.Max (from.Length, to.Length));

		int last_common, min = Math.Min (_from.Length, _to.Length);
		for (last_common = 0; last_common  min;  ++last_common) {
			if (!_from [last_common].Equals (_to [last_common]))
break;
		}

		if (last_common  _from.Length)
			sb.Append (..);
		for (int i = last_common + 1; i  _from.Length; ++i) {
			sb.Append (Path.DirectorySeparatorChar).Append (..);
		}

		if (sb.Length  0)
			sb.Append (Path.DirectorySeparatorChar);
		if (last_common  _to.Length)
			sb.Append (_to [last_common]);
		for (int i = last_common + 1; i  _to.Length; ++i) {
			sb.Append (Path.DirectorySeparatorChar).Append (_to [i]);
		}

		return sb.ToString ();
	}

	static void Check (string a, string b)
	{
		Console.WriteLine (\t{0,5}: \{1}\ == \{2}\, a == b, a, b);
	}

	public static void Main (string[] args)
	{
		Console.WriteLine (Unix);
		Check (folder2/folder3, RelativePath (/folder1, /folder1/folder2/folder3));
		Check (../folder2/folder3, RelativePath (/folder1, /folder2/folder3));
		Check (bin/debug, RelativePath (/folder1, bin/debug));
		Check (../../d, RelativePath (/a/b/c, /a/d));
		Console.WriteLine (Windows);
		Check (@folder2\folder3, 
RelativePath (@C:\folder1, @C:\folder1\folder2\folder3));
		Check (@..\folder2\folder3, RelativePath (@C:\folder1, @C:\folder2\folder3));
		Check (@bin\debug, RelativePath (@C:\folder1, @bin\debug));
		Check (null, RelativePath (@C:\folder, @D:\folder));
		Check (@folder2\folder3, 
RelativePath (@C:/folder1, @C:/folder1/folder2/folder3));
		Check (@..\folder2\folder3, RelativePath (@C:/folder1, @C:/folder2/folder3));
		Check (@bin/debug, RelativePath (@C:/folder1, @bin/debug));
		Check (null, RelativePath (@C:/folder, @D:/folder));
		if (args.Length = 2) {
			Console.WriteLine (from:  + args[0]);
			Console.WriteLine (  to:  + args[1]);
			Console.WriteLine ( rel:  + RelativePath (args [0], args [1]));
		}
	}
}

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


RE: SPAM-LOW: Re: [Mono-dev] NUnit 2.2.6 Portability Bug

2006-01-28 Thread Charlie Poole
Hi Jonathan, 

 On Fri, 2006-01-27 at 12:25 -0800, Charlie Poole wrote:
  I have some code that can be modified to replace the 
 functions I use, 
  but before I re-invent the wheel, can anyone point to portable 
  implementations of Windows PathCanonicalize and PathRelativePathTo? 
  Better yet, does anyone want to contribute implementations? See 
  PathUtils.cs for how we use these functions.
 
 PathCanonicalize: System.IO.Path.GetFullPath() performs path 
 canonicalization.  At least Mono's version does...

I'll write a test. :-)
 
 PathRelativePathTo: this variation on your 
 PathUtils.RelativePath works for me (minimally tested):

This looks too simple to work, but I'll try it. ;-)

Seriously, it looks like it's gonna do the job. I'll write some tests to be
sure.

Thanks for the contribution,
Charlie
 
   public static string RelativePath (string from, string to)
   {
   string[] _from = from.Split 
 (Path.DirectorySeparatorChar);
   string[] _to   =   to.Split 
 (Path.DirectorySeparatorChar);
 
   StringBuilder sb = new StringBuilder 
 (from.Length + to.Length);
 
   int last_common, min = Math.Min (_from.Length, 
 _to.Length);
   for (last_common = 0; last_common  min;  
 ++last_common) {
   if (!_from [last_common].Equals (_to 
 [last_common]))
   break;
   }
   for (int i = last_common; i  _from.Length; ++i) {
   if (sb.Length  0)
   sb.Append (Path.DirectorySeparatorChar);
   sb.Append (..);
   }
   for (int i = last_common; i  _to.Length; ++i)
   sb.Append 
 (Path.DirectorySeparatorChar).Append (_to [i]);
 
   return sb.ToString ();
   }
 
  - Jon
 
 
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list
 



___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list