1 module tests.ut.dub.json; 2 3 4 import unit_threaded; 5 import reggae; 6 import reggae.dub.json; 7 import std.string; 8 9 @("foobar.json gets parsed correctly") 10 unittest { 11 import std.format: format; 12 const path = "/path/to"; 13 const info = getDubInfo(import("foobar.json").format(path, path, path, path, path, path, path, path, path, path, path)); 14 info.shouldEqual( 15 DubInfo( 16 [ 17 DubPackage( 18 "foo", //name 19 "/path/to", //path 20 "/path/to/source/app.d", // mainSourceFile 21 "foo", // targetFileName 22 [], // dflags 23 [], // lflags 24 ["/path/to/source/", "/path/to/bar/source/"], // importPaths 25 [], // stringImportPaths 26 ["/path/to/source/app.d"], // sourceFiles 27 TargetType.executable, 28 ["lefoo", "Have_foo", "Have_bar"], // versions 29 ["bar"], // dependencies 30 [], // libs 31 true, // active 32 [], // preBuildCommands 33 [], //postBuildCommands 34 ), 35 DubPackage( 36 "bar", //name 37 "/path/to/bar", //path 38 "", // mainSourceFile 39 "bar", // targetFileName 40 [], // dflags 41 [], // lflags 42 ["/path/to/bar/source/"], // importPaths 43 [], // stringImportPaths 44 ["/path/to/bar/source/bar.d"], // sourceFiles 45 TargetType.staticLibrary, 46 ["lefoo", "Have_bar"], // versions 47 [], // dependencies 48 [], // libs 49 true, // active 50 [], // preBuildCommands 51 [], //postBuildCommands 52 ), 53 ] 54 ) 55 ); 56 } 57 58 @("DubInfo.targetName") 59 unittest { 60 import std.format: format; 61 const path = "/path/to"; 62 auto info = getDubInfo(import("foobar.json").format(path, path, path, path, path, path, path, path, path, path, path)); 63 64 info.targetName.shouldEqual(TargetName("foo")); 65 66 info.packages[0].targetType = TargetType.dynamicLibrary; 67 info.targetName.shouldEqual(TargetName("libfoo.so")); 68 69 info.packages[0].targetType = TargetType.library; 70 info.targetName.shouldEqual(TargetName("libfoo.a")); 71 } 72 73 @("PACKAGE_DIR") 74 unittest { 75 const jsonString = q{ 76 { 77 "targets": [ 78 { 79 "buildSettings": { 80 "targetName": "lepackage", 81 "targetPath": "/dub/packages/lepackage", 82 "dflags": [], 83 "lflags": ["-L$PACKAGE_DIR"], 84 "importPaths": ["$PACKAGE_DIR/imports"], 85 "stringImportPaths": ["$PACKAGE_DIR/stringImports"], 86 "sourceFiles": [ 87 "$PACKAGE_DIR/foo.o", 88 "src/file.d" 89 ] 90 } 91 }, 92 { 93 "buildSettings": { 94 "targetName": "dep", 95 "targetPath": "/dub/packages/dep", 96 "dflags": [], 97 "lflags": [], 98 "importPaths": [], 99 "stringImportPaths": [], 100 "sourceFiles": [ 101 "$PACKAGE_DIR/bar.o", 102 "src/dep.d" 103 ] 104 } 105 } 106 ] 107 } 108 }; 109 110 getDubInfo(jsonString).shouldEqual( 111 DubInfo( 112 [ 113 DubPackage( 114 "lepackage", 115 "/dub/packages/lepackage", 116 "", // mainSourceFile 117 "lepackage", // targetFileName 118 [], // dflags 119 ["-L/dub/packages/lepackage"], 120 ["/dub/packages/lepackage/imports"], 121 ["/dub/packages/lepackage/stringImports"], 122 ["/dub/packages/lepackage/foo.o", "src/file.d"], 123 TargetType.autodetect, // targetType 124 [], // versions 125 [], // dependencies 126 [], // libs 127 true, // active 128 ), 129 DubPackage( 130 "dep", 131 "/dub/packages/dep", 132 "", // mainSourceFile 133 "dep", //targetFileName 134 [], // dflags 135 [], // lflags 136 [], // importPaths 137 [], // stringImportPaths 138 ["/dub/packages/dep/bar.o", "src/dep.d"], 139 TargetType.autodetect, // targetType 140 [], // versions 141 [], // dependencies 142 [], // libs 143 true, // active 144 ), 145 ] 146 )); 147 } 148 149 150 @("travis string") 151 unittest { 152 getDubInfo(import("travis.json")); 153 }