Fails to use testFilename in unittest

biocyberman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 18 02:40:33 PDT 2017


There is a ongoing discussion about temp file over here:
http://forum.dlang.org/thread/sbehcxusxxibmpkaeopl@forum.dlang.org

I have a question about generating a temporary file to write test 
data. I can create my own file and use it but just want to use 
the existing tool for convenience. testFilename() is used all 
over phobos. So, I don't understand why it does not work on my 
code.

The following code fails to compile.


   % cat testFile.d
#!/usr/bin/env rdmd
import std.stdio;

unittest{

   static import std.file;
   auto deleteme = testFilename();
   scope(failure) printf("Failed test at line %d\n", __LINE__);

   scope(exit) std.file.remove(deleteme);

   // Do some stuffs with open or writing and reading of the temp 
file.
    assert(true);



}
void main(string [] args){
   writeln("Main");

}



More information about the Digitalmars-d-learn mailing list