www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Best practices for testing functions that opens files

reply "splatterdash" <toa.konuva yahoo.com> writes:
Hi all,

Is there a recommended way to test functions that opens and 
iterates over files? The unittest block seems more suited for 
testing functions whose input and output can be defined in the 
program itself. I'm wondering if there is a better way to test 
functions that open files with specific formats.

Thanks before :).
Aug 05 2014
next sibling parent "abanstadya" <abanstadya nowhere.utopia> writes:
On Tuesday, 5 August 2014 at 23:22:24 UTC, splatterdash wrote:
 Hi all,

 Is there a recommended way to test functions that opens and 
 iterates over files? The unittest block seems more suited for 
 testing functions whose input and output can be defined in the 
 program itself. I'm wondering if there is a better way to test 
 functions that open files with specific formats.

 Thanks before :).
The concern would be more on functions that delete files. Yesterday I've made a programming error which resulted into the deletion if the source files of another project. Fortunately the other project was git-i-fyed and I just had to stash/pull to recover my files. Take care. Opening files with wrong args can overwrite, delete the curent one. Maybe make a sandbox environment (clean brand new account).
Aug 05 2014
prev sibling parent simendsjo <simendsjo gmail.com> writes:
On 08/06/2014 01:22 AM, splatterdash wrote:
 Hi all,
 
 Is there a recommended way to test functions that opens and iterates
 over files? The unittest block seems more suited for testing functions
 whose input and output can be defined in the program itself. I'm
 wondering if there is a better way to test functions that open files
 with specific formats.
 
 Thanks before :).
Split it to several functions: ubyte[] readFile(string file) {...} MyFormat parseData(ubyte[] data) { ... } This way you have very little logic where the files are read, and you can easily unittest your parsing.
Aug 05 2014