1 /** 2 Copyright: Copyright (c) 2018, Joakim Brännström. All rights reserved. 3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 */ 6 module config; 7 8 public import core.stdc.stdlib; 9 public import std.algorithm; 10 public import std.array; 11 public import std.ascii; 12 public import std.conv; 13 public import std.file; 14 public import std.process; 15 public import std.path; 16 public import std.range; 17 public import std.stdio; 18 public import std..string; 19 public import logger = std.experimental.logger; 20 21 immutable buildDir = "../build"; 22 immutable distssh = "../build/distssh"; 23 immutable tmpDir = "./build/testdata"; 24 25 private shared(bool) g_isDistsshPrepared = false; 26 27 void prepareDistssh() { 28 synchronized { 29 if (g_isDistsshPrepared) 30 return; 31 g_isDistsshPrepared = true; 32 33 // prepare by cleaning up 34 if (exists(buildDir)) 35 dirEntries(buildDir, SpanMode.shallow).each!(a => remove(a)); 36 37 auto es = spawnShell("cd .. && dub build").wait; 38 assert(es == 0, "failed compilation"); 39 40 assert(exists(distssh), "no binary produced"); 41 } 42 } 43 44 struct TestArea { 45 const string workdir; 46 47 alias workdir this; 48 49 this(string file, ulong id) { 50 prepareDistssh; 51 this.workdir = buildPath(tmpDir, file ~ id.to!string).absolutePath; 52 setup(); 53 } 54 55 void setup() { 56 if (exists(workdir)) { 57 rmdirRecurse(workdir); 58 } 59 60 mkdirRecurse(workdir); 61 } 62 }