[BUG] FileDirectory>>exists

Julian Fitzell julian at beta4.com
Thu May 22 00:39:45 UTC 2003


Lukas Renggli wrote:
>>Lukas, could you please write this up as a unit test?
> 
> 
> Ok, these are just a few ideas to make file-handling easier, dumped out 
> of my brain as SUnit tests:

Argh, should have finished reading the thread before posting.  This is 
almost exactly what I had in mind.

> 	FilenameTest>>testWriteStream
> | 		| file stream |
> 		file := FileDirectory default fileNamed: 'test.dat'.
> 		self deny: file exists.
> 		stream := file writeStream.
> 		stream nextPutAll: 'Hello World'.
> 		stream close.
> 		self assert: file exists.
> 		self assert: file size > 0.
> 		self assert: file readStream contents = 'Hello World'.
> 		file delete.
> 
> 	FilenameTest>>testRenameTo
> | 		| file1 file2 |
> 		file1 := FileDirectory default fileNamed: 'test1'.
> 		file2 := FileDirectory default fileNamed: 'test2'.
> 		file1 createEmpty.
> 		self assert: file1 exists.
> 		self deny: file2 exists.
> 		file1 renameTo: file2.
> 		self deny: file1 exists.
> 		self assert: file2 exists.
> 		file2 delete.

This is where what I had in mind differs.  I think I would expect 
renameTo: to change the name in the object, so file1 and file2 would 
both exist.  This is why I had a File object in mind rather than a 
Filename object, I guess.

Presumably the object would store the directory object that it came from 
or something?  It would be great if you could move it by calling 
File>>moveTo: and passing another directory.  You could have 
FileDirectory>>copyFile: and FileDirectory>>moveFile: or something too.

> 	FileDirectory>>testFilelist
> | 		| file1 list |
> 		file1 := FileDirectory default fileNamed: 'test1'.
> 		file1 createEmpty.
> 		list := FileDirectory default filelist.
> 		list do: [ :item |
> 			self assert: item exists ].
> 		list includes: file1.
> 		file1 delete.
> 
> Some notes:
> - the message FileDirectory>>fileNamed: aString does not return a stream (
> in the current implementation it does, altough I would never have 
> expected that), but an instance of a filename.
> - the new message FileDirectory>>filelist returns a set of instances of 
> FileDirectory and Filename.

Julian



More information about the Squeak-dev mailing list