Re: Path-related asserts

"Charlie Poole" <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nunit.devel
Message-ID <001501c86e66$c1554690$7801a8c0@ferrari>
Hi Kelly, 

> One of the things I've been fighting with lately is the 
> current working directory, and how that interacts with the 
> shadow cache thing.

No connection at all.

> I don't know if that's related, but it has been giving me headaches.
> It would sure be nice if there were a better way to specify a 
> directory within NUnit for such things as test files, etc. 
> The difficulty I'm facing is that the root directory is 
> different on different developers/builder machines, and it's 
> hard to keep the tests running the same everywhere. I don't 
> know if there is a slick way to make this work better or not.

Since NUnit guarantees that the current directory is set to the 
directory containing the assembly, you can always use a path
relative to that directory.
 
> BTW, if you're doing the work outlined below, it would sure 
> be nice to have a public method for converting a path to it's 
> shortest cannonical form.. i.e. convert c:\a\b\c\..\a.out to 
> c:\a\b\a.out

There is such a method in my constraint implementation, but
I hadn't intended to expose it. On the one hand it might
be useful, but on the other it would be the only such utility
routine in the framework.

What do others think?
 
> Will this use the Constraint syntax?

Every assertion in the framework is based on a constraint. In
this case, I defined constructors
  SamePathConstraint(string expected)
  SubPathConstraint(string expected)
  SubPathConstraint(string expected, bool allowSamePath)
The boolean in the last defaults to true, since the most common
test in my experiece is that a path should be the same or under
another path.

For integration with the "Is" syntax, I defined Is.SamePath
and Is.SubPath with the same arguments. Currently, you can
force it to use a non-default OS format by appending the
properties AsLinux or AsWindows, but some of Daniel's comments
are causing me to rethink that.

I'm still thinking about whether to add Assert.SamePath and 
Assert.SubPath.

Charlie

> -Kelly
> 
> On Feb 9, 2008 9:23 AM, Charlie Poole 
> <[email protected]> wrote:
> > Hi All,
> >
> > I'm working on assertions around file paths and I'd like to hear 
> > opinions on what should be included and how the syntax should look.
> >
> > Specific assertions I'm planning to use...
> >
> > * Assert that a path is valid for the current operating system
> > * Assert that two paths are the same. E.g.:
> >      /a/b/c is the same as /a/./b/q/../c
> >      C:\A\B\C is the same as c:\a\b\c on windows
> > * Assert that two paths are not the same
> > * Assert that one path is under another
> > * Assert that one path is not under another
> >
> > This is intended to work with paths as strings, without any need to 
> > access the files or directories refered to. It is motivated by the 
> > need to test apps that work with paths in the same way. In 
> fact, NUnit 
> > itself needs this.
> >
> > Issues...
> > Anything else that should be included? Should I add a test for 
> > existence? For being a file or directory? That would step slightly 
> > outside of the "string" approach but I could do it if it seems 
> > convenient. OTOH, we could add such tests to FileAssert or the 
> > (coming) DirectoryAssert.
> >
> > What syntax do you favor? Should we have a classic-style syntax?
> > * PathAssert.VERB()
> > * Assert.PathVERB()
> > A constraint-oriented syntax?
> > * Is.SamePath()
> > * Is.UnderPath()
> >
> > Other ideas?
> >
> > Limitations...
> >
> > I want this to work for either Windows or Linux, but I'm 
> assuming that 
> > any comparison of paths for two different OS's will fail.
> >
> > Without accessing the file system, any network paths will 
> only compare 
> > successfully if the share is textually the same.
> >
> > Other thoughts?
> >
> > Charlie
> >
> >
> >
> > 
> ----------------------------------------------------------------------
> > --- This SF.net email is sponsored by: Microsoft Defy all 
> challenges. 
> > Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > nunit-developer mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/nunit-developer
> >
> 
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Microsoft Defy all 
> challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> nunit-developer mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-developer
> 



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.