From fe80a5e2624ffeb5414f622e8eb4877be570b15b Mon Sep 17 00:00:00 2001 From: MoonlightSentinel Date: Sun, 26 Apr 2020 21:42:08 +0200 Subject: [PATCH 1/3] Remove /// from private unittests They are not included in the docs but still extracted by test_extractor.d --- src/core/demangle.d | 1 - src/core/time.d | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/core/demangle.d b/src/core/demangle.d index 8708eacba7..157896e204 100644 --- a/src/core/demangle.d +++ b/src/core/demangle.d @@ -2354,7 +2354,6 @@ char[] mangleFunc(T:FT*, FT)(const(char)[] fqn, char[] dst = null) @safe pure no private enum hasTypeBackRef = (int function(void**,void**)).mangleof[$-4 .. $] == "QdZi"; -/// @safe pure nothrow unittest { assert(mangleFunc!(int function(int))("a.b") == "_D1a1bFiZi"); diff --git a/src/core/time.d b/src/core/time.d index 6e3fe9ecea..a1c05d1ac7 100644 --- a/src/core/time.d +++ b/src/core/time.d @@ -3703,7 +3703,6 @@ long splitUnitsFromHNSecs(string units)(ref long hnsecs) @safe pure nothrow @nog return value; } -/// unittest { auto hnsecs = 2595000000007L; @@ -3744,7 +3743,6 @@ long getUnitsFromHNSecs(string units)(long hnsecs) @safe pure nothrow @nogc return convert!("hnsecs", units)(hnsecs); } -/// unittest { auto hnsecs = 2595000000007L; @@ -3783,7 +3781,6 @@ long removeUnitsFromHNSecs(string units)(long hnsecs) @safe pure nothrow @nogc return hnsecs - convert!(units, "hnsecs")(value); } -/// unittest { auto hnsecs = 2595000000007L; @@ -3913,7 +3910,6 @@ template nextLargerTimeUnits(string units) static assert(0, "Broken template constraint"); } -/// unittest { assert(nextLargerTimeUnits!"minutes" == "hours"); From ca4cfe46d6f94397deb391f5850ad4686a776611 Mon Sep 17 00:00:00 2001 From: MoonlightSentinel Date: Thu, 30 Apr 2020 19:17:40 +0200 Subject: [PATCH 2/3] Replace _abs in core.time example --- src/core/time.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/time.d b/src/core/time.d index a1c05d1ac7..bc6d87e89b 100644 --- a/src/core/time.d +++ b/src/core/time.d @@ -1789,8 +1789,9 @@ unittest long tl = to!("seconds",long)(t); assert(tl == 1000); + import core.stdc.math : fabs; double td = to!("seconds",double)(t); - assert(_abs(td - 1000) < 0.001); + assert(fabs(td - 1000) < 0.001); } unittest From 1773532f40bca77ce21940eba073c1a2b91e3967 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Tue, 13 Feb 2018 05:03:32 +0100 Subject: [PATCH 3/3] Add publictests checker for DRuntime Verifies that every public unittests can be executed as standalone on dlang.org and doesn't rely e.g. on imports outside of the unittests block. --- .circleci/config.yml | 3 +++ .circleci/run.sh | 11 +++++++++++ posix.mak | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index b2f6c1afc9..d327175293 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,3 +25,6 @@ jobs: - run: command: ./.circleci/run.sh betterc name: Run @betterC tests + - run: + command: ./.circleci/run.sh publictests + name: Run public unittests diff --git a/.circleci/run.sh b/.circleci/run.sh index f568158a40..4d93f4e6e0 100755 --- a/.circleci/run.sh +++ b/.circleci/run.sh @@ -109,6 +109,16 @@ betterc() make -f posix.mak betterc -j$N DUB="$HOME/dlang/dmd-${HOST_DMD_VER}/linux/bin64/dub" } +publictests() +{ + # checkout a specific version of https://github.com/dlang/tools + if [ ! -d ../tools ] ; then + clone https://github.com/dlang/tools.git ../tools master --depth 1 + fi + + make -f posix.mak publictests -j$N DUB="$HOME/dlang/dmd-${HOST_DMD_VER}/linux/bin64/dub" +} + codecov() { # CodeCov gets confused by lst files which it can't matched @@ -122,6 +132,7 @@ case $1 in setup-repos) setup_repos ;; style) style ;; betterc) betterc ;; + publictests) publictests ;; coverage) coverage ;; codecov) codecov ;; esac diff --git a/posix.mak b/posix.mak index b6c03c3de7..335625aea4 100644 --- a/posix.mak +++ b/posix.mak @@ -446,6 +446,24 @@ style_lint: @echo "Enforce no whitespace after opening parenthesis" $(GREP) -nrE "\<(version) \( " $$(find src -name '*.d') ; test $$? -eq 1 +################################################################################ +# Check for missing imports in public unittest examples. +################################################################################ + +PUBLICTESTS_DIR=$(ROOT)/publictests +publictests: $(addsuffix .publictests, $(basename $(SRCS))) + +################################################################################ +# Extract public tests of a module and test them in an separate file (i.e. without its module) +# This is done to check for potentially missing imports in the examples, e.g. +# make -f posix.mak src/core/time.publictests +################################################################################ +%.publictests: %.d $(TESTS_EXTRACTOR) $(DRUNTIME) | $(PUBLICTESTS_DIR)/.directory + @$(TESTS_EXTRACTOR) --inputdir $< --outputdir $(PUBLICTESTS_DIR) + @$(DMD) -main $(UDFLAGS) $(UTFLAGS) -defaultlib= -debuglib= -od$(PUBLICTESTS_DIR) $(DRUNTIME) -run $(PUBLICTESTS_DIR)/$(subst /,_,$<) + +################################################################################ + .PHONY : auto-tester-build ifneq (,$(findstring Darwin_64_32, $(PWD))) auto-tester-build: