Skip to content

Commit

Permalink
Remove version(dxmlTests)
Browse files Browse the repository at this point in the history
Previously, there was a problem where if someone imported a dxml module
from their unit tests, they would get linker errors about symbols that
dxml's unit tests imported not being found, and I couldn't figure out
why. The solution was to declare the version identifier dxmlTests and
using version(dxmlTests) on all of the unittest blocks and anything that
had been version(unittest), which meant that dub test then didn't work
without providing a custom build type which defined dxmlTests. It
worked, but it was ugly.

Now, I've finally figured out what the problem was. In order to
instantiate the templated types so that their tests would be compiled
and run, for each templated type, a module-level variable was being
declared (originally as version(unittest) and then version(dxmlTests))
which instantiated the type with the correct type to compile in the
tests. With version(unittest), that variable was declared when another
project imported the module when building their unit tests, which meant
that the template was instantiated and the tests were compiled - and
then failed to compile because of symbols that weren't available.

So, by moving those variables to unittest blocks, they only get compiled
(and thus, the templates only gets instantiated with their tests) when
compiling dxml's unit tests and not when another project using dxml
compiles its tests. So, the version identifier dxmlTests is no longer
necessary, and dub test works properly again.
  • Loading branch information
jmdavis committed May 10, 2019
1 parent ad265bf commit af2bcc6
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 109 deletions.
2 changes: 1 addition & 1 deletion cov.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

dub test --build=doCov
dub test --build=unittest-cov
17 changes: 3 additions & 14 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@
"name": "dxml",
"authors": [ "Jonathan M Davis" ],
"description": "An XML parser and writer written in D.",
"copyright": "Copyright © 2017 - 2018, Jonathan M Davis",
"copyright": "Copyright © 2017 - 2019, Jonathan M Davis",
"license": "BSL-1.0",
"targetType": "library",
"buildTypes":
{
"doTests":
"unittest-release":
{
"buildOptions": ["unittests", "debugMode", "debugInfo"],
"versions": ["dxmlTests"]
},
"doReleaseTests":
{
"buildOptions": ["unittests", "debugMode", "debugInfo", "releaseMode"],
"versions": ["dxmlTests"]
},
"doCov":
{
"buildOptions": ["unittests", "debugMode", "debugInfo", "coverage"],
"versions": ["dxmlTests"]
"buildOptions": ["unittests", "debugMode", "debugInfo", "releaseMode"]
}
}
}
20 changes: 11 additions & 9 deletions source/dxml/dom.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$(REF_ALTTEXT simpleXML, simpleXML, dxml, parser) is highly likely to
be used when calling $(LREF parseDOM).
Copyright: Copyright 2018
Copyright: Copyright 2018 - 2019
License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: $(HTTPS jmdavisprog.com, Jonathan M Davis)
Source: $(LINK_TO_SRC dxml/_dom.d)
Expand All @@ -26,7 +26,7 @@
module dxml.dom;

///
version(dxmlTests) unittest
unittest
{
import std.range.primitives : empty;

Expand Down Expand Up @@ -825,7 +825,7 @@ DOMEntity!(ER.Input) parseDOM(ER)(ref ER range)
parseDOM with the default $(REF_ALTTEXT Config, Config, dxml, parser) and a
range of characters.
+/
version(dxmlTests) @safe unittest
@safe unittest
{
import std.range.primitives;

Expand Down Expand Up @@ -876,7 +876,7 @@ version(dxmlTests) @safe unittest
parseDOM with $(REF_ALTTEXT simpleXML, simpleXML, dxml, parser) and a range
of characters.
+/
version(dxmlTests) unittest
unittest
{
import std.range.primitives : empty;

Expand Down Expand Up @@ -925,7 +925,7 @@ version(dxmlTests) unittest
parseDOM with $(REF_ALTTEXT simpleXML, simpleXML, dxml, parser) and an
$(REF_ALTTEXT EntityRange, EntityRange, dxml, parser).
+/
version(dxmlTests) unittest
unittest
{
import std.range.primitives : empty;
import dxml.parser : parseXML;
Expand Down Expand Up @@ -978,7 +978,7 @@ version(dxmlTests) unittest
parseDOM with an $(REF_ALTTEXT EntityRange, EntityRange, dxml, parser)
which is not at the start of the document.
+/
version(dxmlTests) unittest
unittest
{
import std.range.primitives : empty;
import dxml.parser : parseXML, skipToPath;
Expand Down Expand Up @@ -1014,7 +1014,7 @@ version(dxmlTests) unittest
}

/// parseDOM at compile-time
version(dxmlTests) unittest
unittest
{
enum xml = "<!-- comment -->\n" ~
"<root>\n" ~
Expand Down Expand Up @@ -1042,8 +1042,10 @@ private struct DOMCompileTests
@property typeof(this) save() @safe pure nothrow @nogc { assert(0); }
}

version(dxmlTests)
unittest
{
DOMEntity!DOMCompileTests _domTests;
}


private:
Expand Down Expand Up @@ -1115,7 +1117,7 @@ void _parseDOM(ER, DE)(ref ER range, ref DE parent, ER.SliceOfR[] path = null)
parent._children = children.data;
}

version(dxmlTests) unittest
unittest
{
import std.algorithm.comparison : equal;
import dxml.internal : testRangeFuncs;
Expand Down
14 changes: 7 additions & 7 deletions source/dxml/internal.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Written in the D programming language

/+
Copyright: Copyright 2017 - 2018
Copyright: Copyright 2017 - 2019
License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: Jonathan M Davis
+/
Expand Down Expand Up @@ -36,7 +36,7 @@ bool equalCU(R)(R range, string text)
return range.empty;
}

version(dxmlTests) unittest
unittest
{
import std.algorithm : filter;
import std.meta : AliasSeq;
Expand Down Expand Up @@ -87,7 +87,7 @@ pragma(inline, true) auto stripBCU(Orig, R)(R range)
return range;
}

version(dxmlTests) unittest
unittest
{
import std.algorithm : equal, filter;
import std.range : takeExactly;
Expand Down Expand Up @@ -132,7 +132,7 @@ bool isXMLChar(dchar c) pure nothrow @safe @nogc
: c > 127 && (c <= 0xD7FF || (c >= 0xE000 && c <= 0xFFFD) || (c >= 0x10000 && c <= 0x10FFFF));
}

version(dxmlTests) pure nothrow @safe @nogc unittest
pure nothrow @safe @nogc unittest
{
import std.range : only;
import std.typecons : tuple;
Expand Down Expand Up @@ -205,7 +205,7 @@ bool isNameStartChar(dchar c) @safe pure nothrow @nogc
return false;
}

version(dxmlTests) pure nothrow @safe @nogc unittest
pure nothrow @safe @nogc unittest
{
import std.range : only;
import std.typecons : tuple;
Expand Down Expand Up @@ -253,7 +253,7 @@ bool isNameChar(dchar c) @safe pure nothrow @nogc
c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
}

version(dxmlTests) pure nothrow @safe @nogc unittest
pure nothrow @safe @nogc unittest
{
import std.ascii : isAlphaNum;
import std.range : only;
Expand Down Expand Up @@ -299,7 +299,7 @@ version(dxmlTests) pure nothrow @safe @nogc unittest
// Unit test helpers
//------------------------------------------------------------------------------

version(dxmlTests):
version(unittest):

struct FwdCharRange(C)
{
Expand Down
Loading

0 comments on commit af2bcc6

Please sign in to comment.