[BUG] FileDirectory>>exists

Lukas Renggli renggli at hotmail.com
Wed May 21 18:51:00 UTC 2003


> 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:

	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.

	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.

> As I'm not clear on what you're saying. An explanation
> unit test would make it easier to understand what
> interface you desire and the behaviour you expect as a
> result of sending messages to it. 

I'm sorry, my newsreader messed everything up. I agree that SUnit tests 
are most of the time much better to explain expected behaviour, but one 
could/should write hundreds more to explain the complete behaviour of 
Filename. 

> By the way, are you familiar with test first coding or
> Test Driven Development? 

Sure I am! As you have probably heard already I am the developer of 
SmallWiki and almost everything there has been implemented like this. 
Today I have just written the 200th test :-) . It is really a pleasure 
to see them all running green, after fixing a bug or doing several 
refactorings.

Cheers
Lukas

-- 
Lukas Renggli
http://renggli.freezope.org



More information about the Squeak-dev mailing list