Skip to content

Commit 5ccdde3

Browse files
committed
Allow a custom postprocessor for FilterDocs
1 parent 0059d2e commit 5ccdde3

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

source/ddox/main.d

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ int ddoxMain(string[] args)
4646
return 1;
4747
}
4848

49-
int cmdGenerateHtml(string[] args)
49+
int cmdGenerateHtml(string[] args, GeneratorSettings gensettings = new GeneratorSettings())
5050
{
51-
GeneratorSettings gensettings;
5251
Package pack;
5352
if( auto ret = setupGeneratorInput(args, gensettings, pack) )
5453
return ret;
@@ -57,14 +56,13 @@ int cmdGenerateHtml(string[] args)
5756
return 0;
5857
}
5958

60-
int cmdServeHtml(string[] args)
59+
int cmdServeHtml(string[] args, GeneratorSettings gensettings = new GeneratorSettings())
6160
{
6261
string[] webfiledirs;
6362
getopt(args,
6463
config.passThrough,
6564
"web-file-dir", &webfiledirs);
6665

67-
GeneratorSettings gensettings;
6866
Package pack;
6967
if( auto ret = setupGeneratorInput(args, gensettings, pack) )
7068
return ret;
@@ -84,11 +82,9 @@ int cmdServeHtml(string[] args)
8482
return runEventLoop();
8583
}
8684

87-
int cmdServeTest(string[] args)
85+
int cmdServeTest(string[] args, GeneratorSettings gensettings = new GeneratorSettings(), DdoxSettings docsettings = new DdoxSettings())
8886
{
8987
string[] webfiledirs;
90-
auto docsettings = new DdoxSettings;
91-
auto gensettings = new GeneratorSettings;
9288

9389
auto pack = parseD(args[2 .. $]);
9490

@@ -111,7 +107,9 @@ int cmdServeTest(string[] args)
111107

112108
int setupGeneratorInput(ref string[] args, out GeneratorSettings gensettings, out Package pack)
113109
{
114-
gensettings = new GeneratorSettings;
110+
if (gensettings is null)
111+
gensettings = new GeneratorSettings;
112+
115113
auto docsettings = new DdoxSettings;
116114

117115
string[] macrofiles;
@@ -153,7 +151,7 @@ int setupGeneratorInput(ref string[] args, out GeneratorSettings gensettings, ou
153151
return 0;
154152
}
155153

156-
int cmdFilterDocs(string[] args)
154+
int cmdFilterDocs(string[] args, GeneratorSettings generatorSettings = new GeneratorSettings())
157155
{
158156
string[] excluded, included;
159157
Protection minprot = Protection.Private;
@@ -225,6 +223,8 @@ int cmdFilterDocs(string[] args)
225223
if (last_decl["comment"].opt!string.empty) {
226224
writefln("Warning: Cannot add documented unit test %s to %s, which is not documented.", name, last_decl["name"].opt!string);
227225
} else {
226+
if (generatorSettings.postUnittestSourceCode !is null)
227+
source = generatorSettings.postUnittestSourceCode(source);
228228
last_decl["comment"] ~= format("Example:\n%s$(DDOX_UNITTEST_HEADER %s)\n---\n%s\n---\n$(DDOX_UNITTEST_FOOTER %s)\n", comment.strip, name, source, name);
229229
}
230230
} catch (Exception e) {

source/ddox/settings.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ class GeneratorSettings {
6161
@property bool lowerCase() const { return fileNameStyle == MethodStyle.lowerCase; }
6262
deprecated("Use fileNameStyle = MethodStyle.lowerCase instead.")
6363
@property void lowerCase(bool v) { fileNameStyle = MethodStyle.lowerCase; }
64+
65+
/**
66+
Custom delegate that is called after the unittest source code has been parsed
67+
Can be used to inject custom logic like an assert/writeln transformation.
68+
*/
69+
string delegate(string) postUnittestSourceCode;
6470
}

0 commit comments

Comments
 (0)