diff --git a/changelog/cov_ctfe.dd b/changelog/cov_ctfe.dd new file mode 100644 index 0000000..a6ccb63 --- /dev/null +++ b/changelog/cov_ctfe.dd @@ -0,0 +1,4 @@ +The two new build types `cov-ctfe` and `unittest-cov-ctfe` have been added. + +These extend the existing build types `cov` and `unittest-cov` respectively by +appending `-cov=ctfe` to the set of flags passed to the compiler. diff --git a/scripts/fish-completion/dub.fish b/scripts/fish-completion/dub.fish index c8cd222..bda55ed 100644 --- a/scripts/fish-completion/dub.fish +++ b/scripts/fish-completion/dub.fish @@ -49,7 +49,7 @@ complete -c dub -n "contains '$cmd' (commandline -poc)" -s a -l arch -r -d "Force architecture" complete -c dub -n "contains '$cmd' (commandline -poc)" -s d -l debug -r -d "Debug identifier" complete -c dub -n "contains '$cmd' (commandline -poc)" -l nodeps -d "No dependency check" - complete -c dub -n "contains '$cmd' (commandline -poc)" -s b -l build -u -x -d "Build type" -a "debug plain release release-debug release-nobounds unittest profile profile-gc docs ddox cov unittest-cov syntax" + complete -c dub -n "contains '$cmd' (commandline -poc)" -s b -l build -u -x -d "Build type" -a "debug plain release release-debug release-nobounds unittest profile profile-gc docs ddox cov cov-ctfe unittest-cov unittest-cov-ctfe syntax" complete -c dub -n "contains '$cmd' (commandline -poc)" -l build-mode -x -d "How compiler & linker are invoked" -a "separate allAtOnce singleFile" complete -c dub -n "contains '$cmd' (commandline -poc)" -l compiler -x -d "Compiler binary" -a "dmd gdc ldc gdmd ldmd" end diff --git a/scripts/zsh-completion/_dub b/scripts/zsh-completion/_dub index 75fefa5..21457f0 100644 --- a/scripts/zsh-completion/_dub +++ b/scripts/zsh-completion/_dub @@ -147,7 +147,7 @@ $@ \ '::package:_dub_add' \ '(* : -)'{-h,--help}'[Display general or command specific help and exit]' \ - '(-b --build)'{-b,--build=}'[Specifies the type of build to perform]:build type:("debug (default)" plain release release-debug release-nobounds unittest profile profile-gc docs ddox cov unittest-cov syntax)' \ + '(-b --build)'{-b,--build=}'[Specifies the type of build to perform]:build type:("debug (default)" plain release release-debug release-nobounds unittest profile profile-gc docs ddox cov cov-ctfe unittest-cov unittest-cov-ctfe syntax)' \ '(-c --config)'{-c,--config=}'[Builds the specified configuration]:package configuration: ' \ '*--override-config=[ Uses the specified configuration for a certain dependency]:dependency/config: ' \ '--compiler=[Specifies the compiler binary to use (can be a path)]:compiler:(dmd gdc ldc gdmd ldmd)' \ diff --git a/source/dub/commandline.d b/source/dub/commandline.d index fcb0f55..b60d473 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1372,12 +1372,19 @@ args.getopt("f|force", &m_force, [ "Forces a recompilation even if the target is up to date" ]); + bool coverage = false; args.getopt("coverage", &coverage, [ "Enables code coverage statistics to be generated." ]); if (coverage) m_buildType = "unittest-cov"; + bool coverageCTFE = false; + args.getopt("coverage-ctfe", &coverageCTFE, [ + "Enables code coverage (including CTFE) statistics to be generated." + ]); + if (coverageCTFE) m_buildType = "unittest-cov-ctfe"; + super.prepare(args); } diff --git a/source/dub/compilers/buildsettings.d b/source/dub/compilers/buildsettings.d index 212c22a..18410f4 100644 --- a/source/dub/compilers/buildsettings.d +++ b/source/dub/compilers/buildsettings.d @@ -378,10 +378,11 @@ pic = 1<<22, /// Generate position independent code betterC = 1<<23, /// Compile in betterC mode (-betterC) lowmem = 1<<24, /// Compile in lowmem mode (-lowmem) + coverageCTFE = 1<<25, /// Enable code coverage analysis including at compile-time (-cov=ctfe) // for internal usage - _docs = 1<<25, // Write ddoc to docs - _ddox = 1<<26 // Compile docs.json + _docs = 1<<26, // Write ddoc to docs + _ddox = 1<<27, // Compile docs.json } struct BuildOptions { @@ -405,7 +406,7 @@ ) */ enum BuildOptions inheritedBuildOptions = BuildOption.debugMode | BuildOption.releaseMode - | BuildOption.coverage | BuildOption.debugInfo | BuildOption.debugInfoC + | BuildOption.coverage | BuildOption.coverageCTFE | BuildOption.debugInfo | BuildOption.debugInfoC | BuildOption.alwaysStackFrame | BuildOption.stackStomping | BuildOption.inline | BuildOption.noBoundsCheck | BuildOption.profile | BuildOption.ignoreUnknownPragmas | BuildOption.syntaxOnly | BuildOption.warnings | BuildOption.warningsAsErrors diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index 65ee2f4..daf5c5a 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -43,6 +43,7 @@ tuple(BuildOption.debugMode, ["-debug"]), tuple(BuildOption.releaseMode, ["-release"]), tuple(BuildOption.coverage, ["-cov"]), + tuple(BuildOption.coverageCTFE, ["-cov=ctfe"]), tuple(BuildOption.debugInfo, ["-g"]), tuple(BuildOption.debugInfoC, ["-g"]), tuple(BuildOption.alwaysStackFrame, ["-gs"]), diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 1ab5019..fc2791f 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -25,6 +25,7 @@ tuple(BuildOption.debugMode, ["-d-debug"]), tuple(BuildOption.releaseMode, ["-release"]), tuple(BuildOption.coverage, ["-cov"]), + tuple(BuildOption.coverageCTFE, ["-cov=ctfe"]), tuple(BuildOption.debugInfo, ["-g"]), tuple(BuildOption.debugInfoC, ["-gc"]), tuple(BuildOption.alwaysStackFrame, ["-disable-fp-elim"]), diff --git a/source/dub/compilers/utils.d b/source/dub/compilers/utils.d index 171f487..d170b4c 100644 --- a/source/dub/compilers/utils.d +++ b/source/dub/compilers/utils.d @@ -170,6 +170,7 @@ {["-D"], "Call dub with --build=docs or --build=ddox"}, {["-X"], "Call dub with --build=ddox"}, {["-cov"], "Call dub with --build=cov or --build=unittest-cov"}, + {["-cov=ctfe"], "Call dub with --build=cov-ctfe or --build=unittest-cov-ctfe"}, {["-profile"], "Call dub with --build=profile"}, {["-version="], `Use "versions" to specify version constants in a compiler independent way`}, {["-debug="], `Use "debugVersions" to specify version constants in a compiler independent way`}, @@ -186,6 +187,7 @@ {[BuildOption.debugMode], "Call DUB with --build=debug"}, {[BuildOption.releaseMode], "Call DUB with --build=release"}, {[BuildOption.coverage], "Call DUB with --build=cov or --build=unittest-cov"}, + {[BuildOption.coverageCTFE], "Call DUB with --build=cov-ctfe or --build=unittest-cov-ctfe"}, {[BuildOption.debugInfo], "Call DUB with --build=debug"}, {[BuildOption.inline], "Call DUB with --build=release"}, {[BuildOption.noBoundsCheck], "Call DUB with --build=release-nobounds"}, diff --git a/source/dub/generators/sublimetext.d b/source/dub/generators/sublimetext.d index aaf5cf0..f53ae53 100644 --- a/source/dub/generators/sublimetext.d +++ b/source/dub/generators/sublimetext.d @@ -75,7 +75,9 @@ "profile", "profile-gc", "cov", + "cov-ctfe", "unittest-cov", + "unittest-cov-ctfe", "syntax" ]; diff --git a/source/dub/package_.d b/source/dub/package_.d index 98b463b..40a8eda 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -69,7 +69,9 @@ "docs", "ddox", "cov", + "cov-ctfe", "unittest-cov", + "unittest-cov-ctfe", "syntax" ]; @@ -453,7 +455,9 @@ case "profile": settings.addOptions(profile, optimize, inline, debugInfo); break; case "profile-gc": settings.addOptions(profileGC, debugInfo); break; case "cov": settings.addOptions(coverage, debugInfo); break; + case "cov-ctfe": settings.addOptions(coverageCTFE, debugInfo); break; case "unittest-cov": settings.addOptions(unittests, coverage, debugMode, debugInfo); break; + case "unittest-cov-ctfe": settings.addOptions(unittests, coverageCTFE, debugMode, debugInfo); break; case "syntax": settings.addOptions(syntaxOnly); break; } } diff --git a/test/cov-ctfe.sh b/test/cov-ctfe.sh new file mode 100755 index 0000000..1233112 --- /dev/null +++ b/test/cov-ctfe.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +DIR=$(dirname "${BASH_SOURCE[0]}") + +. "$DIR"/common.sh + +DFLAGS='-cov=100' "$DUB" run --root "$DIR"/cov-ctfe --build=cov-ctfe diff --git a/test/cov-ctfe/dub.sdl b/test/cov-ctfe/dub.sdl new file mode 100644 index 0000000..bb1ba3f --- /dev/null +++ b/test/cov-ctfe/dub.sdl @@ -0,0 +1,4 @@ +name "test" +version "1.0.0" +targetType "executable" +sourceFiles "test.d" diff --git a/test/cov-ctfe/test.d b/test/cov-ctfe/test.d new file mode 100644 index 0000000..d1056be --- /dev/null +++ b/test/cov-ctfe/test.d @@ -0,0 +1,17 @@ +int f(int x) +{ + return x + 1; +} + +int g(int x) +{ + return x * 2; +} + +enum gResult = g(12); // execute g() at compile-time + +int main(string[] args) +{ + assert(f(11) + gResult == 36); + return 0; +} diff --git a/test/unittest-cov-ctfe.sh b/test/unittest-cov-ctfe.sh new file mode 100755 index 0000000..9fd7f55 --- /dev/null +++ b/test/unittest-cov-ctfe.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +DIR=$(dirname "${BASH_SOURCE[0]}") + +. "$DIR"/common.sh + +DFLAGS='-cov=100' "$DUB" test --root "$DIR"/unittest-cov-ctfe --build=unittest-cov-ctfe diff --git a/test/unittest-cov-ctfe/dub.sdl b/test/unittest-cov-ctfe/dub.sdl new file mode 100644 index 0000000..660c022 --- /dev/null +++ b/test/unittest-cov-ctfe/dub.sdl @@ -0,0 +1,3 @@ +name "test" +version "1.0.0" +targetType "library" diff --git a/test/unittest-cov-ctfe/source/mod.d b/test/unittest-cov-ctfe/source/mod.d new file mode 100644 index 0000000..649655a --- /dev/null +++ b/test/unittest-cov-ctfe/source/mod.d @@ -0,0 +1,18 @@ +module mod; + +int f(int x) +{ + return x + 1; +} + +int g(int x) +{ + return x * 2; +} + +enum gResult = g(12); // execute g() at compile-time + +unittest +{ + assert(f(11) + gResult == 36); +}