dub

dlang is a fantastic language. Also in the last years the ecosystem evolved considerably. It brings many batteries included so lets describe a quick project setup:


Project creation
dlang comes with dub a package manager and buildsystem at the same time. This is now part of the reference compiler so you can start your project simply with dub init. I suggest to add unit-threaded as dependency to get a nice testing framework in place. The details can get tricky so I suggest to come up with several dub configurations:
  • application: if your module is an application this uses source/app.d to start your program
  • library: if you want to reuse your module, make it a proper library.
  • unittest: for me the following block works best:
    configuration "unittest" {
      targetType "executable"
      targetName "unittest"
      buildOptions "coverage"
    
      dependency "unit-threaded" version="==0.7.22"
      preBuildCommands "dub run unit-threaded -c gen_ut_main -- -f gen/testsuite.d"
      mainSourceFile "gen/testsuite.d"
      excludedSourceFiles "source/app.d"
    }
  • ut: for running quick unittests with unit-threaded:
    configuration "ut" {
      targetType "executable"
      targetName "ut"
      buildOptions "coverage"
    
      versions "unitThreadedLight"
      dependency "unit-threaded" version="==0.7.22"
      mainSourceFile "gen/testsuite.d"
      excludedSourceFiles "source/app.d"
    }
With this enabled you can run dub test -c ut || dub test to get a quick feedback if all tests are green, and a detailed feedback if tests are red. By specifying coverage as build options you also get the dlang builtin coverage when running your tests (watch out for lst files).