[racket] testing impure stuff

2013-12-22 Thread Manfred Lotz
Hi there, I just wrote a file duplicate finder where I'm not quite sure how to build up my test cases. The problem is that most of my test cases are impure. They rely upon a directory layout. What is the best way to do this? Should I create a directory structure containing most (or better all) of

Re: [racket] testing impure stuff

2013-12-22 Thread Matthias Felleisen
On Dec 22, 2013, at 1:54 PM, Manfred Lotz wrote: > Hi there, > I just wrote a file duplicate finder where I'm not quite sure how to > build up my test cases. > > The problem is that most of my test cases are impure. They rely upon a > directory layout. > > What is the best way to do this? Shoul

Re: [racket] testing impure stuff

2013-12-22 Thread Neil Van Dyke
Manfred Lotz wrote at 12/22/2013 01:54 PM: Or perhaps even better create my directory structure on the fly and build my test cases upon this? Yes, like that. It can be tedious to develop, but then your test suite is more likely to work when you or someone else needs it to. I suggest bu

Re: [racket] testing impure stuff

2013-12-22 Thread Manfred Lotz
On Sun, 22 Dec 2013 14:04:40 -0500 Matthias Felleisen wrote: > > On Dec 22, 2013, at 1:54 PM, Manfred Lotz wrote: > > > Hi there, > > I just wrote a file duplicate finder where I'm not quite sure how to > > build up my test cases. > > > > The problem is that most of my test cases are impure. T

Re: [racket] testing impure stuff

2013-12-22 Thread Robby Findler
You should also consider structuring your code such that the code that actually touches the filesystem is separate from the logic that does whatever your program does. Then you can plug in a "fake" filesystem that just implements the same api as the real code, but that also does some specific, smal

Re: [racket] testing impure stuff

2013-12-22 Thread Matthias Felleisen
Yes. There is a (simple) hidden file/directory simulator in the works inside of 2htdp/batch-io for novices to test such things. Nothing you could use but Robby's right and his message recalled my (aborted) effort from last year -- Matthias On Dec 22, 2013, at 3:52 PM, Robby Findler wrote:

Re: [racket] testing impure stuff

2013-12-22 Thread Manfred Lotz
On Sun, 22 Dec 2013 14:52:55 -0600 Robby Findler wrote: > You should also consider structuring your code such that the code that > actually touches the filesystem is separate from the logic that does > whatever your program does. Then you can plug in a "fake" filesystem > that just implements the

Re: [racket] testing impure stuff

2013-12-22 Thread Robby Findler
It can require significant refactoring to separate out the filesystem uses and so you may consider it too painful, but it really does make for better code and you don't have to deal with the filesystem anywhere near as much. Robby On Sun, Dec 22, 2013 at 10:19 PM, Manfred Lotz wrote: > On Sun,

Re: [racket] testing impure stuff

2013-12-23 Thread Greg Hendershott
On Sun, Dec 22, 2013 at 2:49 PM, Neil Van Dyke wrote: > Manfred Lotz wrote at 12/22/2013 01:54 PM: >> Or perhaps even better create my directory structure on the fly and >> build my test cases upon this? > Yes, like that. It can be tedious to develop, but then your test suite is > more likely to

Re: [racket] testing impure stuff

2013-12-23 Thread Manfred Lotz
On Mon, 23 Dec 2013 13:53:05 -0500 Greg Hendershott wrote: > On Sun, Dec 22, 2013 at 2:49 PM, Neil Van Dyke > wrote: > > Manfred Lotz wrote at 12/22/2013 01:54 PM: > >> Or perhaps even better create my directory structure on the fly and > >> build my test cases upon this? > > Yes, like that. It

Re: [racket] testing impure stuff

2013-12-23 Thread Matthias Felleisen
On Dec 23, 2013, at 2:10 PM, Manfred Lotz wrote: > On Mon, 23 Dec 2013 13:53:05 -0500 > Greg Hendershott > wrote: > >> On Sun, Dec 22, 2013 at 2:49 PM, Neil Van Dyke >> wrote: >>> Manfred Lotz wrote at 12/22/2013 01:54 PM: Or perhaps even better create my directory structure on the fly

Re: [racket] testing impure stuff

