digitalmars.D.learn - Temporary file creation for unittests
- Russel Winder (19/19) May 18 2018 Hi,
- Uknown (4/13) May 18 2018 You could use libc's tmpfile with std.stdio.File until a D
- Dr.No (26/43) May 18 2018 I've had no idea C++'s got this in the standard library lol a
- Joakim (4/13) May 20 2018 You could use std.file.deleteme, which is what the Phobos
- Atila Neves (10/13) May 21 2018 Not official, but...
- Dr.No (2/16) May 21 2018 I've never seen "should" being in used in function names before...
- Atila Neves (3/24) May 21 2018 There's a whole lot of them here:
- Russel Winder (12/30) May 21 2018 OK, we like this. A lot.
- Atila Neves (6/30) May 21 2018 It's got so many features that I don't know how to document
Hi, What's the current official position on how to create temporary files for u= se during a unittest. I found=20 https://github.com/dlang/phobos/pull/5788 but it seems to be languishing in the "we have discussed all the issues tha= t no-one will ever have a problem with" phase. What to do between now and when there is an LDC release that has the result= of the merge? =20 --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
May 18 2018
On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:Hi, What's the current official position on how to create temporary files for use during a unittest. I found https://github.com/dlang/phobos/pull/5788 but it seems to be languishing in the "we have discussed all the issues that no-one will ever have a problem with" phase. What to do between now and when there is an LDC release that has the result of the merge?You could use libc's tmpfile with std.stdio.File until a D alternative pops up. http://en.cppreference.com/w/c/io/tmpfile
May 18 2018
On Friday, 18 May 2018 at 15:30:05 UTC, Uknown wrote:On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:I've had no idea C++'s got this in the standard library lol a while ago I ended up doing this (on Windows): /// Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file. /// Returns: the full path of the temp file. string tempFilename() { import core.sys.windows.windows : GetTempFileNameW, MAX_PATH; import std.file : tempDir; import core.stdc.wchar_ : wcslen; import std.windows.syserror : wenforce; import std.conv : text, wtext; wchar[] path = new wchar[MAX_PATH+1]; string dir = tempDir; wenforce(GetTempFileNameW(dir.wtext.ptr, // temp path ("tmp"w).ptr, // dir prefix 0, // id generated internally path.ptr // path buffer ), "GetTempFileName()"); return path[0 .. wcslen(path.ptr)].text; } It's windows-only and call GetTempFileNameW actually so just a function wrapper to work with D. There's a way to MAX_PATH but I didn't care to implement at time...Hi, What's the current official position on how to create temporary files for use during a unittest. I found https://github.com/dlang/phobos/pull/5788 but it seems to be languishing in the "we have discussed all the issues that no-one will ever have a problem with" phase. What to do between now and when there is an LDC release that has the result of the merge?You could use libc's tmpfile with std.stdio.File until a D alternative pops up. http://en.cppreference.com/w/c/io/tmpfile
May 18 2018
On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:Hi, What's the current official position on how to create temporary files for use during a unittest. I found https://github.com/dlang/phobos/pull/5788 but it seems to be languishing in the "we have discussed all the issues that no-one will ever have a problem with" phase. What to do between now and when there is an LDC release that has the result of the merge?You could use std.file.deleteme, which is what the Phobos unittests use: https://github.com/dlang/phobos/blob/master/std/file.d#L117
May 20 2018
On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:Hi, What's the current official position on how to create temporary files for use during a unittest. I foundNot official, but... import unit_threaded; with(const Sandbox()) { writeFile("myfile.txt", "contents"); shouldExist("myfile.txt"); shouldEqualContent("myfile.txt", "contents"); fileShouldContain("myfile.txt", "cont"); } Atila
May 21 2018
On Monday, 21 May 2018 at 15:16:11 UTC, Atila Neves wrote:On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:I've never seen "should" being in used in function names before...Hi, What's the current official position on how to create temporary files for use during a unittest. I foundNot official, but... import unit_threaded; with(const Sandbox()) { writeFile("myfile.txt", "contents"); shouldExist("myfile.txt"); shouldEqualContent("myfile.txt", "contents"); fileShouldContain("myfile.txt", "cont"); } Atila
May 21 2018
On Monday, 21 May 2018 at 15:20:14 UTC, Dr.No wrote:On Monday, 21 May 2018 at 15:16:11 UTC, Atila Neves wrote:There's a whole lot of them here: https://github.com/atilaneves/unit-threaded/blob/master/source/unit_threaded/should.dOn Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:I've never seen "should" being in used in function names before...Hi, What's the current official position on how to create temporary files for use during a unittest. I foundNot official, but... import unit_threaded; with(const Sandbox()) { writeFile("myfile.txt", "contents"); shouldExist("myfile.txt"); shouldEqualContent("myfile.txt", "contents"); fileShouldContain("myfile.txt", "cont"); } Atila
May 21 2018
On Mon, 2018-05-21 at 15:16 +0000, Atila Neves via Digitalmars-d-learn wrot= e:On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:OK, we like this. A lot. Given I use Unit-Threaded, why did I not know this. Ah, OK, RTFM. :-) Did I mention how much I like this RAII approach? --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.ukHi, =20 What's the current official position on how to create temporary=20 files for use during a unittest. I found=20 Not official, but... =20 import unit_threaded; =20 with(const Sandbox()) { writeFile("myfile.txt", "contents"); shouldExist("myfile.txt"); shouldEqualContent("myfile.txt", "contents"); fileShouldContain("myfile.txt", "cont"); } =20 Atila
May 21 2018
On Monday, 21 May 2018 at 17:03:40 UTC, Russel Winder wrote:On Mon, 2018-05-21 at 15:16 +0000, Atila Neves via Digitalmars-d-learn wrote::)On Friday, 18 May 2018 at 15:16:52 UTC, Russel Winder wrote:OK, we like this. A lot.Hi, What's the current official position on how to create temporary files for use during a unittest. I foundNot official, but... import unit_threaded; with(const Sandbox()) { writeFile("myfile.txt", "contents"); shouldExist("myfile.txt"); shouldEqualContent("myfile.txt", "contents"); fileShouldContain("myfile.txt", "cont"); } AtilaGiven I use Unit-Threaded, why did I not know this. Ah, OK, RTFM. :-)It's got so many features that I don't know how to document everything and make it accessible at the same time.Did I mention how much I like this RAII approach?Me too - RAII is definitely C++'s gift to the world. I've been abusing `with` lately quite a bit. I think it's underused.
May 21 2018