1 module dud.pkgdescription.sdltests; 2 3 import std.algorithm.sorting : sort; 4 import std.array : empty, front; 5 import std.conv; 6 import std.exception : assertThrown; 7 import std.typecons : nullable; 8 import std.format : format; 9 import std.stdio; 10 import std.json; 11 12 import dud.pkgdescription; 13 import dud.pkgdescription.sdl; 14 import dud.pkgdescription.output; 15 import dud.pkgdescription.exception; 16 import dud.semver.semver : SemVer; 17 import dud.semver.parse : parseSemVer; 18 import dud.semver.versionrange; 19 import dud.pkgdescription.duplicate : ddup = dup; 20 21 unittest { 22 string input = ` 23 name "pkgdescription" 24 dependency "semver" path="../semver" 25 dependency "path" path="../path" 26 dependency "sdlang" path="../sdlang" 27 dependency "graphqld" version=">=1.0.0" default=true optional=false 28 targetType "library" 29 targetPath "outDir" 30 importPaths "source" "source1" "source2" 31 license "LGPL3" 32 configuration "test" { 33 platforms "windows" 34 libs "libc" 35 } 36 `; 37 38 PackageDescription pkg = sdlToPackageDescription(input); 39 assert(pkg.name == "pkgdescription", pkg.name); 40 assert(pkg.targetType == TargetType.library, to!string(pkg.targetType)); 41 assert(pkg.importPaths == 42 Paths([PathsPlatform( 43 [ UnprocessedPath("source") , UnprocessedPath("source1") 44 , UnprocessedPath("source2") ] 45 , [ ] 46 )]) 47 , to!string(pkg.importPaths)); 48 //assert(pkg.version_ == parseSemVer("1.0.0"), pkg.version_.toString); 49 assert(pkg.license == "LGPL3", pkg.license); 50 assert(pkg.dependencies.length == 4, to!string(pkg.dependencies.length)); 51 auto e = UnprocessedPath("outDir"); 52 assert(pkg.targetPath == e, format("\nexp:\n%s\ngot:\n%s", e, 53 pkg.targetPath)); 54 55 auto dep = 56 [ Dependency("semver") 57 , Dependency("sdlang") 58 , Dependency("graphqld") 59 , Dependency("path") 60 ]; 61 dep[0].path = UnprocessedPath("../semver"); 62 dep[3].path = UnprocessedPath("../path"); 63 dep[1].path = UnprocessedPath("../sdlang"); 64 dep[2].version_ = parseVersionRange(">=1.0.0"); 65 dep[2].default_ = nullable(true); 66 dep[2].optional = nullable(false); 67 pkg.dependencies.sort!((a,b) => a.name < b.name); 68 dep.sort!((a,b) => a.name < b.name); 69 70 assert(pkg.dependencies == dep, format("\ngot:\n%(\t%s\n%)\nexp:\n%(\t%s\n%)", 71 pkg.dependencies, dep)); 72 73 string output = toSDL(pkg); 74 assert(!output.empty); 75 PackageDescription pkgReParse = sdlToPackageDescription(output); 76 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 77 JSONValue j = toJSON(pkg); 78 PackageDescription fromJ = jsonToPackageDescription(j); 79 fromJ.dependencies.sort!((a,b) => a.name < b.name); 80 assert(fromJ == pkg, format("\nexp:\n%s\ngot:\n%s", pkg, fromJ)); 81 82 PackageDescription copy = ddup(pkg); 83 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 84 } 85 86 unittest { 87 string input = ` 88 configuration "default" 89 90 configuration "testing" { 91 } 92 `; 93 94 PackageDescription pkg = sdlToPackageDescription(input); 95 96 PackageDescription copy = ddup(pkg); 97 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 98 } 99 100 101 unittest { 102 string toParse = ` 103 subConfiguration "pkg1" "fast" 104 subConfiguration "pkg2" "slow" 105 subConfiguration "pkg3" "experimental" platform="posix" 106 workingDirectory "/root" 107 `; 108 109 PackageDescription pkg = sdlToPackageDescription(toParse); 110 string output = toSDL(pkg); 111 PackageDescription pkgReParse = sdlToPackageDescription(output); 112 string output2 = toSDL(pkgReParse); 113 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 114 115 PackageDescription copy = ddup(pkg); 116 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 117 } 118 119 unittest { 120 string toParse = ` 121 postBuildCommands "format C:" "install linux" platform="windows" 122 postBuildCommands "echo \"You are good\"" platform="linux" 123 `; 124 125 PackageDescription pkg = sdlToPackageDescription(toParse); 126 string output = toSDL(pkg); 127 PackageDescription pkgReParse = sdlToPackageDescription(output); 128 string output2 = toSDL(pkgReParse); 129 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 130 131 PackageDescription copy = ddup(pkg); 132 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 133 } 134 135 unittest { 136 string toParse = ` 137 buildRequirements "allowWarnings" "disallowDeprecations" 138 `; 139 140 PackageDescription pkg = sdlToPackageDescription(toParse); 141 string output = toSDL(pkg); 142 PackageDescription pkgReParse = sdlToPackageDescription(output); 143 string output2 = toSDL(pkgReParse); 144 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 145 146 PackageDescription copy = ddup(pkg); 147 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 148 } 149 150 unittest { 151 string toParse = ` 152 buildOptions "verbose" 153 buildOptions "debugMode" "coverage" platform="windows" 154 buildOptions "debugMode" "inline" "coverage" platform="posix" 155 `; 156 157 PackageDescription pkg = sdlToPackageDescription(toParse); 158 string output = toSDL(pkg); 159 PackageDescription pkgReParse = sdlToPackageDescription(output); 160 string output2 = toSDL(pkgReParse); 161 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 162 163 PackageDescription copy = ddup(pkg); 164 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 165 } 166 167 unittest { 168 string toParse = ` 169 name "describe-dependency-1" 170 description "A test describe project" 171 homepage "fake.com" 172 authors "nobody" 173 copyright "Copyright © 2015, nobody" 174 license "BSD 2-clause" 175 x:ddoxFilterArgs "dfa1" "dfa2" 176 `; 177 178 PackageDescription pkg = sdlToPackageDescription(toParse); 179 string output = toSDL(pkg); 180 PackageDescription pkgReParse = sdlToPackageDescription(output); 181 string output2 = toSDL(pkgReParse); 182 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 183 184 PackageDescription copy = ddup(pkg); 185 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 186 } 187 188 unittest { 189 string toParse = ` 190 subPackage { 191 name "sub1" 192 } 193 subPackage { 194 name "sub2" 195 targetType "executable" 196 } 197 `; 198 199 PackageDescription pkg = sdlToPackageDescription(toParse); 200 string output = toSDL(pkg); 201 assert(pkg.subPackages.length == 2, output); 202 assert(pkg.subPackages[0].inlinePkg.get().name == "sub1", 203 pkg.subPackages[0].inlinePkg.get().name); 204 assert(pkg.subPackages[1].inlinePkg.get().name == "sub2", 205 pkg.subPackages[1].inlinePkg.get().name); 206 PackageDescription pkgReParse = sdlToPackageDescription(output); 207 string output2 = toSDL(pkgReParse); 208 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 209 210 PackageDescription copy = ddup(pkg); 211 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 212 } 213 214 unittest { 215 string toParse = ` 216 dependency "vibe-d:core" version="*" 217 dependency "mir-linux-kernel" version="~>1.0.0" platform="linux" 218 libs "advapi32" platform="windows" 219 `; 220 221 PackageDescription pkg = sdlToPackageDescription(toParse); 222 string output = toSDL(pkg); 223 PackageDescription pkgReParse = sdlToPackageDescription(output); 224 string output2 = toSDL(pkgReParse); 225 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 226 227 PackageDescription copy = ddup(pkg); 228 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 229 } 230 231 unittest { 232 string toParse = ` 233 configuration "libevent" { 234 libs "wsock32" "ws2_32" "advapi32" platform="windows" 235 sourceFiles "../lib/win-i386/event2.lib" platform="windows-x86" 236 } 237 `; 238 239 PackageDescription pkg = sdlToPackageDescription(toParse); 240 string output = toSDL(pkg); 241 PackageDescription pkgReParse = sdlToPackageDescription(output); 242 string output2 = toSDL(pkgReParse); 243 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 244 245 PackageDescription copy = ddup(pkg); 246 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 247 } 248 249 unittest { 250 string toParse = ` 251 configuration "windows-mscoff" { 252 platforms "windows-x86_mscoff" "windows-x86_64" "windows-x86-ldc" 253 sourceFiles "../lib/win-i386-mscoff/libeay32.lib" "../lib/win-i386-mscoff/ssleay32.lib" platform="windows-x86_mscoff" 254 sourceFiles "../lib/win-amd64/libeay32.lib" "../lib/win-amd64/ssleay32.lib" platform="windows-x86_64" 255 } 256 `; 257 258 PackageDescription pkg = sdlToPackageDescription(toParse); 259 string output = toSDL(pkg); 260 PackageDescription pkgReParse = sdlToPackageDescription(output); 261 string output2 = toSDL(pkgReParse); 262 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 263 264 PackageDescription copy = ddup(pkg); 265 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 266 } 267 268 unittest { 269 string toParse = ` 270 x:versionFilters "Daughter" "Parent" 271 x:debugVersionFilters "dDaughter" "dParent" 272 `; 273 274 PackageDescription pkg = sdlToPackageDescription(toParse); 275 string output = toSDL(pkg); 276 PackageDescription pkgReParse = sdlToPackageDescription(output); 277 string output2 = toSDL(pkgReParse); 278 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 279 280 PackageDescription copy = ddup(pkg); 281 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 282 } 283 284 unittest { 285 string toParse = ` 286 subPackage "../common" 287 `; 288 289 PackageDescription pkg = sdlToPackageDescription(toParse); 290 string output = toSDL(pkg); 291 PackageDescription pkgReParse = sdlToPackageDescription(output); 292 string output2 = toSDL(pkgReParse); 293 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 294 295 PackageDescription copy = ddup(pkg); 296 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 297 } 298 299 unittest { 300 string toParse = ` 301 description "A basic \"Hello, World\" program." 302 `; 303 304 PackageDescription pkg = sdlToPackageDescription(toParse); 305 string output = toSDL(pkg); 306 PackageDescription pkgReParse = sdlToPackageDescription(output); 307 string output2 = toSDL(pkgReParse); 308 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 309 310 PackageDescription copy = ddup(pkg); 311 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 312 } 313 314 unittest { 315 string toParse = q{ 316 preGenerateCommands `rdmd --eval=' 317 auto data = text("module openssl_version;\nenum OPENSSL_VERSION=\"", opensslVersion, "\";"); 318 ` platform="posix" 319 }; 320 321 PackageDescription pkg = sdlToPackageDescription(toParse); 322 string output = toSDL(pkg); 323 PackageDescription pkgReParse = sdlToPackageDescription(output); 324 string output2 = toSDL(pkgReParse); 325 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 326 327 PackageDescription copy = ddup(pkg); 328 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 329 } 330 331 unittest { 332 string toParse = q{ 333 configuration "unittest" { 334 dependency "unit-threaded" version="*" 335 336 targetType "executable" 337 mainSourceFile "bin/ut.d" 338 excludedSourceFiles "source/app.d" 339 targetType "executable" 340 preBuildCommands "dub run unit-threaded -c gen_ut_main -- -f bin/ut.d" 341 } 342 }; 343 344 PackageDescription pkg = sdlToPackageDescription(toParse); 345 string output = toSDL(pkg); 346 PackageDescription pkgReParse = sdlToPackageDescription(output); 347 string output2 = toSDL(pkgReParse); 348 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 349 350 PackageDescription copy = ddup(pkg); 351 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 352 } 353 354 unittest { 355 string toParse = ` 356 name "animated" 357 description "An animation library, written in D, based loosely upon the animation framework used in Android." 358 homepage "https://github.com/luke5542/AnimateD" 359 authors "luke5542" 360 copyright "Copyright © 2015, Devin Ridgway" 361 license "GPL-2.0" 362 dependency "d-unit" version="~master" 363 targetType "library" 364 targetPath "bin\\" 365 `; 366 367 PackageDescription pkg = sdlToPackageDescription(toParse); 368 string output = toSDL(pkg); 369 PackageDescription pkgReParse = sdlToPackageDescription(output); 370 string output2 = toSDL(pkgReParse); 371 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 372 373 PackageDescription copy = ddup(pkg); 374 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 375 } 376 377 unittest { 378 string toParse = ` 379 name "animated" foobar="args" 380 `; 381 382 assertThrown!UnsupportedAttributes(sdlToPackageDescription(toParse)); 383 } 384 385 unittest { 386 string toParse = ` 387 name "eventcore" 388 libs "ws2_32" "user32" platform="windows" 389 libs "anl" platform="linux" 390 configuration "epoll" { 391 platforms "linux" 392 targetType "library" 393 versions "EventcoreEpollDriver" 394 } 395 configuration "kqueue" { 396 platforms "osx" "freebsd" 397 targetType "library" 398 versions "EventcoreKqueueDriver" 399 } 400 configuration "winapi" { 401 platforms "windows-x86_64" "windows-x86_mscoff" 402 targetType "library" 403 versions "EventcoreWinAPIDriver" 404 } 405 configuration "select" { 406 platforms "posix" "windows-x86_64" "windows-x86_mscoff" 407 targetType "library" 408 versions "EventcoreSelectDriver" 409 } 410 `; 411 412 PackageDescription pkg = sdlToPackageDescription(toParse); 413 string output = toSDL(pkg); 414 PackageDescription pkgReParse = sdlToPackageDescription(output); 415 string output2 = toSDL(pkgReParse); 416 assert(pkg == pkgReParse, format("\nexp:\n%s\ngot:\n%s", pkg, pkgReParse)); 417 418 PackageDescription copy = ddup(pkg); 419 assert(pkg == copy, format("\nexp:\n%s\ngot:\n%s", pkg, copy)); 420 } 421 422 unittest { 423 string toParse = ` 424 dependency "semver" path="../semver" 425 dependency "semver" path="../semver" version=">=1.0.0" platform="posix" 426 dependency "semver" path="../semver" version=">=2.0.0" platform="android" 427 428 `; 429 430 PackageDescription pkg = sdlToPackageDescription(toParse); 431 assert(pkg.dependencies.length == 3, format("dep.length %s", 432 pkg.dependencies.length)); 433 } 434 435 unittest { 436 import dud.pkgdescription.json : jsonToPackageDescription; 437 string toParse = ` 438 { 439 "buildTypes": { 440 "unittest-release": { 441 "buildOptions": [ 442 "unittests", 443 "optimize", 444 "inline" 445 ] 446 } 447 }, 448 "copyright": "Auburn Sounds 2016-2018", 449 "description": "The most practical D SIMD solution! Using SIMD intrinsics with Intel syntax with D.", 450 "importPaths": [ 451 "source" 452 ], 453 "license": "BSL-1.0", 454 "name": "intel-intrinsics", 455 "sourcePaths": [ 456 "source" 457 ] 458 } 459 `; 460 461 PackageDescription pkg = jsonToPackageDescription(toParse); 462 string output = toSDL(pkg); 463 PackageDescription pkg2 = sdlToPackageDescription(output); 464 assert(pkg == pkg2, format("\nexp:\n%s\ngot:\n%s", pkg, pkg2)); 465 }