The open file and generated name.
1 import std.algorithm : startsWith; 2 import std.file : remove; 3 4 auto tempFile = mkstemp(".unittest-XXXXXX"); 5 scope (exit) 6 remove(tempFile.name); 7 8 assert(tempFile.name.startsWith(".unittest-")); 9 assert(tempFile.file.isOpen); 10 assert(!tempFile.file.error); 11 tempFile.file.writeln("foobar"); 12 tempFile.file.flush(); 13 tempFile.file.rewind(); 14 assert(tempFile.file.readln() == "foobar\n");
Generate a unique temporary filename from templateString, creates and opens the file, and returns the open file and generated name.
The last six characters of template must be "XXXXXX" and these are replaced with a string that makes the filename unique.
The optional templateSuffix will be appended to the file name.