1 module dud.pkgdescription.convtest; 2 3 import std.stdio; 4 import std.array : empty, front; 5 import std.algorithm.iteration : filter, map; 6 import std.algorithm.searching : endsWith; 7 import std.file : readText; 8 import std.format : format; 9 import std.exception : ifThrown; 10 import std.range : chain; 11 import std.typecons : tuple; 12 import std.json; 13 14 import dud.testdata; 15 import dud.pkgdescription; 16 import dud.pkgdescription.sdl; 17 import dud.pkgdescription.json; 18 import dud.pkgdescription.output; 19 import dud.pkgdescription.testhelper; 20 import dud.pkgdescription.exception; 21 import dud.pkgdescription.helper; 22 23 @safe: 24 25 void fun1() { 26 string input = q{ 27 configuration "windows-release" { 28 preBuildCommands "cd $PACKAGE_DIR\\cpp && cmake . -G \"Visual Studio 14 2015 Win64\" && cmake --build . --config Release" platform="windows-x86_64" 29 preBuildCommands "cd $PACKAGE_DIR\\cpp && cmake . -G \"Visual Studio 14 2015\" && cmake --build . --config Release" platform="windows-x86_mscoff" 30 } 31 }; 32 PackageDescription a = sdlToPackageDescription(input); 33 assert(a.configurations["windows-release"] 34 .preBuildCommands.platforms[0].platforms 35 == [ Platform.windows, Platform.x86_64], 36 format("%s", a.configurations["windows-release"].preBuildCommands)); 37 assert(a.configurations["windows-release"] 38 .preBuildCommands.platforms[1].platforms 39 == [ Platform.windows, Platform.x86_mscoff], 40 format("%s", a.configurations["windows-release"].preBuildCommands)); 41 JSONValue j = a.toJSON(); 42 PackageDescription b = jsonToPackageDescription(j); 43 44 assert(a == b, 45 j.toPrettyString()); 46 //pkgCompare(a, b)); 47 } 48 49 version(ExcessivConvTests): 50 51 void fun2() { 52 auto all = chain( 53 () @trusted { return allDubJSONFiles(); }(), 54 () @trusted { return allDubSDLFiles(); }()) 55 .map!(fn => tuple(fn, readText(fn))) 56 .map!(t => tuple(t[0], 57 t[0].endsWith(".sdl") 58 ? sdlToPackageDescription(t[1]) 59 .ifThrown(PackageDescription.init) 60 : jsonToPackageDescription(t[1]) 61 .ifThrown(PackageDescription.init))) 62 .filter!(t => t[1] != PackageDescription.init); 63 64 size_t idx; 65 size_t failed; 66 size_t worked; 67 size_t[TestFailKind] failCnt; 68 foreach(it; all) { 69 //writefln("%s %s", idx, it[0]); 70 try { 71 PackageDescription a = it[1]; 72 JSONValue js = testToJson(a, it[0], failCnt); 73 if(js == JSONValue.init) { 74 incrementFailCnt(failCnt, TestFailKind.toJson); 75 continue; 76 } 77 PackageDescription b = jsonToPackageDescription(js); 78 if(b != a) { 79 writefln("%5d %s\nb == a failed\n%s", idx, it[0], 80 pkgCompare(b, a)); 81 incrementFailCnt(failCnt, TestFailKind.fromJsonCopy); 82 continue; 83 } 84 85 86 string sdlOut = testToSDL(a, it[0], failCnt); 87 //writefln("%s:\n%s", it[0], sdlOut); 88 PackageDescription c; 89 try { 90 c = sdlToPackageDescription(sdlOut); 91 assert(a == c, 92 () @trusted { 93 return format("f: %s\nexp:\n%s\ngot:\n%s", it[0], a, c); 94 }()); 95 } catch(Exception e) { 96 unRollException(e, it[0]); 97 incrementFailCnt(failCnt, TestFailKind.fromSDLCopy); 98 continue; 99 } 100 101 PackageDescription copy = ddupTest(a, it[0], failCnt); 102 103 if(b != c) { 104 writefln("%5d %s\nb == c failed\n%s", idx, it[0], 105 pkgCompare(b, c)); 106 incrementFailCnt(failCnt, TestFailKind.cmp); 107 continue; 108 } 109 110 ++worked; 111 } catch(Exception e) { 112 //unRollException(e, it[0]); 113 } 114 115 ++idx; 116 } 117 writefln("fails %s, %d worked", failCnt, worked); 118 } 119 120 void main() { 121 fun1(); 122 fun2(); 123 }