2013-12-23 Thread Manfred Lotz
On Mon, 23 Dec 2013 14:29:31 -0500 Matthias Felleisen wrote: > > > On Dec 23, 2013, at 2:10 PM, Manfred Lotz > wrote: > > > On Mon, 23 Dec 2013 13:53:05 -0500 > > Greg Hendershott > > wrote: > > > >> On Sun, Dec 22, 2013 at 2:49 PM, Neil Van Dyke > >> wrote: > >>> Manfred Lotz wrote at 12/

Re: [racket] testing impure stuff

2013-12-23 Thread Matthias Felleisen
For that, you will need to wrap the whole loop because (in-directory ...) fails, and no, I don't know how to resume this optimized loop: #lang racket ;; foo.rkt (define start-dir ".") ;; (with-handlers (((lambda (x) #t) (lambda (e) (log-warning "in-directory failed" (for ([f (in-direc

Re: [racket] testing impure stuff

2013-12-23 Thread Manfred Lotz
On Mon, 23 Dec 2013 15:20:32 -0500 Matthias Felleisen wrote: > > For that, you will need to wrap the whole loop because > (in-directory ...) fails, and no, I don't know how to resume this > optimized loop: > > #lang racket ;; foo.rkt > > (define start-dir ".") > > ;; > (with-handlers (((lam

Re: [racket] testing impure stuff

2013-12-23 Thread Manfred Lotz
I had a look into collects/racket/private/for.rkt where in-directory is defined. I have to admit that I don't understand much of the stuff as this is a level of Racket I haven't yet mastered. Nevertheless, there is (when (directory-exists? fp) (loop fp p) Here it should be

Re: [racket] testing impure stuff

2013-12-23 Thread Matthias Felleisen
Sadly, I think you may have to re-implement in-directory (with a recursive traversal like the one in for.rkt) but use file-or-directory-permission before you try to go into a subdirectory. -- Matthias On Dec 23, 2013, at 4:09 PM, Manfred Lotz wrote: > I had a look into collects/racket/privat

Re: [racket] testing impure stuff

2013-12-23 Thread Manfred Lotz
On Mon, 23 Dec 2013 16:44:03 -0500 Matthias Felleisen wrote: > > Sadly, I think you may have to re-implement in-directory (with a > recursive traversal like the one in for.rkt) but use > file-or-directory-permission before you try to go into a > subdirectory. -- Matthias > > > Yep, I did it

Re: [racket] testing impure stuff

2013-12-23 Thread Matthias Felleisen
On Dec 23, 2013, at 5:12 PM, Manfred Lotz wrote: > I think in-directory should be fixed in the long run. Agreed. -- Matthias Racket Users list: http://lists.racket-lang.org/users

Re: [racket] testing impure stuff

2013-12-23 Thread Robby Findler
Perhaps in-directory can take an optional parameter that controls whether or not to recur? Robby On Mon, Dec 23, 2013 at 4:42 PM, Matthias Felleisen wrote: > > On Dec 23, 2013, at 5:12 PM, Manfred Lotz wrote: > > > I think in-directory should be fixed in the long run. > > Agreed. -- Matthias >

Re: [racket] testing impure stuff

2013-12-23 Thread Matthias Felleisen
If you don't have permissions, you can't recur and the current implementation throws an error w/o recourse to a fix. As Manfred points out, this is a 'fair weather' function. A real implementation should resist such external mishaps. But I also agree w/ you about the parameter. It would general

Re: [racket] testing impure stuff

2013-12-23 Thread Robby Findler
I don't think the proposed fix would "resist" in this manner. The directory could be deleted between the time you check for its existence and when you ask for its contents. Robby On Mon, Dec 23, 2013 at 7:05 PM, Matthias Felleisen wrote: > > If you don't have permissions, you can't recur and th

Re: [racket] testing impure stuff

2013-12-23 Thread Manfred Lotz
On Mon, 23 Dec 2013 20:51:16 -0600 Robby Findler wrote: > I don't think the proposed fix would "resist" in this manner. The > directory could be deleted between the time you check for its > existence and when you ask for its contents. > I would differentiate between static and dynamic errors.

Re: [racket] testing impure stuff

2013-12-24 Thread Matthew Flatt
I'll add support for an optional directory-filtering function to `in-directory`. At Tue, 24 Dec 2013 05:24:50 +0100, Manfred Lotz wrote: > On Mon, 23 Dec 2013 20:51:16 -0600 > Robby Findler > wrote: > > > I don't think the proposed fix would "resist" in this manner. The > > directory could be de